Java Code Examples for org.apache.commons.math.stat.StatUtils#mean()

The following examples show how to use org.apache.commons.math.stat.StatUtils#mean() . 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: SemiVarianceTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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 2
Source File: SemiVarianceTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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 3
Source File: SemiVarianceTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@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 4
Source File: SemiVarianceTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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 5
Source File: SemiVarianceTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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 vote down vote up
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: SemiVarianceTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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 8
Source File: SemiVarianceTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@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 9
Source File: SemiVarianceTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
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: RevisedLesk.java    From lesk-wsd-dsm with GNU General Public License v3.0 5 votes vote down vote up
/**
 *
 * @param list
 * @return
 */
public double getMean(List<SynsetOut> list) {
    double[] scores = new double[list.size()];
    int l = 0;
    for (SynsetOut out : list) {
        scores[l] = out.getScore();
        l++;
    }
    return StatUtils.mean(scores);
}