Search in sources :

Example 96 with ELKIBuilder

use of de.lmu.ifi.dbs.elki.utilities.ELKIBuilder in project elki by elki-project.

the class SplitNumberVectorFilterTest method parameters.

/**
 * Test with parameter s as a list of the columns to split into the first
 * bundle column.
 */
@Test
public void parameters() {
    String s = "0,1,2,3,4";
    int s_int = 5;
    String filename = UNITTEST + "dimensionality-test-1.csv";
    SplitNumberVectorFilter<DoubleVector> filter = // 
    new ELKIBuilder<>(SplitNumberVectorFilter.class).with(SplitNumberVectorFilter.Parameterizer.SELECTED_ATTRIBUTES_ID, s).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.
    assertTrue("Test file not as expected", TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(filteredBundle.meta(0)));
    assertTrue("Test file not as expected", TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(unfilteredBundle.meta(0)));
    // Verify that the filter has split the columns represented by s into the
    // bundle's first column.
    Object obj = filteredBundle.data(0, 0);
    assertEquals("Unexpected data type", DoubleVector.class, obj.getClass());
    DoubleVector d = (DoubleVector) obj;
    assertEquals("Unexpected dimensionality", s_int, d.getDimensionality());
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) 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 97 with ELKIBuilder

use of de.lmu.ifi.dbs.elki.utilities.ELKIBuilder in project elki by elki-project.

the class SparseNumberVectorLabelParserTest method parameters.

@Test
public void parameters() throws IOException {
    String filename = UNITTEST + "parsertest.sparse";
    Parser parser = // 
    new ELKIBuilder<>(SparseNumberVectorLabelParser.class).with(NumberVectorLabelParser.Parameterizer.VECTOR_TYPE_ID, // 
    SparseDoubleVector.Factory.class).build();
    MultipleObjectsBundle bundle;
    try (InputStream is = open(filename);
        InputStreamDatabaseConnection dbc = new InputStreamDatabaseConnection(is, null, parser)) {
        bundle = dbc.loadData();
    }
    // Ensure that the filter has correctly formed the bundle.
    // We expect that the bundle's first column is a number vector field.
    // We expect that the bundle's second column is a LabelList
    // Ensure the first column are the vectors.
    assertTrue("Test file not as expected", TypeUtil.SPARSE_VECTOR_VARIABLE_LENGTH.isAssignableFromType(bundle.meta(0)));
    assertTrue("Test file not as expected", TypeUtil.LABELLIST.isAssignableFromType(bundle.meta(1)));
    assertEquals("Length", 3, bundle.dataLength());
    assertEquals("Length", 4, ((SparseNumberVector) bundle.data(0, 0)).getDimensionality());
    // Ensure that the third column are the LabelList objects.
    assertEquals("Unexpected data type", SparseDoubleVector.class, bundle.data(0, 0).getClass());
    assertEquals("Unexpected data type", LabelList.class, bundle.data(0, 1).getClass());
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) InputStream(java.io.InputStream) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) InputStreamDatabaseConnection(de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection) Test(org.junit.Test) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)

Example 98 with ELKIBuilder

use of de.lmu.ifi.dbs.elki.utilities.ELKIBuilder in project elki by elki-project.

the class TermFrequencyParserTest method parameters.

@Test
public void parameters() throws IOException {
    String filename = UNITTEST + "parsertest.tf";
    Parser parser = // 
    new ELKIBuilder<>(TermFrequencyParser.class).with(// 
    TermFrequencyParser.Parameterizer.NORMALIZE_FLAG).build();
    MultipleObjectsBundle bundle;
    try (InputStream is = open(filename);
        InputStreamDatabaseConnection dbc = new InputStreamDatabaseConnection(is, null, parser)) {
        bundle = dbc.loadData();
    }
    // Ensure that the filter has correctly formed the bundle.
    // We expect that the bundle's first column is a number vector field.
    // We expect that the bundle's second column is a LabelList
    // Ensure the first column are the vectors.
    assertTrue("Test file not as expected", TypeUtil.SPARSE_VECTOR_VARIABLE_LENGTH.isAssignableFromType(bundle.meta(0)));
    assertTrue("Test file not as expected", TypeUtil.LABELLIST.isAssignableFromType(bundle.meta(1)));
    assertEquals("Length", 2, bundle.dataLength());
    assertEquals("Length", 2, ((SparseNumberVector) bundle.data(0, 0)).getDimensionality());
    assertEquals("Length", 4, ((SparseNumberVector) bundle.data(1, 0)).getDimensionality());
    // TODO: the map of words to columns is currently NOT kept.
    // Add this, and test this.
    // Ensure that the third column are the LabelList objects.
    assertEquals("Unexpected data type", SparseFloatVector.class, bundle.data(0, 0).getClass());
    assertEquals("Unexpected data type", LabelList.class, bundle.data(0, 1).getClass());
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) InputStream(java.io.InputStream) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) InputStreamDatabaseConnection(de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection) Test(org.junit.Test) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)

