use of de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution in project elki by elki-project.
the class UniformEnhancedMinMaxEstimatorTest method testEstimator.
@Test
public void testEstimator() {
final UniformEnhancedMinMaxEstimator est = instantiate(UniformEnhancedMinMaxEstimator.class, UniformDistribution.class);
load("unif.ascii.gz");
double[] data = this.data.get("random_0_1");
UniformDistribution dist = est.estimate(data, DoubleArrayAdapter.STATIC);
assertStat("min", dist.getMin(), 0., 9.01732745378526E-4);
assertStat("max", dist.getMax(), 1., -0.004500806282453085);
data = this.data.get("random_M1_2");
dist = est.estimate(data, DoubleArrayAdapter.STATIC);
assertStat("min", dist.getMin(), -1., 9.755307678519509E-4);
assertStat("max", dist.getMax(), 2., -0.05135720346097461);
}
use of de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution in project elki by elki-project.
the class UniformMADEstimatorTest method testEstimator.
@Test
public void testEstimator() {
final UniformMADEstimator est = instantiate(UniformMADEstimator.class, UniformDistribution.class);
load("unif.ascii.gz");
double[] data = this.data.get("random_0_1");
UniformDistribution dist = est.estimate(data, DoubleArrayAdapter.STATIC);
assertStat("min", dist.getMin(), 0., -0.0678463817487403);
assertStat("max", dist.getMax(), 1., -0.08100357095680022);
data = this.data.get("random_M1_2");
dist = est.estimate(data, DoubleArrayAdapter.STATIC);
assertStat("min", dist.getMin(), -1., 0.22023127040794166);
assertStat("max", dist.getMax(), 2., -0.058064123720787064);
}
use of de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution in project elki by elki-project.
the class UniformLMMEstimatorTest method testEstimator.
@Test
public void testEstimator() {
final UniformLMMEstimator est = instantiate(UniformLMMEstimator.class, UniformDistribution.class);
load("unif.ascii.gz");
double[] data = this.data.get("random_0_1");
UniformDistribution dist = est.estimate(data, DoubleArrayAdapter.STATIC);
assertStat("min", dist.getMin(), 0., -0.060238890000330725);
assertStat("max", dist.getMax(), 1., -0.058692258199666725);
data = this.data.get("random_M1_2");
dist = est.estimate(data, DoubleArrayAdapter.STATIC);
assertStat("min", dist.getMin(), -1., 0.10386524890401616);
assertStat("max", dist.getMax(), 2., -0.009881863067372043);
}
use of de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution in project elki by elki-project.
the class BestFitEstimator method estimate.
@Override
public <A> Distribution estimate(A data, NumberArrayAdapter<?, A> adapter) {
int numlmm = 0;
for (LMMDistributionEstimator<?> est : lmmests) {
numlmm = Math.max(numlmm, est.getNumMoments());
}
final int len = adapter.size(data);
// Build various statistics:
StatisticalMoments mom = new StatisticalMoments(), logmom = new StatisticalMoments();
double[] x = new double[len], scratch = new double[len], logx = new double[len];
if (LOG.isDebuggingFine()) {
LOG.debugFine("Computing statistical moments and L-Moments.");
}
for (int i = 0; i < len; i++) {
final double val = x[i] = adapter.getDouble(data, i);
if (Double.NEGATIVE_INFINITY < val && val < Double.POSITIVE_INFINITY) {
mom.put(val);
}
}
if (mom.getMax() <= mom.getMin()) {
LOG.warning("Constant distribution detected. Cannot fit.");
return new UniformDistribution(mom.getMin() - 1., mom.getMax() + 1.);
}
// Sort: for L-Moments, but getting the median is now also cheap.
Arrays.sort(x);
double[] lmm;
try {
lmm = (numlmm > 0) ? ProbabilityWeightedMoments.samLMR(x, DoubleArrayAdapter.STATIC, numlmm) : null;
} catch (ArithmeticException e) {
lmm = null;
}
final double min = x[0], median = .5 * (x[len >> 1] + x[(len + 1) >> 1]), max = x[len - 1];
if (LOG.isDebuggingFine()) {
LOG.debugFine("Computing statistical moments in logspace.");
}
// Build logspace copy:
double shift = Math.min(0., min - (max - min) * 1e-10);
for (int i = 0; i < len; i++) {
double val = x[i] - shift;
val = val > 0. ? FastMath.log(val) : Double.NEGATIVE_INFINITY;
logx[i] = val;
if (Double.NEGATIVE_INFINITY < val && val < Double.POSITIVE_INFINITY) {
logmom.put(val);
}
}
double logmedian = .5 * (logx[len >> 1] + logx[(len + 1) >> 1]);
if (LOG.isDebuggingFine()) {
LOG.debugFine("Computing MADs.");
}
double mad = MADDistributionEstimator.computeMAD(x, len, median, scratch);
double logmad = MADDistributionEstimator.computeMAD(logx, len, logmedian, scratch);
BestFit best = new BestFit(x, scratch);
for (MOMDistributionEstimator<?> est : momests) {
try {
best.test(est, est.estimateFromStatisticalMoments(mom));
} catch (ArithmeticException e) {
warnIfDebugging(e, est);
}
}
for (MADDistributionEstimator<?> est : madests) {
try {
best.test(est, est.estimateFromMedianMAD(median, mad));
} catch (ArithmeticException e) {
warnIfDebugging(e, est);
}
}
for (LMMDistributionEstimator<?> est : lmmests) {
if (lmm != null) {
try {
best.test(est, est.estimateFromLMoments(lmm));
} catch (ArithmeticException e) {
warnIfDebugging(e, est);
}
}
}
for (LogMOMDistributionEstimator<?> est : logmomests) {
try {
best.test(est, est.estimateFromLogStatisticalMoments(logmom, shift));
} catch (ArithmeticException e) {
warnIfDebugging(e, est);
}
}
for (LogMADDistributionEstimator<?> est : logmadests) {
try {
best.test(est, est.estimateFromLogMedianMAD(logmedian, logmad, shift));
} catch (ArithmeticException e) {
warnIfDebugging(e, est);
}
}
{
// Uniform estimators.
final UniformMinMaxEstimator est = UniformMinMaxEstimator.STATIC;
best.test(est, est.estimate(min, max));
}
{
// Uniform estimators.
final UniformEnhancedMinMaxEstimator est = UniformEnhancedMinMaxEstimator.STATIC;
best.test(est, est.estimate(min, max, len));
}
if (LOG.isVeryVerbose()) {
LOG.veryverbose("Best distribution fit: " + best.score + " " + best.toString() + " via " + best.est);
}
return best.dist;
}
use of de.lmu.ifi.dbs.elki.math.statistics.distribution.UniformDistribution in project elki by elki-project.
the class UniformMinMaxEstimatorTest method testEstimator.
@Test
public void testEstimator() {
final UniformMinMaxEstimator est = instantiate(UniformMinMaxEstimator.class, UniformDistribution.class);
load("unif.ascii.gz");
double[] data = this.data.get("random_0_1");
UniformDistribution dist = est.estimate(data, DoubleArrayAdapter.STATIC);
assertStat("min", dist.getMin(), 0., 0.005874720050239368);
assertStat("max", dist.getMax(), 1., -0.009473793587313928);
data = this.data.get("random_M1_2");
dist = est.estimate(data, DoubleArrayAdapter.STATIC);
assertStat("min", dist.getMin(), -1., 0.015713867096707856);
assertStat("max", dist.getMax(), 2., -0.0660955397898304);
}
Aggregations