Search in sources :

Example 1 with GammaDistribution

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

the class GammaLMMEstimatorTest method testEstimator.

@Test
public void testEstimator() {
    final GammaLMMEstimator est = instantiate(GammaLMMEstimator.class, GammaDistribution.class);
    load("gamma.ascii.gz");
    double[] data;
    GammaDistribution dist;
    data = this.data.get("random_01_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, -0.024143831016068915);
    assertStat("theta", dist.getTheta(), 1., -0.4761488556215957);
    data = this.data.get("random_01_10");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, -0.017232059547716963);
    assertStat("theta", dist.getTheta(), 10., -2.6377967219041096);
    data = this.data.get("random_01_20");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, 0.011891135303938705);
    assertStat("theta", dist.getTheta(), 20., 2.5465362790672863);
    data = this.data.get("random_01_4");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, -0.016259316169011648);
    assertStat("theta", dist.getTheta(), 4., -0.5556173425954172);
    data = this.data.get("random_1_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 1., -0.031215620776744557);
    assertStat("theta", dist.getTheta(), 1., 0.021666341701912284);
    data = this.data.get("random_2_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 2., -0.5280147873830532);
    assertStat("theta", dist.getTheta(), 1., -0.2819195063992386);
    data = this.data.get("random_4_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 4., -0.2918957768977939);
    assertStat("theta", dist.getTheta(), 1., -0.04257174762794058);
    data = this.data.get("random_4_10");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 4., 0.7661288103063901);
    assertStat("theta", dist.getTheta(), 10., 1.6459692349784252);
}
Also used : GammaDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution) Test(org.junit.Test)

Example 2 with GammaDistribution

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

the class GammaMOMEstimatorTest method testEstimator.

@Test
public void testEstimator() {
    final GammaMOMEstimator est = instantiate(GammaMOMEstimator.class, GammaDistribution.class);
    load("gamma.ascii.gz");
    double[] data;
    GammaDistribution dist;
    data = this.data.get("random_01_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, -0.011436882562034872);
    assertStat("theta", dist.getTheta(), 1., -0.38839660582615465);
    data = this.data.get("random_01_10");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, 0.0017780713508801227);
    assertStat("theta", dist.getTheta(), 10., -0.9468467326462537);
    data = this.data.get("random_01_20");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, 0.056857634309294774);
    assertStat("theta", dist.getTheta(), 20., 11.607475721793783);
    data = this.data.get("random_01_4");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, 0.009782418339349536);
    assertStat("theta", dist.getTheta(), 4., 0.515519106330272);
    data = this.data.get("random_1_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 1., 0.07124310643556875);
    assertStat("theta", dist.getTheta(), 1., 0.12971787024778658);
    data = this.data.get("random_2_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 2., -0.8079041058107865);
    assertStat("theta", dist.getTheta(), 1., -0.4184582828811385);
    data = this.data.get("random_4_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 4., -0.2968009270431873);
    assertStat("theta", dist.getTheta(), 1., -0.04383825176287526);
    data = this.data.get("random_4_10");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 4., 0.8261654492505475);
    assertStat("theta", dist.getTheta(), 10., 1.7926679244060448);
}
Also used : GammaDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution) Test(org.junit.Test)

Example 3 with GammaDistribution

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

the class GammaChoiWetteEstimatorTest method testEstimator.

@Test
public void testEstimator() {
    final GammaChoiWetteEstimator est = instantiate(GammaChoiWetteEstimator.class, GammaDistribution.class);
    load("gamma.ascii.gz");
    double[] data;
    GammaDistribution dist;
    data = this.data.get("random_01_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, -0.011009099958955534);
    assertStat("theta", dist.getTheta(), 1., -0.38544240435289345);
    data = this.data.get("random_01_10");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, -0.006216238778006325);
    assertStat("theta", dist.getTheta(), 10., -1.6579401332478323);
    data = this.data.get("random_01_20");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, -0.009220767058099488);
    assertStat("theta", dist.getTheta(), 20., -1.7076012022695721);
    data = this.data.get("random_01_4");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 0.1, -0.007461952338469469);
    assertStat("theta", dist.getTheta(), 4., -0.19376828640721389);
    data = this.data.get("random_1_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 1., -0.11468841588478029);
    assertStat("theta", dist.getTheta(), 1., -0.06636289064185863);
    data = this.data.get("random_2_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 2., -0.40548211805937684);
    assertStat("theta", dist.getTheta(), 1., -0.2221442322212216);
    data = this.data.get("random_4_1");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 4., -0.21098492020028203);
    assertStat("theta", dist.getTheta(), 1., -0.02168065733894775);
    data = this.data.get("random_4_10");
    dist = est.estimate(data, DoubleArrayAdapter.STATIC);
    assertStat("k", dist.getK(), 4., 1.0411060521829745);
    assertStat("theta", dist.getTheta(), 10., 2.3178722880996556);
}
Also used : GammaDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution) Test(org.junit.Test)

Example 4 with GammaDistribution

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

the class GeneratorXMLDatabaseConnection method processElementGamma.

/**
 * Process a 'gamma' Element in the XML stream.
 *
 * @param cluster
 * @param cur Current document nod
 */
private void processElementGamma(GeneratorSingleCluster cluster, Node cur) {
    double k = 1.0;
    double theta = 1.0;
    String kstr = ((Element) cur).getAttribute(ATTR_K);
    if (kstr != null && kstr.length() > 0) {
        k = ParseUtil.parseDouble(kstr);
    }
    String thetastr = ((Element) cur).getAttribute(ATTR_THETA);
    if (thetastr != null && thetastr.length() > 0) {
        theta = ParseUtil.parseDouble(thetastr);
    }
    // *** New normal distribution generator
    Random random = cluster.getNewRandomGenerator();
    Distribution generator = new GammaDistribution(k, theta, random);
    cluster.addGenerator(generator);
    // TODO: check for unknown attributes.
    XMLNodeIterator iter = new XMLNodeIterator(cur.getFirstChild());
    while (iter.hasNext()) {
        Node child = iter.next();
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            LOG.warning("Unknown element in XML specification file: " + child.getNodeName());
        }
    }
}
Also used : Random(java.util.Random) Element(org.w3c.dom.Element) Distribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution) NormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution) UniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution) GammaDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution) HaltonUniformDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.HaltonUniformDistribution) Node(org.w3c.dom.Node) GammaDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution) XMLNodeIterator(de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)

Aggregations

GammaDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.GammaDistribution)4 Test (org.junit.Test)3 Distribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution)1 HaltonUniformDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.HaltonUniformDistribution)1 NormalDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution)1 UniformDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution)1 XMLNodeIterator (de.lmu.ifi.dbs.elki.utilities.xml.XMLNodeIterator)1 Random (java.util.Random)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1