1 /* 2 * This file is part of ELKI: 3 * Environment for Developing KDD-Applications Supported by Index-Structures 4 * 5 * Copyright (C) 2018 6 * ELKI Development Team 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Affero General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 package de.lmu.ifi.dbs.elki.algorithm.clustering.kmeans; 22 23 import org.junit.Test; 24 25 import de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest; 26 import de.lmu.ifi.dbs.elki.data.Clustering; 27 import de.lmu.ifi.dbs.elki.data.DoubleVector; 28 import de.lmu.ifi.dbs.elki.database.Database; 29 import de.lmu.ifi.dbs.elki.utilities.ELKIBuilder; 30 31 /** 32 * Test the k-means-- algorithm 33 * 34 * @author Erich Schubert 35 */ 36 public class KMeansMinusMinusTest extends AbstractClusterAlgorithmTest { 37 @Test testKMeansMinusMinusRateZero()38 public void testKMeansMinusMinusRateZero() { 39 Database db = makeSimpleDatabase(UNITTEST + "different-densities-2d-no-noise.ascii", 1000); 40 Clustering<?> result = new ELKIBuilder<KMeansMinusMinus<DoubleVector>>(KMeansMinusMinus.class) // 41 .with(KMeans.K_ID, 5) // 42 .with(KMeans.SEED_ID, 7) // 43 .with(KMeansMinusMinus.Parameterizer.RATE_ID, 0.) // 44 .build().run(db); 45 testFMeasure(db, result, 0.998005); 46 testClusterSizes(result, new int[] { 199, 200, 200, 200, 201 }); 47 } 48 49 @Test testKMeansMinusMinus()50 public void testKMeansMinusMinus() { 51 Database db = makeSimpleDatabase(UNITTEST + "different-densities-2d-no-noise.ascii", 1000); 52 Clustering<?> result = new ELKIBuilder<KMeansMinusMinus<DoubleVector>>(KMeansMinusMinus.class) // 53 .with(KMeans.K_ID, 5) // 54 .with(KMeans.SEED_ID, 7) // 55 .with(KMeansMinusMinus.Parameterizer.RATE_ID, 0.1) // 56 .build().run(db); 57 testFMeasure(db, result, 0.998); 58 testClusterSizes(result, new int[] { 199, 200, 200, 200, 201 }); 59 } 60 61 @Test testKMeansMinusMinusOutlier()62 public void testKMeansMinusMinusOutlier() { 63 Database db = makeSimpleDatabase(UNITTEST + "different-densities-2d-no-noise.ascii", 1000); 64 Clustering<?> result = new ELKIBuilder<KMeansMinusMinus<DoubleVector>>(KMeansMinusMinus.class) // 65 .with(KMeans.K_ID, 5) // 66 .with(KMeans.SEED_ID, 7) // 67 .with(KMeansMinusMinus.Parameterizer.RATE_ID, 0.1) // 68 .with(KMeansMinusMinus.Parameterizer.NOISE_FLAG_ID) // 69 .build().run(db); 70 testFMeasure(db, result, 0.925621); 71 testClusterSizes(result, new int[] { 100, 116, 184, 200, 200, 200 }); 72 } 73 } 74