diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca')
5 files changed, 44 insertions, 31 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/AbstractFilteredPCAIndex.java b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/AbstractFilteredPCAIndex.java index 371dbca6..67a2effc 100644 --- a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/AbstractFilteredPCAIndex.java +++ b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/AbstractFilteredPCAIndex.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.index.preprocessed.localpca; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -29,10 +29,10 @@ import de.lmu.ifi.dbs.elki.database.datastore.DataStoreFactory; import de.lmu.ifi.dbs.elki.database.datastore.DataStoreUtil; import de.lmu.ifi.dbs.elki.database.ids.DBIDIter; import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; +import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDList; import de.lmu.ifi.dbs.elki.database.relation.Relation; import de.lmu.ifi.dbs.elki.distance.distancefunction.DistanceFunction; -import de.lmu.ifi.dbs.elki.distance.distancefunction.EuclideanDistanceFunction; -import de.lmu.ifi.dbs.elki.distance.distanceresultlist.DistanceDBIDResult; +import de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.EuclideanDistanceFunction; import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance; import de.lmu.ifi.dbs.elki.index.preprocessed.AbstractPreprocessorIndex; import de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress; @@ -78,10 +78,8 @@ public abstract class AbstractFilteredPCAIndex<NV extends NumberVector<?>> exten this.pca = pca; } - /** - * Preprocessing step. - */ - protected void preprocess() { + @Override + public void initialize() { if(relation == null || relation.size() <= 0) { throw new IllegalArgumentException(ExceptionMessages.DATABASE_EMPTY); } @@ -99,7 +97,7 @@ public abstract class AbstractFilteredPCAIndex<NV extends NumberVector<?>> exten // TODO: use a bulk operation? for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) { - DistanceDBIDResult<DoubleDistance> objects = objectsForPCA(iditer); + DistanceDBIDList<DoubleDistance> objects = objectsForPCA(iditer); PCAFilteredResult pcares = pca.processQueryResult(objects, relation); @@ -123,7 +121,7 @@ public abstract class AbstractFilteredPCAIndex<NV extends NumberVector<?>> exten @Override public PCAFilteredResult getLocalProjection(DBIDRef objid) { if(storage == null) { - preprocess(); + initialize(); } return storage.get(objid); } @@ -136,7 +134,7 @@ public abstract class AbstractFilteredPCAIndex<NV extends NumberVector<?>> exten * @return the list of the objects (i.e. the ids and the distances to the * query object) to be considered within the PCA */ - protected abstract DistanceDBIDResult<DoubleDistance> objectsForPCA(DBIDRef id); + protected abstract DistanceDBIDList<DoubleDistance> objectsForPCA(DBIDRef id); /** * Factory class. @@ -207,7 +205,7 @@ public abstract class AbstractFilteredPCAIndex<NV extends NumberVector<?>> exten @Override protected void makeOptions(Parameterization config) { super.makeOptions(config); - final ObjectParameter<DistanceFunction<NV, DoubleDistance>> pcaDistanceFunctionP = new ObjectParameter<DistanceFunction<NV, DoubleDistance>>(PCA_DISTANCE_ID, DistanceFunction.class, EuclideanDistanceFunction.class); + final ObjectParameter<DistanceFunction<NV, DoubleDistance>> pcaDistanceFunctionP = new ObjectParameter<>(PCA_DISTANCE_ID, DistanceFunction.class, EuclideanDistanceFunction.class); if(config.grab(pcaDistanceFunctionP)) { pcaDistanceFunction = pcaDistanceFunctionP.instantiateClass(config); diff --git a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/FilteredLocalPCAIndex.java b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/FilteredLocalPCAIndex.java index d0780751..2d64cbc0 100644 --- a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/FilteredLocalPCAIndex.java +++ b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/FilteredLocalPCAIndex.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.index.preprocessed.localpca; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team diff --git a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/KNNQueryFilteredPCAIndex.java b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/KNNQueryFilteredPCAIndex.java index 00ce11b8..e6320833 100644 --- a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/KNNQueryFilteredPCAIndex.java +++ b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/KNNQueryFilteredPCAIndex.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.index.preprocessed.localpca; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -26,10 +26,11 @@ package de.lmu.ifi.dbs.elki.index.preprocessed.localpca; import de.lmu.ifi.dbs.elki.data.NumberVector; import de.lmu.ifi.dbs.elki.database.QueryUtil; import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; +import de.lmu.ifi.dbs.elki.database.ids.distance.KNNList; import de.lmu.ifi.dbs.elki.database.query.knn.KNNQuery; import de.lmu.ifi.dbs.elki.database.relation.Relation; +import de.lmu.ifi.dbs.elki.database.relation.RelationUtil; import de.lmu.ifi.dbs.elki.distance.distancefunction.DistanceFunction; -import de.lmu.ifi.dbs.elki.distance.distanceresultlist.KNNResult; import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance; import de.lmu.ifi.dbs.elki.logging.Logging; import de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAFilteredRunner; @@ -74,19 +75,24 @@ public class KNNQueryFilteredPCAIndex<NV extends NumberVector<?>> extends Abstra /** * Constructor. * - * @param database Database to use + * @param relation Database to use * @param pca PCA Runner to use * @param knnQuery KNN Query to use * @param k k value */ - public KNNQueryFilteredPCAIndex(Relation<NV> database, PCAFilteredRunner<NV> pca, KNNQuery<NV, DoubleDistance> knnQuery, int k) { - super(database, pca); + public KNNQueryFilteredPCAIndex(Relation<NV> relation, PCAFilteredRunner<NV> pca, KNNQuery<NV, DoubleDistance> knnQuery, int k) { + super(relation, pca); this.knnQuery = knnQuery; this.k = k; + // Sanity check: + int dim = RelationUtil.dimensionality(relation); + if (dim > 0 && k <= dim) { + LOG.warning("PCA results with k < dim are meaningless. Choose k much larger than the dimensionality."); + } } @Override - protected KNNResult<DoubleDistance> objectsForPCA(DBIDRef id) { + protected KNNList<DoubleDistance> objectsForPCA(DBIDRef id) { return knnQuery.getKNNForDBID(id, k); } @@ -105,6 +111,11 @@ public class KNNQueryFilteredPCAIndex<NV extends NumberVector<?>> extends Abstra return LOG; } + @Override + public void logStatistics() { + // No statistics to log. + } + /** * Factory class. * @@ -150,7 +161,7 @@ public class KNNQueryFilteredPCAIndex<NV extends NumberVector<?>> extends Abstra public KNNQueryFilteredPCAIndex<V> instantiate(Relation<V> relation) { // TODO: set bulk flag, once the parent class supports bulk. KNNQuery<V, DoubleDistance> knnquery = QueryUtil.getKNNQuery(relation, pcaDistanceFunction, k); - return new KNNQueryFilteredPCAIndex<V>(relation, pca, knnquery, k); + return new KNNQueryFilteredPCAIndex<>(relation, pca, knnquery, k); } /** @@ -168,16 +179,15 @@ public class KNNQueryFilteredPCAIndex<NV extends NumberVector<?>> extends Abstra super.makeOptions(config); final IntParameter kP = new IntParameter(K_ID); kP.addConstraint(new GreaterConstraint(0)); - kP.setOptional(true); - if(config.grab(kP)) { + if (config.grab(kP)) { k = kP.getValue(); } } @Override protected Factory<NV> makeInstance() { - return new Factory<NV>(pcaDistanceFunction, pca, k); + return new Factory<>(pcaDistanceFunction, pca, k); } } } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/RangeQueryFilteredPCAIndex.java b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/RangeQueryFilteredPCAIndex.java index bbc00c64..03b49df3 100644 --- a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/RangeQueryFilteredPCAIndex.java +++ b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/RangeQueryFilteredPCAIndex.java @@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.index.preprocessed.localpca; This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures - Copyright (C) 2012 + Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team @@ -26,10 +26,10 @@ package de.lmu.ifi.dbs.elki.index.preprocessed.localpca; import de.lmu.ifi.dbs.elki.data.NumberVector; import de.lmu.ifi.dbs.elki.database.QueryUtil; import de.lmu.ifi.dbs.elki.database.ids.DBIDRef; +import de.lmu.ifi.dbs.elki.database.ids.distance.DistanceDBIDList; import de.lmu.ifi.dbs.elki.database.query.range.RangeQuery; import de.lmu.ifi.dbs.elki.database.relation.Relation; import de.lmu.ifi.dbs.elki.distance.distancefunction.DistanceFunction; -import de.lmu.ifi.dbs.elki.distance.distanceresultlist.DistanceDBIDResult; import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance; import de.lmu.ifi.dbs.elki.logging.Logging; import de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAFilteredRunner; @@ -84,7 +84,7 @@ public class RangeQueryFilteredPCAIndex<NV extends NumberVector<?>> extends Abst } @Override - protected DistanceDBIDResult<DoubleDistance> objectsForPCA(DBIDRef id) { + protected DistanceDBIDList<DoubleDistance> objectsForPCA(DBIDRef id) { return rangeQuery.getRangeForDBID(id, epsilon); } @@ -99,10 +99,15 @@ public class RangeQueryFilteredPCAIndex<NV extends NumberVector<?>> extends Abst } @Override - public Logging getLogger() { + protected Logging getLogger() { return LOG; } + @Override + public void logStatistics() { + // No statistics to log. + } + /** * Factory class. * @@ -142,7 +147,7 @@ public class RangeQueryFilteredPCAIndex<NV extends NumberVector<?>> extends Abst public RangeQueryFilteredPCAIndex<V> instantiate(Relation<V> relation) { // TODO: set bulk flag, once the parent class supports bulk. RangeQuery<V, DoubleDistance> rangequery = QueryUtil.getRangeQuery(relation, pcaDistanceFunction); - return new RangeQueryFilteredPCAIndex<V>(relation, pca, rangequery, epsilon); + return new RangeQueryFilteredPCAIndex<>(relation, pca, rangequery, epsilon); } /** @@ -158,7 +163,7 @@ public class RangeQueryFilteredPCAIndex<NV extends NumberVector<?>> extends Abst @Override protected void makeOptions(Parameterization config) { super.makeOptions(config); - DistanceParameter<DoubleDistance> epsilonP = new DistanceParameter<DoubleDistance>(EPSILON_ID, pcaDistanceFunction != null ? pcaDistanceFunction.getDistanceFactory() : null); + DistanceParameter<DoubleDistance> epsilonP = new DistanceParameter<>(EPSILON_ID, pcaDistanceFunction != null ? pcaDistanceFunction.getDistanceFactory() : null); if(config.grab(epsilonP)) { epsilon = epsilonP.getValue(); } @@ -166,7 +171,7 @@ public class RangeQueryFilteredPCAIndex<NV extends NumberVector<?>> extends Abst @Override protected Factory<NV> makeInstance() { - return new Factory<NV>(pcaDistanceFunction, pca, epsilon); + return new Factory<>(pcaDistanceFunction, pca, epsilon); } } } diff --git a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/package-info.java b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/package-info.java index 2bd9cc7d..536dbb3c 100644 --- a/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/package-info.java +++ b/src/de/lmu/ifi/dbs/elki/index/preprocessed/localpca/package-info.java @@ -5,7 +5,7 @@ This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures -Copyright (C) 2012 +Copyright (C) 2013 Ludwig-Maximilians-Universität München Lehr- und Forschungseinheit für Datenbanksysteme ELKI Development Team |