List of usage examples for org.apache.commons.lang ArrayUtils toObject
public static Boolean[] toObject(boolean[] array)
Converts an array of primitive booleans to objects.
From source file:com.ironiacorp.statistics.r.type.LinearModelSummary.java
/** * @param summaryLm// w ww.j av a 2s. com * @return * @throws REXPMismatchException */ private RList basicSetup(REXP summaryLm) throws REXPMismatchException { RList li = summaryLm.asList(); REXPDouble coraw = (REXPDouble) li.get("coefficients"); RList dimnames = coraw.getAttribute("dimnames").asList(); String[] itemnames = ((REXP) dimnames.get(0)).asStrings(); String[] colNames = ((REXP) dimnames.get(1)).asStrings(); double[][] coef = coraw.asDoubleMatrix(); coefficients = DoubleMatrixFactory.dense(coef); coefficients.setRowNames(Arrays.asList(itemnames)); coefficients.setColumnNames(Arrays.asList(colNames)); this.residuals = ArrayUtils.toObject(((REXP) li.get("residuals")).asDoubles()); this.rSquared = ((REXP) li.get("r.squared")).asDouble(); this.adjRSquared = ((REXP) li.get("adj.r.squared")).asDouble(); return li; }
From source file:com.opengamma.analytics.financial.provider.curve.inflation.InflationDiscountBuildingRepository.java
/** * Build a unit of curves with the discount curve. * @param instruments The instruments used for the unit calibration. * @param initGuess The initial parameters guess. * @param knownData The known data (fx rates, other curves, model parameters, ...) * @param discountingMap The discounting curves names map. * @param forwardIborMap The forward curves names map. * @param forwardONMap The forward curves names map. * @param generatorsMap The generators map. * @param calculator The calculator of the value on which the calibration is done (usually ParSpreadInflationMarketQuoteDiscountingCalculator (recommended) or converted present value). * @param sensitivityCalculator The parameter sensitivity calculator. * @return The new curves and the calibrated parameters. *//* www .j a v a 2s .c o m*/ private Pair<InflationProviderDiscount, Double[]> makeUnit(final InstrumentDerivative[] instruments, final double[] initGuess, final InflationProviderDiscount knownData, final LinkedHashMap<String, Currency> discountingMap, final LinkedHashMap<String, IndexON[]> forwardONMap, final LinkedHashMap<String, IndexPrice[]> inflationMap, final LinkedHashMap<String, GeneratorCurve> generatorsMap, final InstrumentDerivativeVisitor<InflationProviderInterface, Double> calculator, final InstrumentDerivativeVisitor<InflationProviderInterface, InflationSensitivity> sensitivityCalculator) { final GeneratorInflationProviderDiscount generator = new GeneratorInflationProviderDiscount(knownData, discountingMap, forwardONMap, inflationMap, generatorsMap); final InflationDiscountBuildingData data = new InflationDiscountBuildingData(instruments, generator); final Function1D<DoubleMatrix1D, DoubleMatrix1D> curveCalculator = new InflationDiscountFinderFunction( calculator, data); final Function1D<DoubleMatrix1D, DoubleMatrix2D> jacobianCalculator = new InflationDiscountFinderJacobian( new ParameterSensitivityInflationMatrixCalculator(sensitivityCalculator), data); final double[] parameters = _rootFinder .getRoot(curveCalculator, jacobianCalculator, new DoubleMatrix1D(initGuess)).getData(); final InflationProviderDiscount newCurves = data.getGeneratorMarket() .evaluate(new DoubleMatrix1D(parameters)); return new ObjectsPair<>(newCurves, ArrayUtils.toObject(parameters)); }
From source file:de.tudarmstadt.ukp.dkpro.core.mallet.topicmodel.MalletTopicModelInferencer.java
/** * Assign topics according to the following formula: * <p>//from w w w. j av a 2 s. co m * Topic proportion must be at least the maximum topic's proportion divided by the maximum * number of topics to be assigned. In addition, the topic proportion must not lie under the * minTopicProb. If more topics comply with these criteria, only retain the n * (maxTopicAssignments) largest values. * * @param topicDistribution * a double array containing the document's topic proportions * @return an array of integers pointing to the topics assigned to the document */ private int[] assignTopics(final double[] topicDistribution) { /* * threshold is the largest value divided by the maximum number of topics or the fixed * number set as minTopicProb parameter. */ double threshold = Math.max( Collections.max(Arrays.asList(ArrayUtils.toObject(topicDistribution))) / maxTopicAssignments, minTopicProb); /* * assign indexes for values that are above threshold */ List<Integer> indexes = new ArrayList<>(topicDistribution.length); for (int i = 0; i < topicDistribution.length; i++) { if (topicDistribution[i] >= threshold) { indexes.add(i); } } /* * Reduce assignments to maximum number of allowed assignments. */ if (indexes.size() > maxTopicAssignments) { /* sort index list by corresponding values */ Collections.sort(indexes, new Comparator<Integer>() { @Override public int compare(Integer aO1, Integer aO2) { return Double.compare(topicDistribution[aO1], topicDistribution[aO2]); } }); while (indexes.size() > maxTopicAssignments) { indexes.remove(0); } } return ArrayUtils.toPrimitive(indexes.toArray(new Integer[indexes.size()])); }
From source file:ch.epfl.data.squall.components.signal_components.SignaledDataSourceComponent.java
@Override public SignaledDataSourceComponent setOutputPartKey(int... hashIndexes) { return setOutputPartKey(Arrays.asList(ArrayUtils.toObject(hashIndexes))); }
From source file:ch.epfl.data.squall.operators.AggregateSumOperator.java
@Override public AggregateSumOperator<T> setGroupByColumns(int... hashIndexes) { return setGroupByColumns(Arrays.asList(ArrayUtils.toObject(hashIndexes))); }
From source file:net.big_oh.algorithms.graph.clique.MaximalCliqueFinderFunctionalTest.java
private void testFindMaximalCliques_MultipleCliques_WithNoise(int numNonCliqueNodes, int... cliqueSizes) { if (numNonCliqueNodes < 0) { throw new IllegalArgumentException("numNonCliqueNodes cannot be less than zero."); }//from w ww .j ava 2s . c om if (cliqueSizes.length <= 0) { throw new IllegalArgumentException("must provide one or more cliqueSize arguments."); } final CliqueTestGraphBuilder graphBuilder = new CliqueTestGraphBuilder(); for (int cliqueSize : cliqueSizes) { graphBuilder.addClique(cliqueSize); } graphBuilder.setNumNonCliqueNodes(numNonCliqueNodes); final JungUndirectedGraph multiCliqueGraph = graphBuilder.build(); // find cliques of size 3 or greater; can't use size 2 because of noise // nodes that are connected to one node in each clique Set<Set<JungVertex>> maximalCliques = cliqueFinder.findMaximalCliques(multiCliqueGraph, 3); assertNotNull(maximalCliques); assertEquals("Failed to find expected number of maximal cliques.", cliqueSizes.length, maximalCliques.size()); // extract the _sizes_ of all discovered maximal cliques @SuppressWarnings("unchecked") Collection<Integer> maximalCliqueSizes = CollectionUtils.collect(maximalCliques, new Transformer() { public Object transform(Object input) { Set<JungVertex> clique = (Set<JungVertex>) input; return Integer.valueOf(clique.size()); } }); // the collection of input clique sizes should be equal to the // collection of discovered clique sizes assertTrue(CollectionUtils.isEqualCollection(Arrays.asList(ArrayUtils.toObject(cliqueSizes)), maximalCliqueSizes)); }
From source file:ch.epfl.data.squall.components.EquiJoinComponent.java
@Override public EquiJoinComponent setOutputPartKey(int... hashIndexes) { return setOutputPartKey(Arrays.asList(ArrayUtils.toObject(hashIndexes))); }
From source file:io.joynr.util.JoynrUtil.java
private static Object getResource(InputStream inputStream, boolean asByteArray) throws JoynrRuntimeException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024); byte[] bytes = new byte[512]; // Read bytes from the input stream in bytes.length-sized chunks and // write/*from w w w. j a va2 s . c om*/ // them into the output stream int readBytes; try { while ((readBytes = inputStream.read(bytes)) > 0) { outputStream.write(bytes, 0, readBytes); } Object result = null; if (asByteArray) { result = ArrayUtils.toObject(outputStream.toByteArray()); } else { result = outputStream.toString("UTF-8"); } // Close the streams inputStream.close(); outputStream.close(); return result; } catch (IOException e) { throw new JoynrRuntimeException(e.getMessage(), e) { private static final long serialVersionUID = 1L; }; } }
From source file:de.tudarmstadt.lt.lm.lucenebased.CountingStringLM.java
@Override public double getNgramLogProbability(int[] wordIds) { return getNgramLogProbabilityFromIds(Arrays.asList(ArrayUtils.toObject(wordIds))); }
From source file:net.sourceforge.jaulp.file.read.ReadFileUtils.java
/** * To byte array.//from w w w . j a v a 2s . co m * * @param byteArray * the byte array * @return the byte[] */ private static Byte[] toObject(byte[] byteArray) { return ArrayUtils.toObject(byteArray); }