Search in sources :

Example 1 with LogNormalDistribution

use of de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution in project elki by elki-project.

the class LogNormalLogMADEstimatorTest method testEstimator.

@Test
public void testEstimator() {
    final LogNormalLogMADEstimator est = instantiate(LogNormalLogMADEstimator.class, LogNormalDistribution.class);
    load("lognorm.ascii.gz");
    LogNormalDistribution dist;
    double[] data;
    data = this.data.get("random_0_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 0, -0.03436369913718115);
    assertStat("stddev", dist.getLogStddev(), 1, -0.07952272581038411);
    assertStat("shift", dist.getShift(), 0., 0.);
    data = this.data.get("random_01_01");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 0.1, -0.01931812589596546);
    assertStat("stddev", dist.getLogStddev(), 0.1, -0.023795288575369222);
    assertStat("shift", dist.getShift(), 0., 0.);
    data = this.data.get("random_1_3");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 1., 0.00920155943708334);
    assertStat("stddev", dist.getLogStddev(), 3., 0.11819829486852429);
    assertStat("shift", dist.getShift(), 0., 0.);
}
Also used : LogNormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution) Test(org.junit.Test)

Example 2 with LogNormalDistribution

use of de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution in project elki by elki-project.

the class LogNormalLogMOMEstimatorTest method testEstimator.

@Test
public void testEstimator() {
    final LogNormalLogMOMEstimator est = instantiate(LogNormalLogMOMEstimator.class, LogNormalDistribution.class);
    load("lognorm.ascii.gz");
    LogNormalDistribution dist;
    double[] data;
    data = this.data.get("random_0_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 0, 0.06458262947981522);
    assertStat("stddev", dist.getLogStddev(), 1, -0.03487041814081915);
    assertStat("shift", dist.getShift(), 0., 0.);
    data = this.data.get("random_01_01");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 0.1, -0.013917953897281649);
    assertStat("stddev", dist.getLogStddev(), 0.1, -0.006435134603397549);
    assertStat("shift", dist.getShift(), 0., 0.);
    data = this.data.get("random_1_3");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 1., -0.26911898625563346);
    assertStat("stddev", dist.getLogStddev(), 3., 0.021548283671365187);
    assertStat("shift", dist.getShift(), 0., 0.);
}
Also used : LogNormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution) Test(org.junit.Test)

Example 3 with LogNormalDistribution

use of de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution in project elki by elki-project.

the class LogNormalLevenbergMarquardtKDEEstimator method estimate.

@Override
public <A> LogNormalDistribution estimate(A data, NumberArrayAdapter<?, A> adapter) {
    // We first need the basic parameters:
    final int len = adapter.size(data);
    MeanVariance mv = new MeanVariance();
    // X positions of samples
    double[] x = new double[len];
    for (int i = 0; i < len; i++) {
        final double val = adapter.getDouble(data, i);
        if (!(val > 0)) {
            throw new ArithmeticException("Cannot fit logNormal to a data set which includes non-positive values: " + val);
        }
        x[i] = FastMath.log(val);
        mv.put(x[i]);
    }
    // Sort our copy.
    Arrays.sort(x);
    double median = (x[len >> 1] + x[(len + 1) >> 1]) * .5;
    // Height = density, via KDE.
    KernelDensityEstimator de = new KernelDensityEstimator(x, GaussianKernelDensityFunction.KERNEL, 1e-6);
    double[] y = de.getDensity();
    // Weights:
    double[] s = new double[len];
    Arrays.fill(s, 1.0);
    // Initial parameter estimate:
    double[] params = { median, mv.getSampleStddev(), 1 };
    boolean[] dofit = { true, true, false };
    LevenbergMarquardtMethod fit = new LevenbergMarquardtMethod(GaussianFittingFunction.STATIC, params, dofit, x, y, s);
    fit.run();
    double[] ps = fit.getParams();
    return new LogNormalDistribution(ps[0], ps[1], 0.);
}
Also used : MeanVariance(de.lmu.ifi.dbs.elki.math.MeanVariance) LevenbergMarquardtMethod(de.lmu.ifi.dbs.elki.math.linearalgebra.fitting.LevenbergMarquardtMethod) KernelDensityEstimator(de.lmu.ifi.dbs.elki.math.statistics.KernelDensityEstimator) LogNormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution)

Example 4 with LogNormalDistribution

use of de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution in project elki by elki-project.

the class LogNormalBilkovaLMMEstimatorTest method testEstimator.

@Test
public void testEstimator() {
    final LogNormalBilkovaLMMEstimator est = instantiate(LogNormalBilkovaLMMEstimator.class, LogNormalDistribution.class);
    load("lognorm.ascii.gz");
    LogNormalDistribution dist;
    double[] data;
    data = this.data.get("random_0_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 0, 0.012954431446844161);
    assertStat("stddev", dist.getLogStddev(), 1, 0.014397745529324268);
    assertStat("shift", dist.getShift(), 0., 0.019737855078490796);
    data = this.data.get("random_01_01");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 0.1, -0.3350477334915902);
    assertStat("stddev", dist.getLogStddev(), 0.1, 0.028169367055539768);
    assertStat("shift", dist.getShift(), 0., 0.2975810280046288);
    data = this.data.get("random_1_3");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 1., 0.7242595487466166);
    assertStat("stddev", dist.getLogStddev(), 3., -0.9483779269301524);
    assertStat("shift", dist.getShift(), 0., -1.328086501539353);
}
Also used : LogNormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution) Test(org.junit.Test)

Example 5 with LogNormalDistribution

use of de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution in project elki by elki-project.

the class LogNormalLevenbergMarquardtKDEEstimatorTest method testEstimator.

@Test
public void testEstimator() {
    final LogNormalLevenbergMarquardtKDEEstimator est = instantiate(LogNormalLevenbergMarquardtKDEEstimator.class, LogNormalDistribution.class);
    load("lognorm.ascii.gz");
    LogNormalDistribution dist;
    double[] data;
    data = this.data.get("random_0_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 0, -0.04064829672787483);
    assertStat("stddev", dist.getLogStddev(), 1, 0.06714852682167516);
    assertStat("shift", dist.getShift(), 0., 0);
    data = this.data.get("random_01_01");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 0.1, -0.016785891820179408);
    assertStat("stddev", dist.getLogStddev(), 0.1, -0.0012405007940175933);
    assertStat("shift", dist.getShift(), 0., 0);
    data = this.data.get("random_1_3");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("logmean", dist.getLogMean(), 1., 0.020564791063600873);
    assertStat("stddev", dist.getLogStddev(), 3., 0.42629076317933556);
    assertStat("shift", dist.getShift(), 0., 0);
}
Also used : LogNormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution) Test(org.junit.Test)

Aggregations

LogNormalDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.LogNormalDistribution)6 Test (org.junit.Test)5 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)1 LevenbergMarquardtMethod (de.lmu.ifi.dbs.elki.math.linearalgebra.fitting.LevenbergMarquardtMethod)1 KernelDensityEstimator (de.lmu.ifi.dbs.elki.math.statistics.KernelDensityEstimator)1