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.outlier.anglebased; 22 23 import static org.junit.Assert.assertTrue; 24 25 import org.junit.Test; 26 27 import de.lmu.ifi.dbs.elki.algorithm.outlier.AbstractOutlierAlgorithmTest; 28 import de.lmu.ifi.dbs.elki.data.DoubleVector; 29 import de.lmu.ifi.dbs.elki.database.AbstractDatabase; 30 import de.lmu.ifi.dbs.elki.database.Database; 31 import de.lmu.ifi.dbs.elki.database.query.knn.PreprocessorKNNQuery; 32 import de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.EuclideanDistanceFunction; 33 import de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.SquaredEuclideanDistanceFunction; 34 import de.lmu.ifi.dbs.elki.distance.similarityfunction.kernel.LinearKernelFunction; 35 import de.lmu.ifi.dbs.elki.distance.similarityfunction.kernel.PolynomialKernelFunction; 36 import de.lmu.ifi.dbs.elki.index.preprocessed.knn.MaterializeKNNPreprocessor; 37 import de.lmu.ifi.dbs.elki.result.outlier.OutlierResult; 38 import de.lmu.ifi.dbs.elki.utilities.ELKIBuilder; 39 import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization; 40 41 /** 42 * Tests the FastABOD algorithm. 43 * 44 * @author Lucia Cichella 45 * @since 0.7.0 46 */ 47 public class FastABODTest extends AbstractOutlierAlgorithmTest { 48 @Test testFastABODLinear()49 public void testFastABODLinear() { 50 Database db = makeSimpleDatabase(UNITTEST + "outlier-3d-3clusters.ascii", 960); 51 OutlierResult result = new ELKIBuilder<FastABOD<DoubleVector>>(FastABOD.class) // 52 .with(FastABOD.Parameterizer.K_ID, 5)// 53 .with(FastABOD.Parameterizer.KERNEL_FUNCTION_ID, LinearKernelFunction.STATIC) // 54 .build().run(db); 55 testAUC(db, "Noise", result, 0.993814148); 56 testSingleScore(result, 945, 0.498653289); 57 } 58 59 @Test testFastABODLinearIndexSquared()60 public void testFastABODLinearIndexSquared() { 61 ListParameterization pars = new ListParameterization(); 62 pars.addParameter(AbstractDatabase.Parameterizer.INDEX_ID, MaterializeKNNPreprocessor.Factory.class); 63 pars.addParameter(MaterializeKNNPreprocessor.Factory.DISTANCE_FUNCTION_ID, SquaredEuclideanDistanceFunction.STATIC); 64 pars.addParameter(MaterializeKNNPreprocessor.Factory.K_ID, 6); 65 Database db = makeSimpleDatabase(UNITTEST + "outlier-3d-3clusters.ascii", 960, pars); 66 assertTrue(db.getKNNQuery(db.getDistanceQuery(db.getRelation(DoubleVector.FIELD), SquaredEuclideanDistanceFunction.STATIC), 5) instanceof PreprocessorKNNQuery); 67 OutlierResult result = new ELKIBuilder<FastABOD<DoubleVector>>(FastABOD.class) // 68 .with(FastABOD.Parameterizer.K_ID, 5)// 69 .with(FastABOD.Parameterizer.KERNEL_FUNCTION_ID, LinearKernelFunction.STATIC) // 70 .build().run(db); 71 testAUC(db, "Noise", result, 0.993814148); 72 testSingleScore(result, 945, 0.498653289); 73 } 74 75 @Test testFastABODLinearIndexEuclidean()76 public void testFastABODLinearIndexEuclidean() { 77 ListParameterization pars = new ListParameterization(); 78 pars.addParameter(AbstractDatabase.Parameterizer.INDEX_ID, MaterializeKNNPreprocessor.Factory.class); 79 pars.addParameter(MaterializeKNNPreprocessor.Factory.DISTANCE_FUNCTION_ID, EuclideanDistanceFunction.STATIC); 80 pars.addParameter(MaterializeKNNPreprocessor.Factory.K_ID, 6); 81 Database db = makeSimpleDatabase(UNITTEST + "outlier-3d-3clusters.ascii", 960, pars); 82 assertTrue(db.getKNNQuery(db.getDistanceQuery(db.getRelation(DoubleVector.FIELD), EuclideanDistanceFunction.STATIC), 5) instanceof PreprocessorKNNQuery); 83 OutlierResult result = new ELKIBuilder<FastABOD<DoubleVector>>(FastABOD.class) // 84 .with(FastABOD.Parameterizer.K_ID, 5)// 85 .with(FastABOD.Parameterizer.KERNEL_FUNCTION_ID, LinearKernelFunction.STATIC) // 86 .build().run(db); 87 testAUC(db, "Noise", result, 0.993814148); 88 testSingleScore(result, 945, 0.498653289); 89 } 90 91 @Test testFastABODPoly1()92 public void testFastABODPoly1() { 93 Database db = makeSimpleDatabase(UNITTEST + "outlier-3d-3clusters.ascii", 960); 94 OutlierResult result = new ELKIBuilder<FastABOD<DoubleVector>>(FastABOD.class) // 95 .with(FastABOD.Parameterizer.K_ID, 5)// 96 .with(FastABOD.Parameterizer.KERNEL_FUNCTION_ID, new PolynomialKernelFunction(1)) // 97 .build().run(db); 98 testAUC(db, "Noise", result, 0.993814148); 99 testSingleScore(result, 945, 0.498653289); 100 } 101 102 @Test testFastABODPoly2()103 public void testFastABODPoly2() { 104 Database db = makeSimpleDatabase(UNITTEST + "outlier-3d-3clusters.ascii", 960); 105 OutlierResult result = new ELKIBuilder<FastABOD<DoubleVector>>(FastABOD.class) // 106 .with(FastABOD.Parameterizer.K_ID, 5).build().run(db); 107 testAUC(db, "Noise", result, 0.94626962962); 108 testSingleScore(result, 945, 3.28913914467E-4); 109 } 110 } 111