Search in sources :

Example 1 with DropNaNFilter

use of de.lmu.ifi.dbs.elki.datasource.filter.cleaning.DropNaNFilter in project elki by elki-project.

the class DropNaNFilterTest method defaultParameters.

/**
 * Test with default parameters.
 */
@Test
public void defaultParameters() {
    String filename = UNITTEST + "nan-test-1.csv";
    DropNaNFilter filter = new ELKIBuilder<>(DropNaNFilter.class).build();
    MultipleObjectsBundle filteredBundle = readBundle(filename, filter);
    // Load the test data again without a filter.
    MultipleObjectsBundle unfilteredBundle = readBundle(filename);
    // Get dimensionalities
    int dimFiltered = getFieldDimensionality(filteredBundle, 0, TypeUtil.NUMBER_VECTOR_FIELD);
    int dimUnfiltered = getFieldDimensionality(unfilteredBundle, 0, TypeUtil.NUMBER_VECTOR_FIELD);
    // Ensure that at least a single NaN exists in the unfiltered bundle.
    boolean NaNfound = false;
    for (int row = 0; row < unfilteredBundle.dataLength(); row++) {
        DoubleVector d = get(unfilteredBundle, row, 0, DoubleVector.class);
        for (int col = 0; col < dimUnfiltered; col++) {
            final double v = d.doubleValue(col);
            if (Double.isNaN(v)) {
                NaNfound = true;
                break;
            }
        }
    }
    assertTrue("NaN expected in unfiltered data", NaNfound);
    // Ensure that no single NaN exists in the filtered bundle.
    for (int row = 0; row < filteredBundle.dataLength(); row++) {
        DoubleVector d = get(filteredBundle, row, 0, DoubleVector.class);
        for (int col = 0; col < dimFiltered; col++) {
            assertFalse("NaN not expected", Double.isNaN(d.doubleValue(col)));
        }
    }
}
Also used : DropNaNFilter(de.lmu.ifi.dbs.elki.datasource.filter.cleaning.DropNaNFilter) 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)

Aggregations

DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)1 AbstractDataSourceTest (de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)1 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)1 DropNaNFilter (de.lmu.ifi.dbs.elki.datasource.filter.cleaning.DropNaNFilter)1 Test (org.junit.Test)1