use of de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle in project elki by elki-project.
the class InstanceMeanVarianceNormalizationTest method defaultParameters.
/**
* Test with default parameters.
*/
@Test
public void defaultParameters() {
String filename = UNITTEST + "normalization-test-1.csv";
InstanceMeanVarianceNormalization<DoubleVector> filter = new ELKIBuilder<>(InstanceMeanVarianceNormalization.class).build();
MultipleObjectsBundle bundle = readBundle(filename, filter);
int dim = getFieldDimensionality(bundle, 0, TypeUtil.NUMBER_VECTOR_FIELD);
// Verify that the resulting data has mean 0 and variance 1 in each row.
MeanVariance mvs = new MeanVariance();
for (int row = 0; row < bundle.dataLength(); row++) {
mvs.reset();
DoubleVector d = get(bundle, row, 0, DoubleVector.class);
for (int col = 0; col < dim; col++) {
final double v = d.doubleValue(col);
if (v > Double.NEGATIVE_INFINITY && v < Double.POSITIVE_INFINITY) {
mvs.put(v);
}
}
assertEquals("Mean is not 0", 0., mvs.getMean(), 1e-14);
assertEquals("Variance is not 1", 1., mvs.getNaiveVariance(), 1e-14);
}
}
use of de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle in project elki by elki-project.
the class InstanceMinMaxNormalizationTest method defaultParameters.
/**
* Test with default parameters.
*/
@Test
public void defaultParameters() {
String filename = UNITTEST + "normalization-test-1.csv";
InstanceMinMaxNormalization<DoubleVector> filter = new ELKIBuilder<>(InstanceMinMaxNormalization.class).build();
MultipleObjectsBundle bundle = readBundle(filename, filter);
int dim = getFieldDimensionality(bundle, 0, TypeUtil.NUMBER_VECTOR_FIELD);
// Verify that, in each row, the min value is 0 and the max value 1.
DoubleMinMax mms = new DoubleMinMax();
for (int row = 0; row < bundle.dataLength(); row++) {
mms.reset();
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(), 1e-15);
}
}
use of de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle in project elki by elki-project.
the class InstanceRankNormalizationTest method defaultParameters.
/**
* Test with default parameters.
*/
@Test
public void defaultParameters() {
String filename = UNITTEST + "normalization-test-1.csv";
InstanceRankNormalization<DoubleVector> filter = new ELKIBuilder<>(InstanceRankNormalization.class).build();
MultipleObjectsBundle bundle = readBundle(filename, filter);
int dim = getFieldDimensionality(bundle, 0, TypeUtil.NUMBER_VECTOR_FIELD);
// Verify that, in each row, the min value is 0 and the max value 1.
DoubleMinMax mms = new DoubleMinMax();
for (int row = 0; row < bundle.dataLength(); row++) {
mms.reset();
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);
}
}
use of de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle in project elki by elki-project.
the class Log1PlusNormalizationTest method defaultParameters.
/**
* Test with default parameters.
*/
@Test
public void defaultParameters() {
String filename = UNITTEST + "normalization-test-1.csv";
InstanceMinMaxNormalization<DoubleVector> minMaxFilter = new ELKIBuilder<>(InstanceMinMaxNormalization.class).build();
Log1PlusNormalization<DoubleVector> log1plusFilter = new ELKIBuilder<>(Log1PlusNormalization.class).build();
MultipleObjectsBundle bundle = readBundle(filename, minMaxFilter, log1plusFilter);
int dim = getFieldDimensionality(bundle, 0, TypeUtil.NUMBER_VECTOR_FIELD);
// We verify that minimum and maximum values in each row are 0 and 1:
DoubleMinMax mms = new DoubleMinMax();
for (int row = 0; row < bundle.dataLength(); row++) {
mms.reset();
DoubleVector d = get(bundle, row, 0, DoubleVector.class);
for (int col = 0; col < dim; col++) {
final double val = d.doubleValue(col);
if (val > Double.NEGATIVE_INFINITY && val < Double.POSITIVE_INFINITY) {
mms.put(val);
}
}
assertEquals("Minimum not expected", 0., mms.getMin(), 1e-15);
assertEquals("Maximum not expected", 1., mms.getMax(), 1e-15);
}
}
use of de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle in project elki by elki-project.
the class RandomSamplingStreamFilterTest method parameters.
/**
* Test with parameters p as the probability and seed as the random seed.
*/
@Test
public void parameters() {
String filename = UNITTEST + "normalization-test-1.csv";
RandomSamplingStreamFilter filter = //
new ELKIBuilder<>(RandomSamplingStreamFilter.class).with(RandomSamplingStreamFilter.Parameterizer.PROB_ID, //
.5).with(RandomSamplingStreamFilter.Parameterizer.SEED_ID, //
0).build();
MultipleObjectsBundle filteredBundle = readBundle(filename, filter);
// Load the test data again without a filter.
MultipleObjectsBundle unfilteredBundle = readBundle(filename);
// Ensure the first column are the vectors.
assertEquals("Dimensionality", getFieldDimensionality(unfilteredBundle, 0, TypeUtil.NUMBER_VECTOR_FIELD), getFieldDimensionality(filteredBundle, 0, TypeUtil.NUMBER_VECTOR_FIELD));
// Verify that approximately p% of the values were sampled.
assertEquals("Unexpected bundle length", unfilteredBundle.dataLength() * .5, filteredBundle.dataLength(), .05 * filteredBundle.dataLength());
}
Aggregations