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());
}
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());
}
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());
}
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;
}
}
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 });
}
Aggregations