1 /*
2  * This file is part of ELKI:
3  * Environment for Developing KDD-Applications Supported by Index-Structures
4  *
5  * Copyright (C) 2018
6  * ELKI Development Team
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 package de.lmu.ifi.dbs.elki.math.statistics.distribution.estimator;
22 
23 import org.junit.Test;
24 
25 import de.lmu.ifi.dbs.elki.math.statistics.distribution.ExponentialDistribution;
26 import de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.DoubleArrayAdapter;
27 
28 /**
29  * Regression test the estimation for the ExponentialMAD distribution.
30  *
31  * @author Erich Schubert
32  */
33 public class ExponentialMADEstimatorTest extends AbstractDistributionEstimatorTest {
34   @Test
testEstimator()35   public void testEstimator() {
36     final ExponentialMADEstimator est = instantiate(ExponentialMADEstimator.class, ExponentialDistribution.class);
37     load("exp.ascii.gz");
38     double[] data = this.data.get("random_01");
39     ExponentialDistribution dist = est.estimate(data, DoubleArrayAdapter.STATIC);
40     assertStat("rate", dist.getRate(), 0.1, 0.02137482880013364);
41     assertStat("location", dist.getLocation(), 0., -0.13722743786299407);
42     data = this.data.get("random_05");
43     dist = est.estimate(data, DoubleArrayAdapter.STATIC);
44     assertStat("rate", dist.getRate(), 0.5, -0.06730155202710736);
45     assertStat("location", dist.getLocation(), 0., 0.21872961956325065);
46     data = this.data.get("random_1");
47     dist = est.estimate(data, DoubleArrayAdapter.STATIC);
48     assertStat("rate", dist.getRate(), 1., -0.0016575720628470014);
49     assertStat("location", dist.getLocation(), 0., 0.08118001612560888);
50     data = this.data.get("random_2");
51     dist = est.estimate(data, DoubleArrayAdapter.STATIC);
52     assertStat("rate", dist.getRate(), 2., 0.3750780644851286);
53     assertStat("location", dist.getLocation(), 0., 0.0020751800945797427);
54     data = this.data.get("random_4");
55     dist = est.estimate(data, DoubleArrayAdapter.STATIC);
56     assertStat("rate", dist.getRate(), 4., -0.34649949175019046);
57     assertStat("location", dist.getLocation(), 0., -0.003834216389767331);
58   }
59 }
60