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.data.model.MedoidModel;
29 import de.lmu.ifi.dbs.elki.database.Database;
30 import de.lmu.ifi.dbs.elki.utilities.ELKIBuilder;
31 
32 /**
33  * Regression test for CLARANS
34  *
35  * @author Erich Schubert
36  */
37 public class CLARANSTest extends AbstractClusterAlgorithmTest {
38   @Test
testCLARANS()39   public void testCLARANS() {
40     Database db = makeSimpleDatabase(UNITTEST + "different-densities-2d-no-noise.ascii", 1000);
41     Clustering<MedoidModel> result = new ELKIBuilder<CLARANS<DoubleVector>>(CLARANS.class) //
42         .with(KMeans.K_ID, 5) //
43         .with(CLARANS.Parameterizer.RANDOM_ID, 0) //
44         .with(CLARANS.Parameterizer.NEIGHBORS_ID, 5) //
45         .with(CLARANS.Parameterizer.RESTARTS_ID, 5) //
46         .build().run(db);
47     // This test uses fairly low parameters. It's easy to find some that give
48     // perfect results, but that is less useful for regression testing.
49     testFMeasure(db, result, 0.76375);
50     testClusterSizes(result, new int[] { 114, 173, 200, 200, 313 });
51   }
52 
53   @Test
testCLARANSNoise()54   public void testCLARANSNoise() {
55     Database db = makeSimpleDatabase(UNITTEST + "3clusters-and-noise-2d.csv", 330);
56     Clustering<MedoidModel> result = new ELKIBuilder<CLARANS<DoubleVector>>(CLARANS.class) //
57         .with(KMeans.K_ID, 3) //
58         .with(CLARANS.Parameterizer.RANDOM_ID, 0) //
59         .with(CLARANS.Parameterizer.NEIGHBORS_ID, .1) //
60         .with(CLARANS.Parameterizer.RESTARTS_ID, 5) //
61         .build().run(db);
62     testFMeasure(db, result, 0.913858);
63     testClusterSizes(result, new int[] { 57, 115, 158 });
64   }
65 }
66