List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getVariance
public double getVariance()
From source file:com.github.jessemull.microflex.stat.statdouble.SampleVarianceDoubleWeightsTest.java
/** * Tests the aggregated plate statistics method using the values between the indices. *//*from www.j a v a 2s. c om*/ @Test public void testAggregatedSetIndices() { for (PlateDouble plate : arrayIndices) { int begin = random.nextInt(plate.first().size() - 4); int end = begin + random.nextInt(3) + 3; List<BigDecimal> resultList = new ArrayList<BigDecimal>(); double aggregatedReturned = Precision .round(variance.setsAggregated(plate.dataSet(), weightsIndices, begin, end - begin), precision); for (WellDouble well : plate) { List<BigDecimal> input = well.toBigDecimal().subList(begin, end); for (int i = 0; i < input.size(); i++) { resultList.add(input.get(i).multiply(new BigDecimal(weightsIndices[i]))); } } double[] inputAggregated = new double[resultList.size()]; for (int i = 0; i < resultList.size(); i++) { inputAggregated[i] = resultList.get(i).doubleValue(); } DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated); double resultAggregated = Precision.round(statAggregated.getVariance(), precision); assertTrue(resultAggregated == aggregatedReturned); } }
From source file:com.github.jessemull.microflex.stat.statdouble.SampleVarianceDoubleWeightsTest.java
/** * Tests the aggregated plate statistics method using the values between the indices of * the collection.//from ww w .java 2 s . c o m */ @Test public void testAggregatedSetCollectionIndices() { int begin = random.nextInt(arrayIndices[0].first().size() - 4); int end = begin + random.nextInt(3) + 3; List<WellSetDouble> collection = new ArrayList<WellSetDouble>(); for (PlateDouble plate : arrayIndices) { collection.add(plate.dataSet()); } Map<WellSetDouble, Double> aggregatedReturnedMap = variance.setsAggregated(collection, weightsIndices, begin, end - begin); Map<WellSetDouble, Double> aggregatedResultMap = new TreeMap<WellSetDouble, Double>(); for (WellSetDouble set : collection) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (WellDouble well : set) { List<BigDecimal> input = well.toBigDecimal().subList(begin, end); for (int i = 0; i < input.size(); i++) { resultList.add(input.get(i).multiply(new BigDecimal(weightsIndices[i]))); } } double[] inputAggregated = new double[resultList.size()]; for (int i = 0; i < resultList.size(); i++) { inputAggregated[i] = resultList.get(i).doubleValue(); } DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated); double aggregatedResult = statAggregated.getVariance(); aggregatedResultMap.put(set, aggregatedResult); } for (WellSetDouble set : collection) { double result = Precision.round(aggregatedResultMap.get(set), precision); double returned = Precision.round(aggregatedReturnedMap.get(set), precision); assertTrue(result == returned); } }
From source file:com.github.jessemull.microflex.stat.statdouble.SampleVarianceDoubleWeightsTest.java
/** * Tests the aggregated plate statistics method using the values between the indices of * the array.//from w w w . j ava2 s.c om */ @Test public void testAggregatedSetArrayIndices() { int begin = random.nextInt(arrayIndices[0].first().size() - 4); int end = begin + random.nextInt(3) + 3; WellSetDouble[] setArrayIndices = new WellSetDouble[arrayIndices.length]; for (int i = 0; i < setArrayIndices.length; i++) { setArrayIndices[i] = arrayIndices[i].dataSet(); } Map<WellSetDouble, Double> aggregatedReturnedMap = variance.setsAggregated(setArrayIndices, weightsIndices, begin, end - begin); Map<WellSetDouble, Double> aggregatedResultMap = new TreeMap<WellSetDouble, Double>(); for (WellSetDouble set : setArrayIndices) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (WellDouble well : set) { List<BigDecimal> input = well.toBigDecimal().subList(begin, end); for (int i = 0; i < input.size(); i++) { resultList.add(input.get(i).multiply(new BigDecimal(weightsIndices[i]))); } } double[] inputAggregated = new double[resultList.size()]; for (int i = 0; i < resultList.size(); i++) { inputAggregated[i] = resultList.get(i).doubleValue(); } DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated); double aggregatedResult = statAggregated.getVariance(); aggregatedResultMap.put(set, aggregatedResult); } for (WellSetDouble plate : setArrayIndices) { double result = Precision.round(aggregatedResultMap.get(plate), precision); double returned = Precision.round(aggregatedReturnedMap.get(plate), precision); assertTrue(result == returned); } }
From source file:com.github.jessemull.microflex.stat.statinteger.SampleVarianceIntegerWeightsTest.java
/** * Tests well calculation using indices. */// w w w . j a v a 2 s . co m @Test public void testWellIndices() { for (PlateInteger plate : arrayIndices) { for (WellInteger well : plate) { double[] input = new double[well.size()]; int index = 0; for (double db : well) { input[index] = db * weightsIndices[index]; index++; } int begin = random.nextInt(well.size() - 4); int end = begin + random.nextInt(3) + 3; DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end)); double result = Precision.round(stat.getVariance(), precision); double returned = Precision.round( variance.well(well, ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin), precision); assertTrue(result == returned); } } }
From source file:com.github.jessemull.microflexbiginteger.stat.SampleVarianceTest.java
/** * Tests set calculation using indices.//from w w w . j a va 2 s . c om */ @Test public void testSetIndices() { for (Plate plate : arrayIndices) { int size = arrayIndices[0].first().size(); int begin = random.nextInt(size - 5); int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1); Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>(); Map<Well, BigDecimal> returnedMap = variance.set(plate.dataSet(), begin, end - begin, mc); for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigInteger bi : well) { input[index++] = bi.doubleValue(); } double[] inputArray = ArrayUtils.subarray(input, begin, end); DescriptiveStatistics stat = new DescriptiveStatistics(inputArray); double resultDouble = stat.getVariance(); BigDecimal result = new BigDecimal(resultDouble); resultMap.put(well, result); } for (Well well : plate) { BigDecimal result = resultMap.get(well); BigDecimal returned = returnedMap.get(well); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflexdouble.stat.SampleVarianceWeightsTest.java
/** * Tests well calculation using indices. */// w ww.ja v a2s . c o m @Test public void testWellIndices() { for (Plate plate : arrayIndices) { for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (double db : well) { input[index] = db * weightsIndices[index]; index++; } int begin = random.nextInt(well.size() - 4); int end = begin + random.nextInt(3) + 3; DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end)); double result = Precision.round(stat.getVariance(), precision); double returned = Precision.round( variance.well(well, ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin), precision); assertTrue(result == returned); } } }
From source file:com.github.jessemull.microflex.stat.statbiginteger.SampleVarianceBigIntegerTest.java
/** * Tests set calculation using indices./*from w w w . j a v a 2 s . co m*/ */ @Test public void testSetIndices() { for (PlateBigInteger plate : arrayIndices) { int size = arrayIndices[0].first().size(); int begin = random.nextInt(size - 5); int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1); Map<WellBigInteger, BigDecimal> resultMap = new TreeMap<WellBigInteger, BigDecimal>(); Map<WellBigInteger, BigDecimal> returnedMap = variance.set(plate.dataSet(), begin, end - begin, mc); for (WellBigInteger well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigInteger bi : well) { input[index++] = bi.doubleValue(); } double[] inputArray = ArrayUtils.subarray(input, begin, end); DescriptiveStatistics stat = new DescriptiveStatistics(inputArray); double resultDouble = stat.getVariance(); BigDecimal result = new BigDecimal(resultDouble); resultMap.put(well, result); } for (WellBigInteger well : plate) { BigDecimal result = resultMap.get(well); BigDecimal returned = returnedMap.get(well); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } } }
From source file:com.github.jessemull.microflex.stat.statdouble.SampleVarianceDoubleWeightsTest.java
/** * Tests well calculation using indices. *///ww w .j a v a 2s . c o m @Test public void testWellIndices() { for (PlateDouble plate : arrayIndices) { for (WellDouble well : plate) { double[] input = new double[well.size()]; int index = 0; for (double db : well) { input[index] = db * weightsIndices[index]; index++; } int begin = random.nextInt(well.size() - 4); int end = begin + random.nextInt(3) + 3; DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end)); double result = Precision.round(stat.getVariance(), precision); double returned = Precision.round( variance.well(well, ArrayUtils.subarray(weightsIndices, begin, end), begin, end - begin), precision); assertTrue(result == returned); } } }
From source file:com.github.jessemull.microflex.stat.statbigdecimal.SampleVarianceBigDecimalTest.java
/** * Tests the aggregated plate statistics method. */// w w w. j a v a 2s. c om @Test public void testAggregatedPlate() { for (PlateBigDecimal plate : array) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); BigDecimal aggregatedReturned = variance.platesAggregated(plate, mc); for (WellBigDecimal well : plate) { resultList.addAll(well.data()); } double[] inputAggregated = new double[resultList.size()]; for (int i = 0; i < resultList.size(); i++) { inputAggregated[i] = resultList.get(i).doubleValue(); } DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated); double resultAggregatedDouble = statAggregated.getVariance(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned); assertEquals(corrected[0], corrected[1]); } }
From source file:com.github.jessemull.microflex.stat.statbigdecimal.SampleVarianceBigDecimalTest.java
/** * Tests the aggregated plate statistics method. *//*from w w w. ja va 2 s.c o m*/ @Test public void testAggregatedSet() { for (PlateBigDecimal plate : array) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); BigDecimal aggregatedReturned = variance.setsAggregated(plate.dataSet(), mc); for (WellBigDecimal well : plate) { resultList.addAll(well.data()); } double[] inputAggregated = new double[resultList.size()]; for (int i = 0; i < resultList.size(); i++) { inputAggregated[i] = resultList.get(i).doubleValue(); } DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated); double resultAggregatedDouble = statAggregated.getVariance(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned); assertEquals(corrected[0], corrected[1]); } }