List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getVariance
public double getVariance()
From source file:com.github.jessemull.microflex.stat.statbigdecimal.PopulationVarianceBigDecimalTest.java
/** * Tests the aggregated plate statistics method using a collection. *///from w w w . ja va2 s. c om @Test public void testAggregatedPlateCollection() { List<PlateBigDecimal> collection = Arrays.asList(array); Map<PlateBigDecimal, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(collection, mc); Map<PlateBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigDecimal, BigDecimal>(); for (PlateBigDecimal plate : collection) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); 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(); resultAggregatedDouble *= resultList.size() - 1; resultAggregatedDouble /= resultList.size(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); aggregatedResultMap.put(plate, aggregatedResult); } for (PlateBigDecimal plate : collection) { BigDecimal result = aggregatedResultMap.get(plate); BigDecimal returned = aggregatedReturnedMap.get(plate); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } }
From source file:com.github.jessemull.microflex.stat.statbigdecimal.PopulationVarianceBigDecimalTest.java
/** * Tests the aggregated plate statistics method using an array. *///from w w w. j av a 2 s . c om @Test public void testAggregatedPlateArray() { Map<PlateBigDecimal, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(array, mc); Map<PlateBigDecimal, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigDecimal, BigDecimal>(); for (PlateBigDecimal plate : array) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); 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(); resultAggregatedDouble *= resultList.size() - 1; resultAggregatedDouble /= resultList.size(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); aggregatedResultMap.put(plate, aggregatedResult); } for (PlateBigDecimal plate : array) { BigDecimal result = aggregatedResultMap.get(plate); BigDecimal returned = aggregatedReturnedMap.get(plate); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } }
From source file:com.github.jessemull.microflexbigdecimal.stat.PopulationVarianceTest.java
/** * Tests the aggregated plate statistics method using a collection. *//*from w w w . j av a 2s . c o m*/ @Test public void testAggregatedPlateCollection() { List<Plate> collection = Arrays.asList(array); Map<Plate, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(collection, mc); Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>(); for (Plate plate : collection) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (Well 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(); resultAggregatedDouble *= resultList.size() - 1; resultAggregatedDouble /= resultList.size(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); aggregatedResultMap.put(plate, aggregatedResult); } for (Plate plate : collection) { BigDecimal result = aggregatedResultMap.get(plate); BigDecimal returned = aggregatedReturnedMap.get(plate); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } }
From source file:com.github.jessemull.microflexbigdecimal.stat.PopulationVarianceTest.java
/** * Tests the aggregated plate statistics method using an array. */// ww w. j av a 2 s . c o m @Test public void testAggregatedPlateArray() { Map<Plate, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(array, mc); Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>(); for (Plate plate : array) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (Well 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(); resultAggregatedDouble *= resultList.size() - 1; resultAggregatedDouble /= resultList.size(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); aggregatedResultMap.put(plate, aggregatedResult); } for (Plate plate : array) { BigDecimal result = aggregatedResultMap.get(plate); BigDecimal returned = aggregatedReturnedMap.get(plate); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } }
From source file:com.github.jessemull.microflex.stat.statbiginteger.SampleVarianceBigIntegerWeightsTest.java
/** * Tests the plate statistics method./*w w w .jav a 2 s. c o m*/ */ @Test public void testPlate() { for (PlateBigInteger plate : array) { Map<WellBigInteger, BigDecimal> resultMap = new TreeMap<WellBigInteger, BigDecimal>(); Map<WellBigInteger, BigDecimal> returnedMap = variance.plate(plate, weights, mc); for (WellBigInteger well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigInteger bi : well) { input[index] = bi.doubleValue() * weights[index]; index++; } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getVariance(); BigDecimal result = new BigDecimal(resultDouble, mc); 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.microflexbiginteger.stat.PopulationVarianceTest.java
/** * Tests the aggregated plate statistics method using a collection. *//*ww w .j a va 2 s.c om*/ @Test public void testAggregatedPlateCollection() { List<Plate> collection = Arrays.asList(array); Map<Plate, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(collection, mc); Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>(); for (Plate plate : collection) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (Well well : plate) { resultList.addAll(well.toBigDecimal()); } 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(); resultAggregatedDouble *= resultList.size() - 1; resultAggregatedDouble /= resultList.size(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); aggregatedResultMap.put(plate, aggregatedResult); } for (Plate plate : collection) { BigDecimal result = aggregatedResultMap.get(plate); BigDecimal returned = aggregatedReturnedMap.get(plate); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } }
From source file:com.github.jessemull.microflexbiginteger.stat.PopulationVarianceTest.java
/** * Tests the aggregated plate statistics method using an array. */// ww w . ja va 2 s . c om @Test public void testAggregatedPlateArray() { Map<Plate, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(array, mc); Map<Plate, BigDecimal> aggregatedResultMap = new TreeMap<Plate, BigDecimal>(); for (Plate plate : array) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (Well well : plate) { resultList.addAll(well.toBigDecimal()); } 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(); resultAggregatedDouble *= resultList.size() - 1; resultAggregatedDouble /= resultList.size(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); aggregatedResultMap.put(plate, aggregatedResult); } for (Plate plate : array) { BigDecimal result = aggregatedResultMap.get(plate); BigDecimal returned = aggregatedReturnedMap.get(plate); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } }
From source file:com.github.jessemull.microflexbiginteger.stat.SampleVarianceWeightsTest.java
/** * Tests the plate statistics method./* w ww .j av a 2 s . c o m*/ */ @Test public void testPlate() { for (Plate plate : array) { Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>(); Map<Well, BigDecimal> returnedMap = variance.plate(plate, weights, mc); for (Well well : plate) { double[] input = new double[well.size()]; int index = 0; for (BigInteger bi : well) { input[index] = bi.doubleValue() * weights[index]; index++; } DescriptiveStatistics stat = new DescriptiveStatistics(input); double resultDouble = stat.getVariance(); BigDecimal result = new BigDecimal(resultDouble, mc); 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.microflex.stat.statbiginteger.PopulationVarianceBigIntegerTest.java
/** * Tests the aggregated plate statistics method using a collection. *///from w ww . j ava 2s . co m @Test public void testAggregatedPlateCollection() { List<PlateBigInteger> collection = Arrays.asList(array); Map<PlateBigInteger, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(collection, mc); Map<PlateBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigInteger, BigDecimal>(); for (PlateBigInteger plate : collection) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (WellBigInteger well : plate) { resultList.addAll(well.toBigDecimal()); } 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(); resultAggregatedDouble *= resultList.size() - 1; resultAggregatedDouble /= resultList.size(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); aggregatedResultMap.put(plate, aggregatedResult); } for (PlateBigInteger plate : collection) { BigDecimal result = aggregatedResultMap.get(plate); BigDecimal returned = aggregatedReturnedMap.get(plate); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } }
From source file:com.github.jessemull.microflex.stat.statbiginteger.PopulationVarianceBigIntegerTest.java
/** * Tests the aggregated plate statistics method using an array. *//*from w ww . j av a 2s . c o m*/ @Test public void testAggregatedPlateArray() { Map<PlateBigInteger, BigDecimal> aggregatedReturnedMap = variance.platesAggregated(array, mc); Map<PlateBigInteger, BigDecimal> aggregatedResultMap = new TreeMap<PlateBigInteger, BigDecimal>(); for (PlateBigInteger plate : array) { List<BigDecimal> resultList = new ArrayList<BigDecimal>(); for (WellBigInteger well : plate) { resultList.addAll(well.toBigDecimal()); } 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(); resultAggregatedDouble *= resultList.size() - 1; resultAggregatedDouble /= resultList.size(); BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble); aggregatedResultMap.put(plate, aggregatedResult); } for (PlateBigInteger plate : array) { BigDecimal result = aggregatedResultMap.get(plate); BigDecimal returned = aggregatedReturnedMap.get(plate); BigDecimal[] corrected = correctRoundingErrors(result, returned); assertEquals(corrected[0], corrected[1]); } }