Example 99 with ELKIBuilder

use of de.lmu.ifi.dbs.elki.utilities.ELKIBuilder in project elki by elki-project.

the class AbstractFrequentItemsetAlgorithmTest method loadTransactions.

/**
 * Load a transaction database.
 *
 * @param filename Filename
 * @param expectedSize Expected size
 * @return Database
 */
public static <T> Database loadTransactions(String filename, int expectedSize) {
    // Allow loading test data from resources.
    try (InputStream is = open(filename)) {
        // Instantiate filters manually. TODO: redesign
        List<ObjectFilter> filterlist = new ArrayList<>();
        filterlist.add(new FixedDBIDsFilter(1));
        // Setup parser and data loading
        SimpleTransactionParser parser = new SimpleTransactionParser(CSVReaderFormat.DEFAULT_FORMAT);
        InputStreamDatabaseConnection dbc = new InputStreamDatabaseConnection(is, filterlist, parser);
        // We want to allow the use of indexes via "params"
        Database db = // 
        new ELKIBuilder<>(StaticArrayDatabase.class).with(AbstractDatabase.Parameterizer.DATABASE_CONNECTION_ID, dbc).build();
        db.initialize();
        Relation<?> rel = db.getRelation(TypeUtil.ANY);
        if (expectedSize > 0) {
            assertEquals("Database size does not match.", expectedSize, rel.size());
        }
        return db;
    } catch (IOException e) {
        fail("Test data " + filename + " not found.");
        // Not reached.
        return null;
    }
}
Also used : FixedDBIDsFilter(de.lmu.ifi.dbs.elki.datasource.filter.FixedDBIDsFilter) InputStream(java.io.InputStream) ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) ArrayList(java.util.ArrayList) SimpleTransactionParser(de.lmu.ifi.dbs.elki.datasource.parser.SimpleTransactionParser) Database(de.lmu.ifi.dbs.elki.database.Database) AbstractDatabase(de.lmu.ifi.dbs.elki.database.AbstractDatabase) StaticArrayDatabase(de.lmu.ifi.dbs.elki.database.StaticArrayDatabase) ObjectFilter(de.lmu.ifi.dbs.elki.datasource.filter.ObjectFilter) InputStreamDatabaseConnection(de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection) IOException(java.io.IOException)

Example 100 with ELKIBuilder

use of de.lmu.ifi.dbs.elki.utilities.ELKIBuilder in project elki by elki-project.

the class FastOPTICSTest method testFastOPTICS.

@Test
public void testFastOPTICS() {
    Database db = makeSimpleDatabase(UNITTEST + "hierarchical-2d.ascii", 710);
    Clustering<?> clustering = // 
    new ELKIBuilder<>(OPTICSXi.class).with(OPTICSList.Parameterizer.MINPTS_ID, // 
    18).with(OPTICSXi.Parameterizer.XI_ID, // 
    0.038).with(OPTICSXi.Parameterizer.XIALG_ID, // 
    FastOPTICS.class).with(RandomProjectedNeighborsAndDensities.Parameterizer.RANDOM_ID, // 
    0).build().run(db);
    testFMeasure(db, clustering, 0.75722304);
    testClusterSizes(clustering, new int[] { 4, 5, 5, 6, 7, 8, 13, 23, 26, 35, 42, 57, 94, 166, 219 });
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) Database(de.lmu.ifi.dbs.elki.database.Database) AbstractClusterAlgorithmTest(de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest) Test(org.junit.Test)

Aggregations

ELKIBuilder (de.lmu.ifi.dbs.elki.utilities.ELKIBuilder)114 Test (org.junit.Test)111 Database (de.lmu.ifi.dbs.elki.database.Database)102 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)75 AbstractClusterAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)73 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)26 AbstractOutlierAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.outlier.AbstractOutlierAlgorithmTest)22 Model (de.lmu.ifi.dbs.elki.data.model.Model)11 AbstractDataSourceTest (de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)10 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)10 MedoidModel (de.lmu.ifi.dbs.elki.data.model.MedoidModel)7 SubspaceModel (de.lmu.ifi.dbs.elki.data.model.SubspaceModel)5 InputStreamDatabaseConnection (de.lmu.ifi.dbs.elki.datasource.InputStreamDatabaseConnection)3 WeightedCovarianceMatrixBuilder (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.WeightedCovarianceMatrixBuilder)3 InputStream (java.io.InputStream)3 CorrelationModel (de.lmu.ifi.dbs.elki.data.model.CorrelationModel)2 PercentageEigenPairFilter (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.PercentageEigenPairFilter)2 KolmogorovSmirnovTest (de.lmu.ifi.dbs.elki.math.statistics.tests.KolmogorovSmirnovTest)2 WelchTTest (de.lmu.ifi.dbs.elki.math.statistics.tests.WelchTTest)2 ArrayList (java.util.ArrayList)2