Search in sources :

Example 46 with MultipleObjectsBundle

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);
    }
}
Also used : MeanVariance(de.lmu.ifi.dbs.elki.math.MeanVariance) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest) Test(org.junit.Test)

Example 47 with MultipleObjectsBundle

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);
    }
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest) Test(org.junit.Test)

Example 48 with MultipleObjectsBundle

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);
    }
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest) Test(org.junit.Test)

Example 49 with MultipleObjectsBundle

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);
    }
}
Also used : DoubleMinMax(de.lmu.ifi.dbs.elki.math.DoubleMinMax) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest) Test(org.junit.Test)

Example 50 with MultipleObjectsBundle

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());
}
Also used : MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest) Test(org.junit.Test)

Aggregations

MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)72 AbstractDataSourceTest (de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)37 Test (org.junit.Test)37 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)27 ArrayList (java.util.ArrayList)19 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)13 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)10 ELKIBuilder (de.lmu.ifi.dbs.elki.utilities.ELKIBuilder)10 VectorFieldTypeInformation (de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation)9 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)8 List (java.util.List)7 LabelList (de.lmu.ifi.dbs.elki.data.LabelList)5 SimpleTypeInformation (de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation)5 InputStreamDatabaseConnection (de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection)5 InputStream (java.io.InputStream)5 ClassLabel (de.lmu.ifi.dbs.elki.data.ClassLabel)4 TypeInformation (de.lmu.ifi.dbs.elki.data.type.TypeInformation)4 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)4 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)4 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)4