Search in sources :

Example 31 with ELKIBuilder

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

the class KMeansCompareTest method testKMeansCompare.

/**
 * Run KMeans with fixed parameters and compare the result to a golden
 * standard.
 */
@Test
public void testKMeansCompare() {
    Database db = makeSimpleDatabase(UNITTEST + "different-densities-2d-no-noise.ascii", 1000);
    Clustering<?> result = // 
    new ELKIBuilder<KMeansCompare<DoubleVector>>(KMeansCompare.class).with(KMeans.K_ID, // 
    5).with(KMeans.SEED_ID, // 
    7).build().run(db);
    testFMeasure(db, result, 0.998005);
    testClusterSizes(result, new int[] { 199, 200, 200, 200, 201 });
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) Database(de.lmu.ifi.dbs.elki.database.Database) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) AbstractClusterAlgorithmTest(de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest) Test(org.junit.Test)

Example 32 with ELKIBuilder

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

the class KMeansHamerlyTest method testKMeansHamerly.

/**
 * Run KMeans with fixed parameters and compare the result to a golden
 * standard.
 */
@Test
public void testKMeansHamerly() {
    Database db = makeSimpleDatabase(UNITTEST + "different-densities-2d-no-noise.ascii", 1000);
    Clustering<?> result = // 
    new ELKIBuilder<KMeansHamerly<DoubleVector>>(KMeansHamerly.class).with(KMeans.K_ID, // 
    5).with(KMeans.SEED_ID, // 
    7).build().run(db);
    testFMeasure(db, result, 0.998005);
    testClusterSizes(result, new int[] { 199, 200, 200, 200, 201 });
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) Database(de.lmu.ifi.dbs.elki.database.Database) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) AbstractClusterAlgorithmTest(de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest) Test(org.junit.Test)

Example 33 with ELKIBuilder

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

the class NNChainTest method testBetaVariance.

/**
 * Run agglomerative hierarchical clustering with fixed parameters and compare
 * the result to a golden standard.
 */
@Test
public void testBetaVariance() {
    Database db = makeSimpleDatabase(UNITTEST + "single-link-effect.ascii", 638);
    Clustering<?> clustering = // 
    new ELKIBuilder<>(CutDendrogramByNumberOfClusters.class).with(CutDendrogramByNumberOfClusters.Parameterizer.MINCLUSTERS_ID, // 
    3).with(AbstractAlgorithm.ALGORITHM_ID, // 
    NNChain.class).with(AGNES.Parameterizer.LINKAGE_ID, // 
    FlexibleBetaLinkage.class).with(FlexibleBetaLinkage.Parameterizer.BETA_ID, // 
    -.33).build().run(db);
    testFMeasure(db, clustering, 0.9381678);
    testClusterSizes(clustering, new int[] { 200, 217, 221 });
}
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)

Example 34 with ELKIBuilder

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

the class ReplaceNaNWithRandomFilterTest method parameters.

/**
 * Test with standard normal distribution as parameter.
 */
@Test
public void parameters() {
    String filename = UNITTEST + "nan-test-1.csv";
    ReplaceNaNWithRandomFilter filter = // 
    new ELKIBuilder<>(ReplaceNaNWithRandomFilter.class).with(// 
    ReplaceNaNWithRandomFilter.Parameterizer.REPLACEMENT_DISTRIBUTION, new NormalDistribution(0, 1, new Random(0L))).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)));
    // This cast is now safe (vector field):
    int dimFiltered = ((FieldTypeInformation) unfilteredBundle.meta(0)).getDimensionality();
    int dimUnfiltered = ((FieldTypeInformation) unfilteredBundle.meta(0)).getDimensionality();
    assertEquals("Dimensionality expected equal", dimFiltered, dimUnfiltered);
    // Note the indices of the NaN(s) in the data.
    List<IntegerVector> NaNs = new ArrayList<IntegerVector>();
    for (int row = 0; row < unfilteredBundle.dataLength(); row++) {
        Object obj = unfilteredBundle.data(row, 0);
        assertEquals("Unexpected data type", DoubleVector.class, obj.getClass());
        DoubleVector d = (DoubleVector) obj;
        for (int col = 0; col < dimUnfiltered; col++) {
            final double v = d.doubleValue(col);
            if (Double.isNaN(v)) {
                NaNs.add(new IntegerVector(new int[] { row, col }));
            }
        }
    }
    // Verify that at least a single NaN exists in the unfiltered bundle.
    assertTrue("NaN expected in unfiltered data", NaNs.size() > 0);
    for (IntegerVector iv : NaNs) {
        Object obj = filteredBundle.data(iv.intValue(0), 0);
        assertEquals("Unexpected data type", DoubleVector.class, obj.getClass());
        DoubleVector d = (DoubleVector) obj;
        final double v = d.doubleValue(iv.intValue(1));
        assertFalse("NaN not expected", Double.isNaN(v));
    }
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) ArrayList(java.util.ArrayList) FieldTypeInformation(de.lmu.ifi.dbs.elki.data.type.FieldTypeInformation) IntegerVector(de.lmu.ifi.dbs.elki.data.IntegerVector) Random(java.util.Random) NormalDistribution(de.lmu.ifi.dbs.elki.math.statistics.distribution.NormalDistribution) ReplaceNaNWithRandomFilter(de.lmu.ifi.dbs.elki.datasource.filter.cleaning.ReplaceNaNWithRandomFilter) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) Test(org.junit.Test) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest)

Example 35 with ELKIBuilder

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

the class ByLabelFilterTest method parameters.

/**
 * Test with parameter s as the label to look for.
 */
@Test
public void parameters() {
    String s = "yes";
    String filename = UNITTEST + "label-selection-test-1.csv";
    ByLabelFilter filter = // 
    new ELKIBuilder<>(ByLabelFilter.class).with(ByLabelFilter.Parameterizer.LABELFILTER_PATTERN_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.
    assertEquals("Dimensionality", getFieldDimensionality(unfilteredBundle, 0, TypeUtil.NUMBER_VECTOR_FIELD), getFieldDimensionality(filteredBundle, 0, TypeUtil.NUMBER_VECTOR_FIELD));
    // Verify that the filter selected all vectors which match the pattern.
    int count_match = 0;
    for (int row = 0; row < unfilteredBundle.dataLength(); row++) {
        LabelList ll = get(unfilteredBundle, row, 1, LabelList.class);
        if (ll.get(0).equals(s)) {
            count_match++;
        }
    }
    assertTrue("Expected at least one match", count_match > 0);
    assertEquals("Unexpected number of matches", count_match, filteredBundle.dataLength());
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) LabelList(de.lmu.ifi.dbs.elki.data.LabelList) MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) AbstractDataSourceTest(de.lmu.ifi.dbs.elki.datasource.AbstractDataSourceTest) 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