Search in sources :

Example 1 with ListParameterization

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization in project elki by elki-project.

the class UniformDistributionTest method testParameterizer.

@Test
public void testParameterizer() throws ClassInstantiationException {
    load("unif.ascii.gz");
    ListParameterization params = new ListParameterization();
    params.addParameter(UniformDistribution.Parameterizer.MIN_ID, 0.);
    params.addParameter(UniformDistribution.Parameterizer.MAX_ID, 1.);
    Distribution dist = ClassGenericsUtil.parameterizeOrAbort(UniformDistribution.class, params);
    checkPDF(dist, "pdf_scipy_0_1", 1e-15);
}
Also used : ListParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization) Test(org.junit.Test)

Example 2 with ListParameterization

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization in project elki by elki-project.

the class AbstractDistributionEstimatorTest method instantiate.

/**
 * This function is not strictly necessary, as all the estimators will have a
 * {@code STATIC} instance that we can use. But this way, we also cover the
 * parameterization API.
 *
 * We also verify the {@link DistributionEstimator#getDistributionClass()}
 * method here.
 *
 * @param cls Class
 * @param <D> Distribution
 * @param <T> Estimator class
 * @return Instance
 */
public static <D extends Distribution, T extends DistributionEstimator<D>> T instantiate(Class<T> cls, Class<D> dist) {
    try {
        T est = ClassGenericsUtil.tryInstantiate(cls, cls, new ListParameterization());
        assertEquals("Estimator has default toString.", -1, est.toString().indexOf('@'));
        assertEquals("Estimator returns unexpected distribution.", dist, est.getDistributionClass());
        return est;
    } catch (ClassInstantiationException e) {
        fail("Could not instantiate");
        return null;
    }
}
Also used : ClassInstantiationException(de.lmu.ifi.dbs.elki.utilities.exceptions.ClassInstantiationException) ListParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization)

Example 3 with ListParameterization

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization 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 4 with ListParameterization

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization in project elki by elki-project.

the class WeibullDistributionTest method testParameterizer.

@Test
public void testParameterizer() throws ClassInstantiationException {
    load("weibull.ascii.gz");
    ListParameterization params = new ListParameterization();
    params.addParameter(WeibullDistribution.Parameterizer.SHAPE_ID, .1);
    params.addParameter(WeibullDistribution.Parameterizer.SCALE_ID, 4.);
    Distribution dist = ClassGenericsUtil.parameterizeOrAbort(WeibullDistribution.class, params);
    checkPDF(dist, "pdf_scipy_01_4", 1e-15);
}
Also used : ListParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization) Test(org.junit.Test)

Example 5 with ListParameterization

use of de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization in project elki by elki-project.

the class GeneralizedParetoDistributionTest method testParameterizer.

@Test
public void testParameterizer() throws ClassInstantiationException {
    load("gpd.ascii.gz");
    ListParameterization params = new ListParameterization();
    params.addParameter(GeneralizedParetoDistribution.Parameterizer.LOCATION_ID, .1);
    params.addParameter(GeneralizedParetoDistribution.Parameterizer.SCALE_ID, .5);
    params.addParameter(GeneralizedParetoDistribution.Parameterizer.SHAPE_ID, .1);
    Distribution dist = ClassGenericsUtil.parameterizeOrAbort(GeneralizedParetoDistribution.class, params);
    checkPDF(dist, "pdf_scipy_01_05_01", 1e-15);
}
Also used : ListParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization) Test(org.junit.Test)

Aggregations

ListParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization)76 Test (org.junit.Test)68 AbstractIndexStructureTest (de.lmu.ifi.dbs.elki.index.AbstractIndexStructureTest)26 Database (de.lmu.ifi.dbs.elki.database.Database)10 AbstractSimpleAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.AbstractSimpleAlgorithmTest)9 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)9 LinearScanDistanceKNNQuery (de.lmu.ifi.dbs.elki.database.query.knn.LinearScanDistanceKNNQuery)8 HilbertSpatialSorter (de.lmu.ifi.dbs.elki.math.spacefillingcurves.HilbertSpatialSorter)6 SpacefillingKNNPreprocessor (de.lmu.ifi.dbs.elki.index.preprocessed.knn.SpacefillingKNNPreprocessor)5 Random (java.util.Random)3 AbstractClusterAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)2 Model (de.lmu.ifi.dbs.elki.data.model.Model)2 StaticArrayDatabase (de.lmu.ifi.dbs.elki.database.StaticArrayDatabase)2 InputStreamDatabaseConnection (de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection)2 MaterializeKNNAndRKNNPreprocessor (de.lmu.ifi.dbs.elki.index.preprocessed.knn.MaterializeKNNAndRKNNPreprocessor)2 NormalDistribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution)2 NormalMOMEstimator (de.lmu.ifi.dbs.elki.math.statistics.distribution.estimator.NormalMOMEstimator)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ByLabelClustering (de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelClustering)1