List of usage examples for org.apache.commons.lang3 ArrayUtils toPrimitive
public static boolean[] toPrimitive(final Boolean[] array)
Converts an array of object Booleans to primitives.
This method returns null for a null input array.
From source file:com.vsthost.rnd.commons.math.ext.linear.DMatrixUtils.java
/** * Get the order of the specified elements in descending or ascending order. * * @param values A vector of double values. * @param indices The indices which will be considered for ordering. * @param descending Flag indicating if we go descending or not. * @return A vector of indices sorted in the provided order. *///from w ww . jav a 2 s.c o m public static int[] getOrder(double[] values, int[] indices, boolean descending) { // Create an index series: Integer[] opIndices = ArrayUtils.toObject(indices); // Sort indices: Arrays.sort(opIndices, new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { if (descending) { return Double.compare(values[o2], values[o1]); } else { return Double.compare(values[o1], values[o2]); } } }); return ArrayUtils.toPrimitive(opIndices); }
From source file:kieker.tools.opad.timeseries.forecast.AbstractRForecaster.java
private ForecastResult forecastWithR(final int numForecastSteps) throws InvalidREvaluationResultException { final ITimeSeries<Double> history = this.getTsOriginal(); final ITimeSeries<Double> tsForecast = this.prepareForecastTS(); final String varNameValues = RBridgeControl.uniqueVarname(); final String varNameModel = RBridgeControl.uniqueVarname(); final String varNameForecast = RBridgeControl.uniqueVarname(); final List<Double> allHistory = new ArrayList<Double>(history.getValues()); final Double[] histValuesNotNull = AbstractRForecaster.removeNullValues(allHistory); final double[] values = ArrayUtils.toPrimitive(histValuesNotNull); double fcQuality = Double.NaN; // 0. Assign values to temporal variable AbstractRForecaster.RBRIDGE.assign(varNameValues, values); if (history.getFrequency() != 0) { if (this.strategy != ForecastMethod.ARIMA) { // frequency for time series object in R --> needed for MASE calculation. AbstractRForecaster.RBRIDGE.toTS(varNameValues, history.getFrequency()); } else {// ww w . ja va2 s . c o m AbstractRForecaster.RBRIDGE.toTS(varNameValues); } } // 1. Compute stochastic model for forecast if (this.modelFunc == null) { // In this case, the values are the model ... AbstractRForecaster.RBRIDGE.assign(varNameModel, values); if (history.getFrequency() != 0) { if (this.strategy != ForecastMethod.ARIMA) { // frequency for time series object in R --> needed for MASE calculation. AbstractRForecaster.RBRIDGE.toTS(varNameValues, history.getFrequency()); } else { AbstractRForecaster.RBRIDGE.toTS(varNameValues); } } } else { final String[] additionalModelParams = this.getModelFuncParams(); final StringBuffer params = new StringBuffer(); params.append(varNameValues); if (null != additionalModelParams) { for (final String param : additionalModelParams) { params.append(','); params.append(param); } } AbstractRForecaster.RBRIDGE .evalWithR(String.format("%s <- %s(%s)", varNameModel, this.modelFunc, params)); } // remove temporal variable: AbstractRForecaster.RBRIDGE.evalWithR(String.format("rm(%s)", varNameValues)); // 2. Perform forecast based on stochastic model if ((this.getConfidenceLevel() == 0) || !this.supportsConfidence()) { AbstractRForecaster.RBRIDGE.evalWithR(String.format("%s <- %s(%s, h=%d)", varNameForecast, this.forecastFunc, varNameModel, numForecastSteps)); } else { AbstractRForecaster.RBRIDGE.evalWithR(String.format("%s <- %s(%s, h=%d, level=c(%d))", varNameForecast, this.forecastFunc, varNameModel, numForecastSteps, this.getConfidenceLevel())); } final double[] forecastValues = AbstractRForecaster.RBRIDGE .eDblArr(this.forecastOperationOnResult(varNameForecast)); // 3. Calculate Forecast Quality Metric if (forecastValues.length > 1) { if ((this.modelFunc == null)) { // Re-enable when TBATS included: || (this.strategy == ForecastMethod.TBATS) fcQuality = AbstractRForecaster.RBRIDGE.eDbl("accuracy(" + varNameForecast + ")[6]"); } else { fcQuality = AbstractRForecaster.RBRIDGE.eDbl("accuracy(" + varNameModel + ")[6]"); } } tsForecast.appendAll(ArrayUtils.toObject(forecastValues)); final ITimeSeries<Double> tsLower; final ITimeSeries<Double> tsUpper; if ((this.getConfidenceLevel() == 0) || !this.supportsConfidence()) { tsLower = tsForecast; tsUpper = tsForecast; } else { final double[] lowerValues = AbstractRForecaster.RBRIDGE .eDblArr(this.lowerOperationOnResult(varNameForecast)); final double[] upperValues = AbstractRForecaster.RBRIDGE .eDblArr(this.upperOperationOnResult(varNameForecast)); tsLower = this.prepareForecastTS(); tsLower.appendAll(ArrayUtils.toObject(lowerValues)); tsUpper = this.prepareForecastTS(); tsUpper.appendAll(ArrayUtils.toObject(upperValues)); } // remove temporal variable: AbstractRForecaster.RBRIDGE.evalWithR(String.format("rm(%s)", varNameModel)); AbstractRForecaster.RBRIDGE.evalWithR(String.format("rm(%s)", varNameValues)); AbstractRForecaster.RBRIDGE.evalWithR(String.format("rm(%s)", varNameForecast)); return new ForecastResult(tsForecast, this.getTsOriginal(), this.getConfidenceLevel(), fcQuality, tsLower, tsUpper, this.strategy); }
From source file:com.github.jessemull.microflex.util.IntegerUtil.java
/** * Converts a list of integers to an array of bytes. * @param List<Integer> list of integers * @return array of bytes *//* w ww .jav a 2s. c o m*/ public static byte[] toByteArray(List<Integer> list) { for (Integer val : list) { if (!OverFlowUtil.byteOverflow(val)) { OverFlowUtil.overflowError(val); } } return ArrayUtils.toPrimitive(list.toArray(new Byte[list.size()])); }
From source file:com.github.jessemull.microflex.util.DoubleUtil.java
/** * Converts a list of doubles to an array of shorts. * @param List<Double> list of doubles * @return array of shorts *//* w w w. j av a2s .c o m*/ public static short[] toShortArray(List<Double> list) { for (Double val : list) { if (!OverFlowUtil.shortOverflow(val)) { OverFlowUtil.overflowError(val); } } return ArrayUtils.toPrimitive(list.toArray(new Short[list.size()])); }
From source file:dynamicswordskills.entity.EntityLeapingBlow.java
@Override public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); compound.setFloat("damage", damage); compound.setInteger("level", level); compound.setInteger("lifespan", lifespan); compound.setIntArray("affectedEntities", ArrayUtils.toPrimitive(affectedEntities.toArray(new Integer[affectedEntities.size()]))); }
From source file:ijfx.core.overlay.OverlayStatService.java
public <T extends RealType<T>> PixelStatistics getPixelStatistics(Overlay overlay, RandomAccessibleInterval<T> rai) { RandomAccess<T> randomAccess = rai.randomAccess(); PixelMeasurer<T> measurer = new PixelMeasurer<>(randomAccess); overlayDrawingService.drawOverlay(overlay, OverlayDrawingService.FILLER, measurer); return new PixelStatisticsBase( new DescriptiveStatistics(ArrayUtils.toPrimitive(measurer.getValuesAsArray()))); }
From source file:gephi.spade.panel.FCSOperations.java
/** * Populates selectedEvents//w w w. jav a 2s . c o m */ private Array2DRowRealMatrix populateSelectedEvents(int[] selectedClust) { int clusterColumn = fcsInputFile.getChannelIdFromShortName("cluster"); ArrayList<Integer> columns = new ArrayList<Integer>(); //Populate selectedEventsInitial for (int i = 0; i < eventsInitl.getColumnDimension(); i++) { int cluster = (int) eventsInitl.getEntry(clusterColumn, i); for (int j = 0; j < selectedClust.length; j++) { if (cluster == selectedClust[j]) { columns.add(i); } } } int[] rows = new int[eventsInitl.getRowDimension()]; for (int i = 0; i < rows.length; i++) { rows[i] = i; } return (Array2DRowRealMatrix) eventsInitl.getSubMatrix(rows, ArrayUtils.toPrimitive(columns.toArray(new Integer[0]))); }
From source file:net.larry1123.elec.util.test.config.AbstractConfigTest.java
public void FloatArrayTest(String fieldName, Field testField) { try {//from w w w . ja v a 2s.co m float[] testFieldValue = ArrayUtils.toPrimitive((Float[]) testField.get(getConfigBase())); Assert.assertTrue(ArrayUtils.isEquals(getPropertiesFile().getFloatArray(fieldName), testFieldValue)); } catch (IllegalAccessException e) { assertFailFieldError(fieldName); } }
From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java
/** * Converts a list of BigIntegers to an array of integers. * @param List<BigInteger> list of BigIntegers * @return array of integers *//* w w w . ja v a 2 s. c om*/ public static int[] toIntArray(List<BigInteger> list) { for (BigInteger val : list) { if (!OverFlowUtil.intOverflow(val)) { OverFlowUtil.overflowError(val); } } return ArrayUtils.toPrimitive(list.toArray(new Integer[list.size()])); }
From source file:com.github.jessemull.microflex.util.BigDecimalUtil.java
/** * Converts a list of BigDecimals to an array of integers. * @param List<BigDecimal> list of BigDecimals * @return array of integers *//*from w ww. j a v a 2 s . co m*/ public static int[] toIntArray(List<BigDecimal> list) { for (BigDecimal val : list) { if (!OverFlowUtil.intOverflow(val)) { OverFlowUtil.overflowError(val); } } return ArrayUtils.toPrimitive(list.toArray(new Integer[list.size()])); }