diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/distance/similarityfunction/SharedNearestNeighborSimilarityFunction.java')
-rw-r--r-- | src/de/lmu/ifi/dbs/elki/distance/similarityfunction/SharedNearestNeighborSimilarityFunction.java | 101 |
1 files changed, 41 insertions, 60 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/distance/similarityfunction/SharedNearestNeighborSimilarityFunction.java b/src/de/lmu/ifi/dbs/elki/distance/similarityfunction/SharedNearestNeighborSimilarityFunction.java index 82334e05..74c2534c 100644 --- a/src/de/lmu/ifi/dbs/elki/distance/similarityfunction/SharedNearestNeighborSimilarityFunction.java +++ b/src/de/lmu/ifi/dbs/elki/distance/similarityfunction/SharedNearestNeighborSimilarityFunction.java @@ -1,33 +1,33 @@ package de.lmu.ifi.dbs.elki.distance.similarityfunction; + /* -This file is part of ELKI: -Environment for Developing KDD-Applications Supported by Index-Structures + This file is part of ELKI: + Environment for Developing KDD-Applications Supported by Index-Structures -Copyright (C) 2011 -Ludwig-Maximilians-Universität München -Lehr- und Forschungseinheit für Datenbanksysteme -ELKI Development Team + Copyright (C) 2011 + Ludwig-Maximilians-Universität München + Lehr- und Forschungseinheit für Datenbanksysteme + ELKI Development Team -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU Affero General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. -You should have received a copy of the GNU Affero General Public License -along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ import java.util.Iterator; import de.lmu.ifi.dbs.elki.database.ids.DBID; import de.lmu.ifi.dbs.elki.database.ids.SetDBIDs; import de.lmu.ifi.dbs.elki.database.relation.Relation; -import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance; import de.lmu.ifi.dbs.elki.distance.distancevalue.IntegerDistance; import de.lmu.ifi.dbs.elki.index.preprocessed.snn.SharedNearestNeighborIndex; import de.lmu.ifi.dbs.elki.index.preprocessed.snn.SharedNearestNeighborPreprocessor; @@ -43,10 +43,9 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameteriz * @apiviz.uses Instance oneway - - «create» * * @param <O> object type - * @param <D> distance type */ // todo arthur comment class -public class SharedNearestNeighborSimilarityFunction<O, D extends Distance<D>> extends AbstractIndexBasedSimilarityFunction<O, SharedNearestNeighborIndex<O>, SetDBIDs, IntegerDistance> { +public class SharedNearestNeighborSimilarityFunction<O> extends AbstractIndexBasedSimilarityFunction<O, SharedNearestNeighborIndex<O>, SetDBIDs, IntegerDistance> { /** * Constructor. * @@ -65,46 +64,20 @@ public class SharedNearestNeighborSimilarityFunction<O, D extends Distance<D>> e int intersection = 0; Iterator<DBID> iter1 = neighbors1.iterator(); Iterator<DBID> iter2 = neighbors2.iterator(); - DBID neighbors1ID = null; - DBID neighbors2ID = null; - if(iter1.hasNext()) { - neighbors1ID = iter1.next(); - } - if(iter2.hasNext()) { - neighbors2ID = iter2.next(); - } + DBID neighbors1ID = iter1.hasNext() ? iter1.next() : null; + DBID neighbors2ID = iter2.hasNext() ? iter2.next() : null; while((iter1.hasNext() || iter2.hasNext()) && neighbors1ID != null && neighbors2ID != null) { if(neighbors1ID.equals(neighbors2ID)) { intersection++; - if(iter1.hasNext()) { - neighbors1ID = iter1.next(); - } - else { - neighbors1ID = null; - } - if(iter2.hasNext()) { - neighbors2ID = iter2.next(); - } - else { - neighbors2ID = null; - } + neighbors1ID = iter1.hasNext() ? iter1.next() : null; + neighbors2ID = iter2.hasNext() ? iter2.next() : null; } else if(neighbors2ID.compareTo(neighbors1ID) > 0) { - if(iter1.hasNext()) { - neighbors1ID = iter1.next(); - } - else { - neighbors1ID = null; - } + neighbors1ID = iter1.hasNext() ? iter1.next() : null; } else // neighbors1ID > neighbors2ID { - if(iter2.hasNext()) { - neighbors2ID = iter2.next(); - } - else { - neighbors2ID = null; - } + neighbors2ID = iter2.hasNext() ? iter2.next() : null; } } return intersection; @@ -112,21 +85,27 @@ public class SharedNearestNeighborSimilarityFunction<O, D extends Distance<D>> e @SuppressWarnings("unchecked") @Override - public <T extends O> Instance<T, D> instantiate(Relation<T> database) { + public <T extends O> Instance<T> instantiate(Relation<T> database) { SharedNearestNeighborIndex<O> indexi = indexFactory.instantiate((Relation<O>) database); - return (Instance<T, D>) new Instance<O, D>((Relation<O>) database, indexi); + return (Instance<T>) new Instance<O>((Relation<O>) database, indexi); } /** - * TODO: document + * Instance for a particular database. * * @author Erich Schubert * * @apiviz.uses SharedNearestNeighborIndex * - * @param <D> + * @param <O> Object type */ - public static class Instance<O, D extends Distance<D>> extends AbstractIndexBasedSimilarityFunction.Instance<O, SharedNearestNeighborIndex<O>, SetDBIDs, IntegerDistance> { + public static class Instance<O> extends AbstractIndexBasedSimilarityFunction.Instance<O, SharedNearestNeighborIndex<O>, SetDBIDs, IntegerDistance> { + /** + * Constructor. + * + * @param database Database + * @param preprocessor Index + */ public Instance(Relation<O> database, SharedNearestNeighborIndex<O> preprocessor) { super(database, preprocessor); } @@ -150,8 +129,10 @@ public class SharedNearestNeighborSimilarityFunction<O, D extends Distance<D>> e * @author Erich Schubert * * @apiviz.exclude + * + * @param <O> Object type */ - public static class Parameterizer<O, D extends Distance<D>> extends AbstractIndexBasedSimilarityFunction.Parameterizer<SharedNearestNeighborIndex.Factory<O, SharedNearestNeighborIndex<O>>> { + public static class Parameterizer<O> extends AbstractIndexBasedSimilarityFunction.Parameterizer<SharedNearestNeighborIndex.Factory<O, SharedNearestNeighborIndex<O>>> { @Override protected void makeOptions(Parameterization config) { super.makeOptions(config); @@ -159,8 +140,8 @@ public class SharedNearestNeighborSimilarityFunction<O, D extends Distance<D>> e } @Override - protected SharedNearestNeighborSimilarityFunction<O, D> makeInstance() { - return new SharedNearestNeighborSimilarityFunction<O, D>(factory); + protected SharedNearestNeighborSimilarityFunction<O> makeInstance() { + return new SharedNearestNeighborSimilarityFunction<O>(factory); } } }
\ No newline at end of file |