SemiVariance extends AbstractUnivariateStatistic implements Serializable { @Override public double evaluate(final double[] values, final int start, final int length) throws MathIllegalArgumentException { double m = (new Mean()).evaluate(values, start, length); return evaluate(values, m, varianceDirection, biasCorrected, 0, values.length); } SemiVariance();  SemiVariance(final boolean biasCorrected);  SemiVariance(final Direction direction);  SemiVariance(final boolean corrected, final Direction direction);  SemiVariance(final SemiVariance original); @Override SemiVariance copy(); static void copy(final SemiVariance source, SemiVariance dest); @Override double evaluate(final double[] values, final int start, final int length); double evaluate(final double[] values, Direction direction); double evaluate(final double[] values, final double cutoff); double evaluate(final double[] values, final double cutoff, final Direction direction); double evaluate(final double[] values, final double cutoff, final Direction direction,
            final boolean corrected, final int start, final int length); boolean isBiasCorrected(); void setBiasCorrected(boolean biasCorrected); Direction getVarianceDirection(); void setVarianceDirection(Direction varianceDirection); static final Direction UPSIDE_VARIANCE; static final Direction DOWNSIDE_VARIANCE; }
@Test public void testSingleDown() { SemiVariance sv = new SemiVariance(); double[] values = { 50.0d }; double singletest = sv.evaluate(values); Assert.assertEquals(0.0d, singletest, 0); }
@Test public void testSingleUp() { SemiVariance sv = new SemiVariance(SemiVariance.UPSIDE_VARIANCE); double[] values = { 50.0d }; double singletest = sv.evaluate(values); Assert.assertEquals(0.0d, singletest, 0); }
@Test public void testNonMeanCutoffs() { double[] values = { -2.0d, 2.0d, 4.0d, -2.0d, 22.0d, 11.0d, 3.0d, 14.0d, 5.0d }; SemiVariance sv = new SemiVariance(false); double singletest = sv.evaluate(values, 1.0d, SemiVariance.DOWNSIDE_VARIANCE, false, 0, values.length); Assert.assertEquals(TestUtils.sumSquareDev(new double[] { -2d, -2d }, 1.0d) / values.length, singletest, 0.01d); singletest = sv.evaluate(values, 3.0d, SemiVariance.UPSIDE_VARIANCE, false, 0, values.length); Assert.assertEquals(TestUtils.sumSquareDev(new double[] { 4d, 22d, 11d, 14d, 5d }, 3.0d) / values.length, singletest, 0.01d); }
@Test public void testNoVariance() { final double[] values = {100d, 100d, 100d, 100d}; SemiVariance sv = new SemiVariance(); Assert.assertEquals(0, sv.evaluate(values), 10E-12); Assert.assertEquals(0, sv.evaluate(values, 100d), 10E-12); Assert.assertEquals(0, sv.evaluate(values, 100d, SemiVariance.UPSIDE_VARIANCE, false, 0, values.length), 10E-12); }