Java源码示例:org.apache.commons.math3.stat.descriptive.UnivariateStatistic
示例1
@Test
public void testAllTechniquesNullEmpty() {
final double[] nullArray = null;
final double[] emptyArray = new double[] {};
for (final Percentile.EstimationType e : Percentile.EstimationType.values()) {
reset (50, e);
final UnivariateStatistic percentile = getUnivariateStatistic();
try {
percentile.evaluate(nullArray);
Assert.fail("Expecting MathIllegalArgumentException "
+ "for null array");
} catch (final MathIllegalArgumentException ex) {
// expected
}
Assert.assertTrue(Double.isNaN(percentile.evaluate(emptyArray)));
}
}
示例2
@Test
public void testAllTechniquesSingleton() {
final double[] singletonArray = new double[] { 1d };
for (final Percentile.EstimationType e : Percentile.EstimationType.values()) {
reset (50, e);
final UnivariateStatistic percentile = getUnivariateStatistic();
Assert.assertEquals(1d, percentile.evaluate(singletonArray), 0);
Assert.assertEquals(1d, percentile.evaluate(singletonArray, 0, 1),
0);
Assert.assertEquals(1d,
new Percentile().evaluate(singletonArray, 0, 1, 5), 0);
Assert.assertEquals(1d,
new Percentile().evaluate(singletonArray, 0, 1, 100), 0);
Assert.assertTrue(Double.isNaN(percentile.evaluate(singletonArray,
0, 0)));
}
}
示例3
@Test
public void testAllTechniquesEmpty() {
final double[] singletonArray = new double[] { };
for (final Percentile.EstimationType e : Percentile.EstimationType.values()) {
reset (50, e);
final UnivariateStatistic percentile = getUnivariateStatistic();
Assert.assertEquals(Double.NaN, percentile.evaluate(singletonArray),
0);
Assert.assertEquals(Double.NaN, percentile.evaluate(singletonArray,
0, 0),
0);
Assert.assertEquals(Double.NaN,
new Percentile().evaluate(singletonArray, 0, 0, 5), 0);
Assert.assertEquals(Double.NaN,
new Percentile().evaluate(singletonArray, 0, 0, 100), 0);
Assert.assertTrue(Double.isNaN(percentile.evaluate(singletonArray,
0, 0)));
}
}
示例4
@Test
public void testAllTechniquesSingleton() {
final double[] singletonArray = new double[] { 1d };
for (final Percentile.EstimationType e : Percentile.EstimationType.values()) {
reset (50, e);
final UnivariateStatistic percentile = getUnivariateStatistic();
Assert.assertEquals(1d, percentile.evaluate(singletonArray), 0);
Assert.assertEquals(1d, percentile.evaluate(singletonArray, 0, 1),
0);
Assert.assertEquals(1d,
new Percentile().evaluate(singletonArray, 0, 1, 5), 0);
Assert.assertEquals(1d,
new Percentile().evaluate(singletonArray, 0, 1, 100), 0);
Assert.assertTrue(Double.isNaN(percentile.evaluate(singletonArray,
0, 0)));
}
}
示例5
@Test
public void testAllTechniquesNullEmpty() {
final double[] nullArray = null;
final double[] emptyArray = new double[] {};
for (final Percentile.EstimationType e : Percentile.EstimationType.values()) {
reset (50, e);
final UnivariateStatistic percentile = getUnivariateStatistic();
try {
percentile.evaluate(nullArray);
Assert.fail("Expecting MathIllegalArgumentException "
+ "for null array");
} catch (final MathIllegalArgumentException ex) {
// expected
}
Assert.assertTrue(Double.isNaN(percentile.evaluate(emptyArray)));
}
}
示例6
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
@Override
public double apply(UnivariateStatistic stat) {
double[] v = this.getValues();
if (v != null) {
return stat.evaluate(v, 0, v.length);
}
return Double.NaN;
}
示例7
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
@Override
public double apply(UnivariateStatistic stat) {
double[] v = this.getValues();
if (v != null) {
return stat.evaluate(v, 0, v.length);
}
return Double.NaN;
}
示例8
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
@Override
public double apply(UnivariateStatistic stat) {
double[] v = this.getValues();
if (v != null) {
return stat.evaluate(v, 0, v.length);
}
return Double.NaN;
}
示例9
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
@Override
public double apply(UnivariateStatistic stat) {
double[] v = this.getValues();
if (v != null) {
return stat.evaluate(v, 0, v.length);
}
return Double.NaN;
}
示例10
/**
* Apply the given statistic to this univariate collection.
* @param stat the statistic to apply
* @return the computed value of the statistic.
*/
@Override
public double apply(UnivariateStatistic stat) {
double[] v = this.getValues();
if (v != null) {
return stat.evaluate(v, 0, v.length);
}
return Double.NaN;
}
示例11
protected AbstractStatistic(final UnivariateStatistic stat) {
this.stat = stat;
}
示例12
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Variance();
}
示例13
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new GeometricMean();
}
示例14
/**
* @see org.apache.commons.math3.stat.descriptive.UnivariateStatisticAbstractTest#getUnivariateStatistic()
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new FirstMoment();
}
示例15
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Sum();
}
示例16
@Override
public UnivariateStatistic copy() {
return new MeanAboveMedian();
}
示例17
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Variance();
}
示例18
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Sum();
}
示例19
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Skewness();
}
示例20
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new GeometricMean();
}
示例21
/**
* @see org.apache.commons.math3.stat.descriptive.UnivariateStatisticAbstractTest#getUnivariateStatistic()
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new ThirdMoment();
}
示例22
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Mean();
}
示例23
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Percentile(95.0);
}
示例24
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Max();
}
示例25
@Override
public UnivariateStatistic getUnivariateStatistic() {
PSquarePercentile ptile = new PSquarePercentile(95);
// Assert.assertNull(ptile.markers());
return ptile;
}
示例26
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Median();
}
示例27
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new Kurtosis();
}
示例28
/**
* {@inheritDoc}
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new SumOfLogs();
}
示例29
/**
* @see org.apache.commons.math3.stat.descriptive.UnivariateStatisticAbstractTest#getUnivariateStatistic()
*/
@Override
public UnivariateStatistic getUnivariateStatistic() {
return new ThirdMoment();
}
示例30
@Test
public void testAllTechniquesSpecialValues() {
reset(50d, Percentile.EstimationType.LEGACY);
final UnivariateStatistic percentile = getUnivariateStatistic();
double[] specialValues =
new double[] { 0d, 1d, 2d, 3d, 4d, Double.NaN };
Assert.assertEquals(2.5d, percentile.evaluate(specialValues), 0);
testAssertMappedValues(specialValues, new Object[][] {
{ Percentile.EstimationType.LEGACY, 2.5d }, { Percentile.EstimationType.R_1, 2.0 }, { Percentile.EstimationType.R_2, 2.0 }, { Percentile.EstimationType.R_3, 1.0 },
{ Percentile.EstimationType.R_4, 1.5 }, { Percentile.EstimationType.R_5, 2.0 }, { Percentile.EstimationType.R_6, 2.0 },
{ Percentile.EstimationType.R_7, 2.0 }, { Percentile.EstimationType.R_8, 2.0 }, { Percentile.EstimationType.R_9, 2.0 }}, 50d, 0d);
specialValues =
new double[] { Double.NEGATIVE_INFINITY, 1d, 2d, 3d,
Double.NaN, Double.POSITIVE_INFINITY };
Assert.assertEquals(2.5d, percentile.evaluate(specialValues), 0);
testAssertMappedValues(specialValues, new Object[][] {
{ Percentile.EstimationType.LEGACY, 2.5d }, { Percentile.EstimationType.R_1, 2.0 }, { Percentile.EstimationType.R_2, 2.0 }, { Percentile.EstimationType.R_3, 1.0 },
{ Percentile.EstimationType.R_4, 1.5 }, { Percentile.EstimationType.R_5, 2.0 }, { Percentile.EstimationType.R_7, 2.0 }, { Percentile.EstimationType.R_7, 2.0 },
{ Percentile.EstimationType.R_8, 2.0 }, { Percentile.EstimationType.R_9, 2.0 } }, 50d, 0d);
specialValues =
new double[] { 1d, 1d, Double.POSITIVE_INFINITY,
Double.POSITIVE_INFINITY };
Assert.assertTrue(Double.isInfinite(percentile.evaluate(specialValues)));
testAssertMappedValues(specialValues, new Object[][] {
// This is one test not matching with R results.
{ Percentile.EstimationType.LEGACY, Double.POSITIVE_INFINITY },
{ Percentile.EstimationType.R_1,/* 1.0 */Double.NaN },
{ Percentile.EstimationType.R_2, /* Double.POSITIVE_INFINITY */Double.NaN },
{ Percentile.EstimationType.R_3, /* 1.0 */Double.NaN }, { Percentile.EstimationType.R_4, /* 1.0 */Double.NaN },
{ Percentile.EstimationType.R_5, Double.POSITIVE_INFINITY },
{ Percentile.EstimationType.R_6, Double.POSITIVE_INFINITY },
{ Percentile.EstimationType.R_7, Double.POSITIVE_INFINITY },
{ Percentile.EstimationType.R_8, Double.POSITIVE_INFINITY },
{ Percentile.EstimationType.R_9, Double.POSITIVE_INFINITY }, }, 50d, 0d);
specialValues = new double[] { 1d, 1d, Double.NaN, Double.NaN };
Assert.assertTrue(Double.isNaN(percentile.evaluate(specialValues)));
testAssertMappedValues(specialValues, new Object[][] {
{ Percentile.EstimationType.LEGACY, Double.NaN }, { Percentile.EstimationType.R_1, 1.0 }, { Percentile.EstimationType.R_2, 1.0 }, { Percentile.EstimationType.R_3, 1.0 },
{ Percentile.EstimationType.R_4, 1.0 }, { Percentile.EstimationType.R_5, 1.0 },{ Percentile.EstimationType.R_6, 1.0 },{ Percentile.EstimationType.R_7, 1.0 },
{ Percentile.EstimationType.R_8, 1.0 }, { Percentile.EstimationType.R_9, 1.0 },}, 50d, 0d);
specialValues =
new double[] { 1d, 1d, Double.NEGATIVE_INFINITY,
Double.NEGATIVE_INFINITY };
testAssertMappedValues(specialValues, new Object[][] {
{ Percentile.EstimationType.LEGACY, Double.NaN }, { Percentile.EstimationType.R_1, Double.NaN },
{ Percentile.EstimationType.R_2, Double.NaN }, { Percentile.EstimationType.R_3, Double.NaN }, { Percentile.EstimationType.R_4, Double.NaN },
{ Percentile.EstimationType.R_5, Double.NaN }, { Percentile.EstimationType.R_6, Double.NaN },
{ Percentile.EstimationType.R_7, Double.NaN }, { Percentile.EstimationType.R_8, Double.NaN }, { Percentile.EstimationType.R_9, Double.NaN }
}, 50d, 0d);
}