use of de.lmu.ifi.dbs.elki.math.MeanVariance in project elki by elki-project.
the class InstanceLogRankNormalizationTest method defaultParameters.
/**
* Test with default parameters.
*/
@Test
public void defaultParameters() {
String filename = UNITTEST + "normalization-test-1.csv";
InstanceLogRankNormalization<DoubleVector> filter = new ELKIBuilder<>(InstanceLogRankNormalization.class).build();
MultipleObjectsBundle bundle = readBundle(filename, filter);
int dim = getFieldDimensionality(bundle, 0, TypeUtil.NUMBER_VECTOR_FIELD);
// Compute the expected mean and variances..
MeanVariance expected = new MeanVariance();
for (int ii = 0; ii < dim; ii++) {
expected.put(Math.log1p(ii / (double) (dim - 1)) * MathUtil.ONE_BY_LOG2);
}
// The smallest value (except for ties) must be mapped to 0, the largest to
// 1. And (again, except for ties), the mean and variance must match above
// expected values of a uniform distribution.
MeanVarianceMinMax mms = new MeanVarianceMinMax();
for (int row = 0; row < bundle.dataLength(); row++) {
DoubleVector d = get(bundle, row, 0, DoubleVector.class);
for (int col = 0; col < dim; col++) {
mms.put(d.doubleValue(col));
}
assertEquals("Min value is not 0", 0., mms.getMin(), 0);
assertEquals("Max value is not 1", 1., mms.getMax(), 0);
assertEquals("Mean value is not as expected", expected.getMean(), mms.getMean(), 1e-14);
assertEquals("Variance is not as expected", expected.getNaiveVariance(), mms.getNaiveVariance(), 1e-14);
mms.reset();
}
}
Aggregations