Search in sources :

Example 1 with NormalMOMEstimator

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);
}
Also used : Random(java.util.Random) NormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution) NormalMOMEstimator(de.lmu.ifi.dbs.elki.math.statistics.distribution.estimator.NormalMOMEstimator) ListParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization) Test(org.junit.Test)

Example 2 with NormalMOMEstimator

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);
}
Also used : Random(java.util.Random) NormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution) NormalMOMEstimator(de.lmu.ifi.dbs.elki.math.statistics.distribution.estimator.NormalMOMEstimator) ListParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization) Test(org.junit.Test)

Aggregations

NormalDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution)2 NormalMOMEstimator (de.lmu.ifi.dbs.elki.math.statistics.distribution.estimator.NormalMOMEstimator)2 ListParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization)2 Random (java.util.Random)2 Test (org.junit.Test)2