org.apache.commons.math.stat.StatUtils Java Examples
The following examples show how to use
org.apache.commons.math.stat.StatUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DoubleArrayAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testMinMax() { da.addElement(2.0); da.addElement(22.0); da.addElement(-2.0); da.addElement(21.0); da.addElement(22.0); da.addElement(42.0); da.addElement(62.0); da.addElement(22.0); da.addElement(122.0); da.addElement(1212.0); assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE); assertEquals( "Max should be 1212.0", 1212.0, StatUtils.max(da.getElements()), Double.MIN_VALUE); }
Example #2
Source File: SemiVarianceTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testSample() { final double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; final int length = values.length; final double mean = StatUtils.mean(values); // 6.333... final SemiVariance sv = new SemiVariance(); // Default bias correction is true final double downsideSemiVariance = sv.evaluate(values); // Downside is the default Assert.assertEquals(TestUtils.sumSquareDev(new double[] {-2d, 2d, 4d, -2d, 3d, 5d}, mean) / (length - 1), downsideSemiVariance, 1E-14); sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE); final double upsideSemiVariance = sv.evaluate(values); Assert.assertEquals(TestUtils.sumSquareDev(new double[] {22d, 11d, 14d}, mean) / (length - 1), upsideSemiVariance, 1E-14); // Verify that upper + lower semivariance against the mean sum to variance Assert.assertEquals(StatUtils.variance(values), downsideSemiVariance + upsideSemiVariance, 10e-12); }
Example #3
Source File: RealMatrixWrapper.java From Juicebox with MIT License | 6 votes |
private void computePercentiles() { // Statistics, other attributes DoubleArrayList flattenedDataList = new DoubleArrayList(matrix.getColumnDimension() * matrix.getRowDimension()); double min = 1; double max = -1; for (int i = 0; i < matrix.getRowDimension(); i++) { for (int j = 0; j < matrix.getColumnDimension(); j++) { double value = matrix.getEntry(i, j); if (!Double.isNaN(value) && value != 1) { min = value < min ? value : min; max = value > max ? value : max; flattenedDataList.add(value); } } } // Stats double[] flattenedData = flattenedDataList.toArray(); lowerValue = (float) StatUtils.percentile(flattenedData, 5); upperValue = (float) StatUtils.percentile(flattenedData, 95); System.out.println(lowerValue + " " + upperValue); }
Example #4
Source File: DoubleArrayAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testMinMax() { da.addElement(2.0); da.addElement(22.0); da.addElement(-2.0); da.addElement(21.0); da.addElement(22.0); da.addElement(42.0); da.addElement(62.0); da.addElement(22.0); da.addElement(122.0); da.addElement(1212.0); assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE); assertEquals( "Max should be 1212.0", 1212.0, StatUtils.max(da.getElements()), Double.MIN_VALUE); }
Example #5
Source File: SemiVarianceTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSample() { final double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; final int length = values.length; final double mean = StatUtils.mean(values); // 6.333... final SemiVariance sv = new SemiVariance(); // Default bias correction is true final double downsideSemiVariance = sv.evaluate(values); // Downside is the default assertEquals(TestUtils.sumSquareDev(new double[] {-2d, 2d, 4d, -2d, 3d, 5d}, mean) / (length - 1), downsideSemiVariance, 1E-14); sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE); final double upsideSemiVariance = sv.evaluate(values); assertEquals(TestUtils.sumSquareDev(new double[] {22d, 11d, 14d}, mean) / (length - 1), upsideSemiVariance, 1E-14); // Verify that upper + lower semivariance against the mean sum to variance assertEquals(StatUtils.variance(values), downsideSemiVariance + upsideSemiVariance, 10e-12); }
Example #6
Source File: SemiVarianceTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSample() { final double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; final int length = values.length; final double mean = StatUtils.mean(values); // 6.333... final SemiVariance sv = new SemiVariance(); // Default bias correction is true final double downsideSemiVariance = sv.evaluate(values); // Downside is the default assertEquals(TestUtils.sumSquareDev(new double[] {-2d, 2d, 4d, -2d, 3d, 5d}, mean) / (length - 1), downsideSemiVariance, 1E-14); sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE); final double upsideSemiVariance = sv.evaluate(values); assertEquals(TestUtils.sumSquareDev(new double[] {22d, 11d, 14d}, mean) / (length - 1), upsideSemiVariance, 1E-14); // Verify that upper + lower semivariance against the mean sum to variance assertEquals(StatUtils.variance(values), downsideSemiVariance + upsideSemiVariance, 10e-12); }
Example #7
Source File: DoubleArrayAbstractTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void testMinMax() { da.addElement(2.0); da.addElement(22.0); da.addElement(-2.0); da.addElement(21.0); da.addElement(22.0); da.addElement(42.0); da.addElement(62.0); da.addElement(22.0); da.addElement(122.0); da.addElement(1212.0); assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE); assertEquals( "Max should be 1212.0", 1212.0, StatUtils.max(da.getElements()), Double.MIN_VALUE); }
Example #8
Source File: DoubleArrayAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testMinMax() { da.addElement(2.0); da.addElement(22.0); da.addElement(-2.0); da.addElement(21.0); da.addElement(22.0); da.addElement(42.0); da.addElement(62.0); da.addElement(22.0); da.addElement(122.0); da.addElement(1212.0); assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE); assertEquals( "Max should be 1212.0", 1212.0, StatUtils.max(da.getElements()), Double.MIN_VALUE); }
Example #9
Source File: SemiVarianceTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testSample() { final double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; final int length = values.length; final double mean = StatUtils.mean(values); // 6.333... final SemiVariance sv = new SemiVariance(); // Default bias correction is true final double downsideSemiVariance = sv.evaluate(values); // Downside is the default assertEquals(TestUtils.sumSquareDev(new double[] {-2d, 2d, 4d, -2d, 3d, 5d}, mean) / (length - 1), downsideSemiVariance, 1E-14); sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE); final double upsideSemiVariance = sv.evaluate(values); assertEquals(TestUtils.sumSquareDev(new double[] {22d, 11d, 14d}, mean) / (length - 1), upsideSemiVariance, 1E-14); // Verify that upper + lower semivariance against the mean sum to variance assertEquals(StatUtils.variance(values), downsideSemiVariance + upsideSemiVariance, 10e-12); }
Example #10
Source File: SemiVarianceTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testSample() { final double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; final int length = values.length; final double mean = StatUtils.mean(values); // 6.333... final SemiVariance sv = new SemiVariance(); // Default bias correction is true final double downsideSemiVariance = sv.evaluate(values); // Downside is the default Assert.assertEquals(TestUtils.sumSquareDev(new double[] {-2d, 2d, 4d, -2d, 3d, 5d}, mean) / (length - 1), downsideSemiVariance, 1E-14); sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE); final double upsideSemiVariance = sv.evaluate(values); Assert.assertEquals(TestUtils.sumSquareDev(new double[] {22d, 11d, 14d}, mean) / (length - 1), upsideSemiVariance, 1E-14); // Verify that upper + lower semivariance against the mean sum to variance Assert.assertEquals(StatUtils.variance(values), downsideSemiVariance + upsideSemiVariance, 10e-12); }
Example #11
Source File: DoubleArrayAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testMinMax() { da.addElement(2.0); da.addElement(22.0); da.addElement(-2.0); da.addElement(21.0); da.addElement(22.0); da.addElement(42.0); da.addElement(62.0); da.addElement(22.0); da.addElement(122.0); da.addElement(1212.0); assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE); assertEquals( "Max should be 1212.0", 1212.0, StatUtils.max(da.getElements()), Double.MIN_VALUE); }
Example #12
Source File: DoubleArrayAbstractTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test public void testMinMax() { da.addElement(2.0); da.addElement(22.0); da.addElement(-2.0); da.addElement(21.0); da.addElement(22.0); da.addElement(42.0); da.addElement(62.0); da.addElement(22.0); da.addElement(122.0); da.addElement(1212.0); Assert.assertEquals("Min should be -2.0", -2.0, StatUtils.min(da.getElements()), Double.MIN_VALUE); Assert.assertEquals( "Max should be 1212.0", 1212.0, StatUtils.max(da.getElements()), Double.MIN_VALUE); }
Example #13
Source File: BeanListUnivariateImplTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** test stats */ public void testSerialization() { double[] values = {35d, 23d, 42d}; DescriptiveStatistics u = new BeanListUnivariateImpl( patientList, "age" ); assertEquals("total count",3,u.getN(),tolerance); assertEquals("mean", StatUtils.mean(values), u.getMean(), tolerance); assertEquals("min", StatUtils.min(values), u.getMin(), tolerance); assertEquals("max", StatUtils.max(values), u.getMax(), tolerance); assertEquals("var", StatUtils.variance(values), u.getVariance(), tolerance); DescriptiveStatistics u2 = (DescriptiveStatistics)TestUtils.serializeAndRecover(u); assertEquals("total count",3,u2.getN(),tolerance); assertEquals("mean", StatUtils.mean(values), u2.getMean(), tolerance); assertEquals("min", StatUtils.min(values), u2.getMin(), tolerance); assertEquals("max", StatUtils.max(values), u2.getMax(), tolerance); assertEquals("var", StatUtils.variance(values), u2.getVariance(), tolerance); u.clear(); assertEquals("total count",0,u.getN(),tolerance); u2.clear(); assertEquals("total count",0,u2.getN(),tolerance); }
Example #14
Source File: SemiVarianceTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Check that the lower + upper semivariance against the mean sum to the * variance. */ public void testVarianceDecompMeanCutoff() { double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; double variance = StatUtils.variance(values); SemiVariance sv = new SemiVariance(true); // Bias corrected sv.setVarianceDirection(SemiVariance.DOWNSIDE_VARIANCE); final double lower = sv.evaluate(values); sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE); final double upper = sv.evaluate(values); assertEquals(variance, lower + upper, 10e-12); }
Example #15
Source File: UniformRandomGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testMeanAndStandardDeviation() { RandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(17399225432l); UniformRandomGenerator generator = new UniformRandomGenerator(rg); double[] sample = new double[10000]; for (int i = 0; i < sample.length; ++i) { sample[i] = generator.nextNormalizedDouble(); } assertEquals(0.0, StatUtils.mean(sample), 0.07); assertEquals(1.0, StatUtils.variance(sample), 0.02); }
Example #16
Source File: UniformRandomGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testMeanAndStandardDeviation() { RandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(17399225432l); UniformRandomGenerator generator = new UniformRandomGenerator(rg); double[] sample = new double[10000]; for (int i = 0; i < sample.length; ++i) { sample[i] = generator.nextNormalizedDouble(); } assertEquals(0.0, StatUtils.mean(sample), 0.07); assertEquals(1.0, StatUtils.variance(sample), 0.02); }
Example #17
Source File: BeanListUnivariateImplTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** test stats */ public void testSerialization() { double[] values = {35d, 23d, 42d}; DescriptiveStatistics u = new BeanListUnivariateImpl( patientList, "age" ); assertEquals("total count",3,u.getN(),tolerance); assertEquals("mean", StatUtils.mean(values), u.getMean(), tolerance); assertEquals("min", StatUtils.min(values), u.getMin(), tolerance); assertEquals("max", StatUtils.max(values), u.getMax(), tolerance); assertEquals("var", StatUtils.variance(values), u.getVariance(), tolerance); DescriptiveStatistics u2 = (DescriptiveStatistics)TestUtils.serializeAndRecover(u); assertEquals("total count",3,u2.getN(),tolerance); assertEquals("mean", StatUtils.mean(values), u2.getMean(), tolerance); assertEquals("min", StatUtils.min(values), u2.getMin(), tolerance); assertEquals("max", StatUtils.max(values), u2.getMax(), tolerance); assertEquals("var", StatUtils.variance(values), u2.getVariance(), tolerance); u.clear(); assertEquals("total count",0,u.getN(),tolerance); u2.clear(); assertEquals("total count",0,u2.getN(),tolerance); }
Example #18
Source File: SemiVarianceTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Check that the lower + upper semivariance against the mean sum to the * variance. */ public void testVarianceDecompMeanCutoff() { double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; double variance = StatUtils.variance(values); SemiVariance sv = new SemiVariance(true); // Bias corrected sv.setVarianceDirection(SemiVariance.DOWNSIDE_VARIANCE); final double lower = sv.evaluate(values); sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE); final double upper = sv.evaluate(values); assertEquals(variance, lower + upper, 10e-12); }
Example #19
Source File: BeanListUnivariateImplTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** test stats */ public void testStats() { DescriptiveStatistics u = new BeanListUnivariateImpl( patientList, "age" ); double[] values = {35d, 23d, 42d}; assertEquals("total count",3,u.getN(),tolerance); assertEquals("mean", StatUtils.mean(values), u.getMean(), tolerance); assertEquals("min", StatUtils.min(values), u.getMin(), tolerance); assertEquals("max", StatUtils.max(values), u.getMax(), tolerance); assertEquals("var", StatUtils.variance(values), u.getVariance(), tolerance); u.clear(); assertEquals("total count",0,u.getN(),tolerance); }
Example #20
Source File: UniformRandomGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testMeanAndStandardDeviation() { RandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(17399225432l); UniformRandomGenerator generator = new UniformRandomGenerator(rg); double[] sample = new double[10000]; for (int i = 0; i < sample.length; ++i) { sample[i] = generator.nextNormalizedDouble(); } assertEquals(0.0, StatUtils.mean(sample), 0.07); assertEquals(1.0, StatUtils.variance(sample), 0.02); }
Example #21
Source File: GaussianRandomGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testMeanAndStandardDeviation() { RandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(17399225432l); GaussianRandomGenerator generator = new GaussianRandomGenerator(rg); double[] sample = new double[10000]; for (int i = 0; i < sample.length; ++i) { sample[i] = generator.nextNormalizedDouble(); } assertEquals(0.0, StatUtils.mean(sample), 0.012); assertEquals(1.0, StatUtils.variance(sample), 0.01); }
Example #22
Source File: SemiVarianceTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Check that the lower + upper semivariance against the mean sum to the * variance. */ public void testVarianceDecompMeanCutoff() { double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; double variance = StatUtils.variance(values); SemiVariance sv = new SemiVariance(true); // Bias corrected sv.setVarianceDirection(SemiVariance.DOWNSIDE_VARIANCE); final double lower = sv.evaluate(values); sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE); final double upper = sv.evaluate(values); assertEquals(variance, lower + upper, 10e-12); }
Example #23
Source File: VectorUtil.java From graphify with Apache License 2.0 | 5 votes |
public static double getFeatureMatchDistribution(GraphDatabaseService db, Long patternId) { Transaction tx = db.beginTx(); Node startNode = db.getNodeById(patternId); // Feature match distribution List<Double> matches = IteratorUtil.asCollection(db.traversalDescription() .depthFirst() .relationships(withName("HAS_CLASS"), Direction.OUTGOING) .evaluator(Evaluators.fromDepth(1)) .evaluator(Evaluators.toDepth(1)) .traverse(startNode) .relationships()) .stream() .map(p -> ((Integer)p.getProperty("matches")).doubleValue()) .collect(Collectors.toList()); tx.success(); tx.close(); double variance = 1.0; if(matches.size() > 1) { Double[] matchArr = matches.toArray(new Double[matches.size()]); // Get the standard deviation DescriptiveStatistics ds = new DescriptiveStatistics(); matches.forEach(m -> ds.addValue(m.doubleValue() / StatUtils.sum(ArrayUtils.toPrimitive(matchArr)))); variance = ds.getStandardDeviation(); } return variance; }
Example #24
Source File: RevisedLesk.java From lesk-wsd-dsm with GNU General Public License v3.0 | 5 votes |
/** * * @param list * @return */ public double getVariance(List<SynsetOut> list) { double[] scores = new double[list.size()]; int l = 0; for (SynsetOut out : list) { scores[l] = out.getScore(); l++; } return StatUtils.variance(scores); }
Example #25
Source File: OLSMultipleLinearRegressionTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Verifies that calculateYVariance and calculateResidualVariance return consistent * values with direct variance computation from Y, residuals, respectively. */ protected void checkVarianceConsistency(OLSMultipleLinearRegression model) throws Exception { // Check Y variance consistency TestUtils.assertEquals(StatUtils.variance(model.Y.getData()), model.calculateYVariance(), 0); // Check residual variance consistency double[] residuals = model.calculateResiduals().getData(); RealMatrix X = model.X; TestUtils.assertEquals( StatUtils.variance(model.calculateResiduals().getData()) * (residuals.length - 1), model.calculateErrorVariance() * (X.getRowDimension() - X.getColumnDimension()), 1E-20); }
Example #26
Source File: SemiVarianceTest.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Check that the lower + upper semivariance against the mean sum to the * variance. */ public void testVarianceDecompMeanCutoff() { double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; double variance = StatUtils.variance(values); SemiVariance sv = new SemiVariance(true); // Bias corrected sv.setVarianceDirection(SemiVariance.DOWNSIDE_VARIANCE); final double lower = sv.evaluate(values); sv.setVarianceDirection(SemiVariance.UPSIDE_VARIANCE); final double upper = sv.evaluate(values); assertEquals(variance, lower + upper, 10e-12); }
Example #27
Source File: DoubleArrayAbstractTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testAddElementRolling() { ra.addElement(0.5); ra.addElement(1.0); ra.addElement(1.0); ra.addElement(1.0); ra.addElement(1.0); ra.addElement(1.0); ra.addElementRolling(2.0); assertEquals( "There should be 6 elements in the eda", 6, ra.getNumElements()); assertEquals( "The max element should be 2.0", 2.0, StatUtils.max(ra.getElements()), Double.MIN_VALUE); assertEquals( "The min element should be 1.0", 1.0, StatUtils.min(ra.getElements()), Double.MIN_VALUE); for (int i = 0; i < 1024; i++) { ra.addElementRolling(i); } assertEquals( "We just inserted 1024 rolling elements, num elements should still be 6", 6, ra.getNumElements()); }
Example #28
Source File: UniformRandomGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testMeanAndStandardDeviation() { RandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(17399225432l); UniformRandomGenerator generator = new UniformRandomGenerator(rg); double[] sample = new double[10000]; for (int i = 0; i < sample.length; ++i) { sample[i] = generator.nextNormalizedDouble(); } assertEquals(0.0, StatUtils.mean(sample), 0.07); assertEquals(1.0, StatUtils.variance(sample), 0.02); }
Example #29
Source File: UniformRandomGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testMeanAndStandardDeviation() { RandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(17399225432l); UniformRandomGenerator generator = new UniformRandomGenerator(rg); double[] sample = new double[10000]; for (int i = 0; i < sample.length; ++i) { sample[i] = generator.nextNormalizedDouble(); } assertEquals(0.0, StatUtils.mean(sample), 0.07); assertEquals(1.0, StatUtils.variance(sample), 0.02); }
Example #30
Source File: GaussianRandomGeneratorTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testMeanAndStandardDeviation() { RandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(17399225432l); GaussianRandomGenerator generator = new GaussianRandomGenerator(rg); double[] sample = new double[10000]; for (int i = 0; i < sample.length; ++i) { sample[i] = generator.nextNormalizedDouble(); } assertEquals(0.0, StatUtils.mean(sample), 0.012); assertEquals(1.0, StatUtils.variance(sample), 0.01); }