use of de.lmu.ifi.dbs.elki.math.statistics.distribution.estimator.NormalMOMEstimator in project elki by elki-project.
the class WinsorizingEstimatorTest method testNormalDistribution.
@Test
public void testNormalDistribution() {
final double trim = .01;
NormalMOMEstimator mom = NormalMOMEstimator.STATIC;
// We could instantiate directly, but we also want to cover the
// parameterizer class.
ListParameterization config = new ListParameterization();
config.addParameter(WinsorizingEstimator.Parameterizer.INNER_ID, mom);
config.addParameter(WinsorizingEstimator.Parameterizer.WINSORIZE_ID, trim);
WinsorizingEstimator<NormalDistribution> est = ClassGenericsUtil.parameterizeOrAbort(WinsorizingEstimator.class, config);
Random r = new Random(0L);
double[] data = new double[10000];
final int corrupt = (int) Math.floor(data.length * trim * .5);
for (int i = 0; i < data.length; i++) {
data[i] = i < corrupt ? 1e10 : r.nextGaussian();
}
NormalDistribution bad = mom.estimate(data, DoubleArrayAdapter.STATIC);
NormalDistribution good = est.estimate(data, DoubleArrayAdapter.STATIC);
assertEquals("Mean not as expected from naive estimator.", 5e7, bad.getMean(), 1e-2);
assertEquals("Stddev not as expected from naive estimator.", 7e8, bad.getStddev(), 1e7);
assertEquals("Mean not as expected from trimmed estimator.", 0, good.getMean(), 2e-2);
assertEquals("Stddev not as expected from trimmed estimator.", 1.0, good.getStddev(), 2e-2);
}
use of de.lmu.ifi.dbs.elki.math.statistics.distribution.estimator.NormalMOMEstimator in project elki by elki-project.
the class TrimmedEstimatorTest method testNormalDistribution.
@Test
public void testNormalDistribution() {
final double trim = .01;
NormalMOMEstimator mom = NormalMOMEstimator.STATIC;
// We could instantiate directly, but we also want to cover the
// parameterizer class.
ListParameterization config = new ListParameterization();
config.addParameter(TrimmedEstimator.Parameterizer.INNER_ID, mom);
config.addParameter(TrimmedEstimator.Parameterizer.TRIM_ID, trim);
TrimmedEstimator<NormalDistribution> est = ClassGenericsUtil.parameterizeOrAbort(TrimmedEstimator.class, config);
Random r = new Random(0L);
double[] data = new double[10000];
final int corrupt = (int) Math.floor(data.length * trim * .5);
for (int i = 0; i < data.length; i++) {
data[i] = i < corrupt ? 1e10 : r.nextGaussian();
}
NormalDistribution bad = mom.estimate(data, DoubleArrayAdapter.STATIC);
NormalDistribution good = est.estimate(data, DoubleArrayAdapter.STATIC);
assertEquals("Mean not as expected from naive estimator.", 5e7, bad.getMean(), 1e-2);
assertEquals("Stddev not as expected from naive estimator.", 7e8, bad.getStddev(), 1e7);
assertEquals("Mean not as expected from trimmed estimator.", 0, good.getMean(), 1e-2);
assertEquals("Stddev not as expected from trimmed estimator.", 1.0, good.getStddev(), 3e-2);
}
Aggregations