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);
}
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;
}
}
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);
}
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);
}
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);
}
Aggregations