summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace
diff options
context:
space:
mode:
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace')
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractDimensionsSelectingDistanceFunction.java (renamed from src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractDimensionsSelectingDoubleDistanceFunction.java)71
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractPreferenceVectorBasedCorrelationDistanceFunction.java231
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DiSHDistanceFunction.java163
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DimensionSelectingSubspaceDistanceFunction.java14
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/HiSCDistanceFunction.java158
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/LocalSubspaceDistanceFunction.java152
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/OnedimensionalDistanceFunction.java (renamed from src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DimensionSelectingDistanceFunction.java)92
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceEuclideanDistanceFunction.java32
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceLPNormDistanceFunction.java61
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceManhattanDistanceFunction.java38
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceMaximumDistanceFunction.java66
-rw-r--r--src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/package-info.java4
12 files changed, 165 insertions, 917 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractDimensionsSelectingDoubleDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractDimensionsSelectingDistanceFunction.java
index 052e089c..caf45d9d 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractDimensionsSelectingDoubleDistanceFunction.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractDimensionsSelectingDistanceFunction.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,12 +23,12 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import java.util.BitSet;
+import java.util.List;
import de.lmu.ifi.dbs.elki.data.FeatureVector;
import de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractPrimitiveDistanceFunction;
-import de.lmu.ifi.dbs.elki.distance.distancefunction.PrimitiveDoubleDistanceFunction;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.distance.distancefunction.PrimitiveDistanceFunction;
+import de.lmu.ifi.dbs.elki.utilities.BitsUtil;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.CommonConstraints;
@@ -36,52 +36,47 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameteriz
import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.IntListParameter;
/**
- * Provides a distance function that computes the distance (which is a double
- * distance) between feature vectors only in specified dimensions.
+ * Abstract base class for distances computed only in subspaces.
+ *
+ * Selected dimensions are encuded as bits in a {@code long[]}.
*
* @author Elke Achtert
* @param <V> the type of FeatureVector to compute the distances in between
*/
-public abstract class AbstractDimensionsSelectingDoubleDistanceFunction<V extends FeatureVector<?>> extends AbstractPrimitiveDistanceFunction<V, DoubleDistance> implements PrimitiveDoubleDistanceFunction<V>, DimensionSelectingSubspaceDistanceFunction<V, DoubleDistance> {
- /**
- * Dimensions parameter.
- */
- public static final OptionID DIMS_ID = new OptionID("distance.dims", "a comma separated array of integer values, where 0 <= d_i < the dimensionality of the feature space specifying the dimensions to be considered for distance computation. If this parameter is not set, no dimensions will be considered, i.e. the distance between two objects is always 0.");
-
+public abstract class AbstractDimensionsSelectingDistanceFunction<V extends FeatureVector<?>> extends AbstractPrimitiveDistanceFunction<V> implements PrimitiveDistanceFunction<V>, DimensionSelectingSubspaceDistanceFunction<V> {
/**
* The dimensions to be considered for distance computation.
*/
- protected BitSet dimensions;
+ protected long[] dimensions;
/**
* Constructor.
*
* @param dimensions
*/
- public AbstractDimensionsSelectingDoubleDistanceFunction(BitSet dimensions) {
+ public AbstractDimensionsSelectingDistanceFunction(long[] dimensions) {
super();
this.dimensions = dimensions;
}
@Override
- public DoubleDistance distance(V o1, V o2) {
- return new DoubleDistance(doubleDistance(o1, o2));
+ public double distance(V o1, V o2) {
+ return distance(o1, o2);
}
@Override
- public BitSet getSelectedDimensions() {
+ public long[] getSelectedDimensions() {
return dimensions;
}
@Override
- public void setSelectedDimensions(BitSet dimensions) {
- this.dimensions.clear();
- this.dimensions.or(dimensions);
- }
-
- @Override
- public DoubleDistance getDistanceFactory() {
- return DoubleDistance.FACTORY;
+ public void setSelectedDimensions(long[] dimensions) {
+ if(this.dimensions == null || this.dimensions.length < dimensions.length) {
+ this.dimensions = dimensions.clone();
+ return;
+ }
+ BitsUtil.zeroI(this.dimensions);
+ BitsUtil.orI(this.dimensions, dimensions);
}
@Override
@@ -92,7 +87,7 @@ public abstract class AbstractDimensionsSelectingDoubleDistanceFunction<V extend
if(!this.getClass().equals(obj.getClass())) {
return false;
}
- return this.dimensions.equals(((AbstractDimensionsSelectingDoubleDistanceFunction<?>) obj).dimensions);
+ return this.dimensions.equals(((AbstractDimensionsSelectingDistanceFunction<?>) obj).dimensions);
}
/**
@@ -103,18 +98,28 @@ public abstract class AbstractDimensionsSelectingDoubleDistanceFunction<V extend
* @apiviz.exclude
*/
public abstract static class Parameterizer extends AbstractParameterizer {
- protected BitSet dimensions = null;
+ /**
+ * Dimensions parameter.
+ */
+ public static final OptionID DIMS_ID = new OptionID("distance.dims", "a comma separated array of integer values, where 0 <= d_i < the dimensionality of the feature space specifying the dimensions to be considered for distance computation. If this parameter is not set, no dimensions will be considered, i.e. the distance between two objects is always 0.");
+
+ protected long[] dimensions = null;
@Override
protected void makeOptions(Parameterization config) {
super.makeOptions(config);
- dimensions = new BitSet();
- final IntListParameter dimsP = new IntListParameter(DIMS_ID);
- dimsP.addConstraint(CommonConstraints.GREATER_EQUAL_ZERO_INT_LIST);
- dimsP.setOptional(true);
+ final IntListParameter dimsP = new IntListParameter(DIMS_ID)//
+ .addConstraint(CommonConstraints.GREATER_EQUAL_ZERO_INT_LIST) //
+ .setOptional(true);
if(config.grab(dimsP)) {
- for(int d : dimsP.getValue()) {
- dimensions.set(d);
+ final List<Integer> value = dimsP.getValue();
+ int maxd = 0;
+ for(int d : value) {
+ maxd = (d > maxd) ? d : maxd;
+ }
+ dimensions = BitsUtil.zero(maxd);
+ for(int d : value) {
+ BitsUtil.setI(dimensions, d);
}
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractPreferenceVectorBasedCorrelationDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractPreferenceVectorBasedCorrelationDistanceFunction.java
deleted file mode 100644
index 20ee637e..00000000
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/AbstractPreferenceVectorBasedCorrelationDistanceFunction.java
+++ /dev/null
@@ -1,231 +0,0 @@
-package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- 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 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/>.
- */
-
-import java.util.BitSet;
-
-import de.lmu.ifi.dbs.elki.data.NumberVector;
-import de.lmu.ifi.dbs.elki.database.ids.DBID;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.relation.Relation;
-import de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractIndexBasedDistanceFunction;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.PreferenceVectorBasedCorrelationDistance;
-import de.lmu.ifi.dbs.elki.index.IndexFactory;
-import de.lmu.ifi.dbs.elki.index.preprocessed.preference.PreferenceVectorIndex;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.CommonConstraints;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.DoubleParameter;
-
-/**
- * Abstract super class for all preference vector based correlation distance
- * functions.
- *
- * @author Arthur Zimek
- * @param <V> the type of NumberVector to compute the distances in between
- * @param <P> the type of Preprocessor used
- */
-public abstract class AbstractPreferenceVectorBasedCorrelationDistanceFunction<V extends NumberVector<?>, P extends PreferenceVectorIndex<V>> extends AbstractIndexBasedDistanceFunction<V, P, PreferenceVectorBasedCorrelationDistance> {
- /**
- * Parameter to specify the maximum distance between two vectors with equal
- * preference vectors before considering them as parallel, must be a double
- * equal to or greater than 0.
- * <p>
- * Default value: {@code 0.001}
- * </p>
- * <p>
- * Key: {@code -pvbasedcorrelationdf.epsilon}
- * </p>
- */
- public static final OptionID EPSILON_ID = new OptionID("distancefunction.epsilon", "The maximum distance between two vectors with equal preference vectors before considering them as parallel.");
-
- /**
- * Holds the value of {@link #EPSILON_ID}.
- */
- private double epsilon;
-
- /**
- * Constructor.
- *
- * @param indexFactory Index factory
- * @param epsilon Epsilon value
- */
- public AbstractPreferenceVectorBasedCorrelationDistanceFunction(IndexFactory<V, P> indexFactory, double epsilon) {
- super(indexFactory);
- this.epsilon = epsilon;
- }
-
- @Override
- public PreferenceVectorBasedCorrelationDistance getDistanceFactory() {
- return PreferenceVectorBasedCorrelationDistance.FACTORY;
- }
-
- /**
- * Returns epsilon.
- *
- * @return epsilon
- */
- public double getEpsilon() {
- return epsilon;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (!this.getClass().equals(obj.getClass())) {
- return false;
- }
- AbstractPreferenceVectorBasedCorrelationDistanceFunction<?, ?> other = (AbstractPreferenceVectorBasedCorrelationDistanceFunction<?, ?>) obj;
- return (this.indexFactory.equals(other.indexFactory)) && this.epsilon == other.epsilon;
- }
-
- /**
- * Instance to compute the distances on an actual database.
- *
- * @author Erich Schubert
- */
- abstract public static class Instance<V extends NumberVector<?>, P extends PreferenceVectorIndex<V>> extends AbstractIndexBasedDistanceFunction.Instance<V, P, PreferenceVectorBasedCorrelationDistance, AbstractPreferenceVectorBasedCorrelationDistanceFunction<? super V, ?>> {
- /**
- * The epsilon value
- */
- final double epsilon;
-
- /**
- * Constructor.
- *
- * @param database Database
- * @param preprocessor Preprocessor
- * @param epsilon Epsilon
- * @param distanceFunction parent distance function
- */
- public Instance(Relation<V> database, P preprocessor, double epsilon, AbstractPreferenceVectorBasedCorrelationDistanceFunction<? super V, ?> distanceFunction) {
- super(database, preprocessor, distanceFunction);
- this.epsilon = epsilon;
- }
-
- @Override
- public PreferenceVectorBasedCorrelationDistance distance(DBIDRef id1, DBIDRef id2) {
- BitSet preferenceVector1 = index.getPreferenceVector(id1);
- BitSet preferenceVector2 = index.getPreferenceVector(id2);
- V v1 = relation.get(id1);
- V v2 = relation.get(id2);
- return correlationDistance(v1, v2, preferenceVector1, preferenceVector2);
- }
-
- /**
- * Computes the correlation distance between the two specified vectors
- * according to the specified preference vectors.
- *
- * @param v1 first vector
- * @param v2 second vector
- * @param pv1 the first preference vector
- * @param pv2 the second preference vector
- * @return the correlation distance between the two specified vectors
- */
- public abstract PreferenceVectorBasedCorrelationDistance correlationDistance(V v1, V v2, BitSet pv1, BitSet pv2);
-
- /**
- * Computes the weighted distance between the two specified vectors
- * according to the given preference vector.
- *
- * @param v1 the first vector
- * @param v2 the second vector
- * @param weightVector the preference vector
- * @return the weighted distance between the two specified vectors according
- * to the given preference vector
- */
- public double weightedDistance(V v1, V v2, BitSet weightVector) {
- if (v1.getDimensionality() != v2.getDimensionality()) {
- throw new IllegalArgumentException("Different dimensionality of FeatureVectors\n first argument: " + v1.toString() + "\n second argument: " + v2.toString());
- }
-
- double sqrDist = 0;
- for (int i = 0; i < v1.getDimensionality(); i++) {
- if (weightVector.get(i)) {
- double manhattanI = v1.doubleValue(i) - v2.doubleValue(i);
- sqrDist += manhattanI * manhattanI;
- }
- }
- return Math.sqrt(sqrDist);
- }
-
- /**
- * Computes the weighted distance between the two specified vectors
- * according to the given preference vector.
- *
- * @param id1 the id of the first vector
- * @param id2 the id of the second vector
- * @param weightVector the preference vector
- * @return the weighted distance between the two specified vectors according
- * to the given preference vector
- */
- public double weightedDistance(DBID id1, DBID id2, BitSet weightVector) {
- return weightedDistance(relation.get(id1), relation.get(id2), weightVector);
- }
-
- /**
- * Computes the weighted distance between the two specified data vectors
- * according to their preference vectors.
- *
- * @param id1 the id of the first vector
- * @param id2 the id of the second vector
- * @return the weighted distance between the two specified vectors according
- * to the preference vector of the first data vector
- */
- public double weightedPrefereneceVectorDistance(DBID id1, DBID id2) {
- final V v1 = relation.get(id1);
- final V v2 = relation.get(id2);
- double d1 = weightedDistance(v1, v2, index.getPreferenceVector(id1));
- double d2 = weightedDistance(v2, v1, index.getPreferenceVector(id2));
- return Math.max(d1, d2);
- }
- }
-
- /**
- * Parameterization class.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- public abstract static class Parameterizer<F extends IndexFactory<?, ?>> extends AbstractIndexBasedDistanceFunction.Parameterizer<F> {
- protected double epsilon = 0.0;
-
- @Override
- protected void makeOptions(Parameterization config) {
- super.makeOptions(config);
- configEpsilon(config);
- }
-
- protected void configEpsilon(Parameterization config) {
- final DoubleParameter epsilonP = new DoubleParameter(EPSILON_ID, 0.001);
- epsilonP.addConstraint(CommonConstraints.GREATER_EQUAL_ZERO_DOUBLE);
- if (config.grab(epsilonP)) {
- epsilon = epsilonP.doubleValue();
- }
- }
- }
-}
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DiSHDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DiSHDistanceFunction.java
deleted file mode 100644
index 7303797d..00000000
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DiSHDistanceFunction.java
+++ /dev/null
@@ -1,163 +0,0 @@
-package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- 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 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/>.
- */
-
-import java.util.BitSet;
-
-import de.lmu.ifi.dbs.elki.data.NumberVector;
-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.distancevalue.PreferenceVectorBasedCorrelationDistance;
-import de.lmu.ifi.dbs.elki.index.preprocessed.preference.DiSHPreferenceVectorIndex;
-import de.lmu.ifi.dbs.elki.logging.Logging;
-import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil;
-import de.lmu.ifi.dbs.elki.utilities.FormatUtil;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;
-
-/**
- * Distance function used in the DiSH algorithm.
- *
- * @author Elke Achtert
- *
- * @apiviz.has Instance
- */
-public class DiSHDistanceFunction extends AbstractPreferenceVectorBasedCorrelationDistanceFunction<NumberVector<?>, DiSHPreferenceVectorIndex<NumberVector<?>>> {
- /**
- * Logger for debug.
- */
- private static final Logging LOG = Logging.getLogger(DiSHDistanceFunction.class);
-
- /**
- * Constructor.
- *
- * @param indexFactory DiSH index factory
- * @param epsilon Epsilon value
- */
- public DiSHDistanceFunction(DiSHPreferenceVectorIndex.Factory<NumberVector<?>> indexFactory, double epsilon) {
- super(indexFactory, epsilon);
- }
-
- @Override
- public <T extends NumberVector<?>> Instance<T> instantiate(Relation<T> database) {
- // We can't really avoid these warnings, due to a limitation in Java
- // Generics (AFAICT)
- @SuppressWarnings("unchecked")
- DiSHPreferenceVectorIndex<T> indexinst = (DiSHPreferenceVectorIndex<T>) indexFactory.instantiate((Relation<NumberVector<?>>) database);
- return new Instance<>(database, indexinst, getEpsilon(), this);
- }
-
- /**
- * Get the minpts value.
- *
- * @return the minpts parameter
- */
- public int getMinpts() {
- // TODO: get rid of this cast?
- return ((DiSHPreferenceVectorIndex.Factory<NumberVector<?>>) indexFactory).getMinpts();
- }
-
- /**
- * The actual instance bound to a particular database.
- *
- * @author Erich Schubert
- */
- public static class Instance<V extends NumberVector<?>> extends AbstractPreferenceVectorBasedCorrelationDistanceFunction.Instance<V, DiSHPreferenceVectorIndex<V>> {
- /**
- * Constructor.
- *
- * @param database Database
- * @param index Preprocessed index
- * @param epsilon Epsilon
- * @param distanceFunction parent distance function
- */
- public Instance(Relation<V> database, DiSHPreferenceVectorIndex<V> index, double epsilon, DiSHDistanceFunction distanceFunction) {
- super(database, index, epsilon, distanceFunction);
- }
-
- /**
- * Computes the correlation distance between the two specified vectors
- * according to the specified preference vectors.
- *
- * @param v1 first vector
- * @param v2 second vector
- * @param pv1 the first preference vector
- * @param pv2 the second preference vector
- * @return the correlation distance between the two specified vectors
- */
- @Override
- public PreferenceVectorBasedCorrelationDistance correlationDistance(V v1, V v2, BitSet pv1, BitSet pv2) {
- BitSet commonPreferenceVector = (BitSet) pv1.clone();
- commonPreferenceVector.and(pv2);
- int dim = v1.getDimensionality();
-
- // number of zero values in commonPreferenceVector
- Integer subspaceDim = dim - commonPreferenceVector.cardinality();
-
- // special case: v1 and v2 are in parallel subspaces
- if(commonPreferenceVector.equals(pv1) || commonPreferenceVector.equals(pv2)) {
- double d = weightedDistance(v1, v2, commonPreferenceVector);
- if(d > 2 * epsilon) {
- subspaceDim++;
- if(LOG.isDebugging()) {
- //Representation<String> rep = database.getObjectLabelQuery();
- StringBuilder msg = new StringBuilder();
- msg.append("d ").append(d);
- //msg.append("\nv1 ").append(rep.get(v1.getID()));
- //msg.append("\nv2 ").append(rep.get(v2.getID()));
- msg.append("\nsubspaceDim ").append(subspaceDim);
- msg.append("\ncommon pv ").append(FormatUtil.format(dim, commonPreferenceVector));
- LOG.debugFine(msg.toString());
- }
- }
- }
-
- // flip commonPreferenceVector for distance computation in common subspace
- BitSet inverseCommonPreferenceVector = (BitSet) commonPreferenceVector.clone();
- inverseCommonPreferenceVector.flip(0, dim);
-
- return new PreferenceVectorBasedCorrelationDistance(RelationUtil.dimensionality(relation), subspaceDim, weightedDistance(v1, v2, inverseCommonPreferenceVector), commonPreferenceVector);
- }
- }
-
- /**
- * Parameterization class.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- public static class Parameterizer extends AbstractPreferenceVectorBasedCorrelationDistanceFunction.Parameterizer<DiSHPreferenceVectorIndex.Factory<NumberVector<?>>> {
- @Override
- protected void makeOptions(Parameterization config) {
- super.makeOptions(config);
- Class<DiSHPreferenceVectorIndex.Factory<NumberVector<?>>> cls = ClassGenericsUtil.uglyCastIntoSubclass(DiSHPreferenceVectorIndex.Factory.class);
- factory = config.tryInstantiate(cls);
- }
-
- @Override
- protected DiSHDistanceFunction makeInstance() {
- return new DiSHDistanceFunction(factory, epsilon);
- }
- }
-} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DimensionSelectingSubspaceDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DimensionSelectingSubspaceDistanceFunction.java
index f60e2fdc..dcab8e26 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DimensionSelectingSubspaceDistanceFunction.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DimensionSelectingSubspaceDistanceFunction.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -22,10 +22,7 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
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.BitSet;
-
import de.lmu.ifi.dbs.elki.distance.distancefunction.DistanceFunction;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
/**
* Interface for dimension selecting subspace distance functions.
@@ -33,20 +30,19 @@ import de.lmu.ifi.dbs.elki.distance.distancevalue.Distance;
* @author Erich Schubert
*
* @param <O> Object type
- * @param <D> Distance value
*/
-public interface DimensionSelectingSubspaceDistanceFunction<O, D extends Distance<D>> extends DistanceFunction<O, D> {
+public interface DimensionSelectingSubspaceDistanceFunction<O> extends DistanceFunction<O> {
/**
* Returns a bit set representing the selected dimensions.
*
* @return a bit set representing the selected dimensions
*/
- public BitSet getSelectedDimensions();
+ public long[] getSelectedDimensions();
/**
* Sets the selected dimensions according to the set bits in the given BitSet.
*
- * @param dimensions a BitSet designating the new selected dimensions
+ * @param dimensions a bit set designating the new selected dimensions
*/
- public void setSelectedDimensions(BitSet dimensions);
+ public void setSelectedDimensions(long[] dimensions);
}
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/HiSCDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/HiSCDistanceFunction.java
deleted file mode 100644
index a339c389..00000000
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/HiSCDistanceFunction.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- 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 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/>.
- */
-
-import java.util.BitSet;
-
-import de.lmu.ifi.dbs.elki.data.NumberVector;
-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.distancevalue.PreferenceVectorBasedCorrelationDistance;
-import de.lmu.ifi.dbs.elki.index.preprocessed.preference.HiSCPreferenceVectorIndex;
-import de.lmu.ifi.dbs.elki.logging.Logging;
-import de.lmu.ifi.dbs.elki.utilities.ClassGenericsUtil;
-import de.lmu.ifi.dbs.elki.utilities.FormatUtil;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;
-
-/**
- * Distance function used in the HiSC algorithm.
- *
- * @author Elke Achtert
- *
- * @apiviz.has Instance
- *
- * @param <V> the type of NumberVector to compute the distances in between
- */
-public class HiSCDistanceFunction<V extends NumberVector<?>> extends AbstractPreferenceVectorBasedCorrelationDistanceFunction<V, HiSCPreferenceVectorIndex<V>> {
- /**
- * Logger for debug.
- */
- private static final Logging LOG = Logging.getLogger(HiSCDistanceFunction.class);
-
- /**
- * Constructor.
- *
- * @param indexFactory HiSC index factory
- * @param epsilon Epsilon value
- */
- public HiSCDistanceFunction(HiSCPreferenceVectorIndex.Factory<V> indexFactory, double epsilon) {
- super(indexFactory, epsilon);
- }
-
- @Override
- public <T extends V> Instance<T> instantiate(Relation<T> database) {
- // We can't really avoid these warnings, due to a limitation in Java
- // Generics (AFAICT)
- @SuppressWarnings("unchecked")
- HiSCPreferenceVectorIndex<T> indexinst = (HiSCPreferenceVectorIndex<T>) indexFactory.instantiate((Relation<V>) database);
- return new Instance<>(database, indexinst, getEpsilon(), this);
- }
-
- /**
- * The actual instance bound to a particular database.
- *
- * @author Erich Schubert
- *
- * @param <V> the type of NumberVector to compute the distances in between
- */
- public static class Instance<V extends NumberVector<?>> extends AbstractPreferenceVectorBasedCorrelationDistanceFunction.Instance<V, HiSCPreferenceVectorIndex<V>> {
- /**
- * Constructor.
- *
- * @param database Database
- * @param index Preprocessed index
- * @param epsilon Epsilon
- * @param distanceFunction parent distance function
- */
- public Instance(Relation<V> database, HiSCPreferenceVectorIndex<V> index, double epsilon, HiSCDistanceFunction<? super V> distanceFunction) {
- super(database, index, epsilon, distanceFunction);
- }
-
- /**
- * Computes the correlation distance between the two specified vectors
- * according to the specified preference vectors.
- *
- * @param v1 first vector
- * @param v2 second vector
- * @param pv1 the first preference vector
- * @param pv2 the second preference vector
- * @return the correlation distance between the two specified vectors
- */
- @Override
- public PreferenceVectorBasedCorrelationDistance correlationDistance(V v1, V v2, BitSet pv1, BitSet pv2) {
- BitSet commonPreferenceVector = (BitSet) pv1.clone();
- commonPreferenceVector.and(pv2);
- int dim = v1.getDimensionality();
-
- // number of zero values in commonPreferenceVector
- Integer subspaceDim = dim - commonPreferenceVector.cardinality();
-
- // special case: v1 and v2 are in parallel subspaces
- double dist1 = weightedDistance(v1, v2, pv1);
- double dist2 = weightedDistance(v1, v2, pv2);
-
- if(Math.max(dist1, dist2) > epsilon) {
- subspaceDim++;
- if(LOG.isDebugging()) {
- //Representation<String> rep = rep.getObjectLabelQuery();
- StringBuilder msg = new StringBuilder();
- msg.append("\ndist1 ").append(dist1);
- msg.append("\ndist2 ").append(dist2);
- // msg.append("\nv1 ").append(rep.get(v1.getID()));
- // msg.append("\nv2 ").append(rep.get(v2.getID()));
- msg.append("\nsubspaceDim ").append(subspaceDim);
- msg.append("\ncommon pv ").append(FormatUtil.format(dim, commonPreferenceVector));
- LOG.debugFine(msg.toString());
- }
- }
-
- // flip commonPreferenceVector for distance computation in common subspace
- BitSet inverseCommonPreferenceVector = (BitSet) commonPreferenceVector.clone();
- inverseCommonPreferenceVector.flip(0, dim);
-
- return new PreferenceVectorBasedCorrelationDistance(RelationUtil.dimensionality(relation), subspaceDim, weightedDistance(v1, v2, inverseCommonPreferenceVector), commonPreferenceVector);
- }
- }
-
- /**
- * Parameterization class.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- public static class Parameterizer<V extends NumberVector<?>> extends AbstractPreferenceVectorBasedCorrelationDistanceFunction.Parameterizer<HiSCPreferenceVectorIndex.Factory<V>> {
- @Override
- protected void makeOptions(Parameterization config) {
- super.makeOptions(config);
- Class<HiSCPreferenceVectorIndex.Factory<V>> cls = ClassGenericsUtil.uglyCastIntoSubclass(HiSCPreferenceVectorIndex.Factory.class);
- factory = config.tryInstantiate(cls);
- }
-
- @Override
- protected HiSCDistanceFunction<V> makeInstance() {
- return new HiSCDistanceFunction<>(factory, epsilon);
- }
- }
-} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/LocalSubspaceDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/LocalSubspaceDistanceFunction.java
deleted file mode 100644
index efcf6a3c..00000000
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/LocalSubspaceDistanceFunction.java
+++ /dev/null
@@ -1,152 +0,0 @@
-package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
-
-/*
- This file is part of ELKI:
- Environment for Developing KDD-Applications Supported by Index-Structures
-
- Copyright (C) 2013
- 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 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/>.
- */
-
-import de.lmu.ifi.dbs.elki.data.NumberVector;
-import de.lmu.ifi.dbs.elki.database.ids.DBIDRef;
-import de.lmu.ifi.dbs.elki.database.relation.Relation;
-import de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractIndexBasedDistanceFunction;
-import de.lmu.ifi.dbs.elki.distance.distancefunction.FilteredLocalPCABasedDistanceFunction;
-import de.lmu.ifi.dbs.elki.distance.distancefunction.WeightedDistanceFunction;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.SubspaceDistance;
-import de.lmu.ifi.dbs.elki.index.IndexFactory;
-import de.lmu.ifi.dbs.elki.index.preprocessed.LocalProjectionIndex;
-import de.lmu.ifi.dbs.elki.index.preprocessed.localpca.FilteredLocalPCAIndex;
-import de.lmu.ifi.dbs.elki.index.preprocessed.localpca.KNNQueryFilteredPCAIndex;
-import de.lmu.ifi.dbs.elki.math.linearalgebra.Matrix;
-import de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAFilteredResult;
-import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;
-
-/**
- * Provides a distance function to determine a kind of correlation distance
- * between two points, which is a pair consisting of the distance between the
- * two subspaces spanned by the strong eigenvectors of the two points and the
- * affine distance between the two subspaces.
- *
- * @author Elke Achtert
- *
- * @apiviz.has Instance
- */
-public class LocalSubspaceDistanceFunction extends AbstractIndexBasedDistanceFunction<NumberVector<?>, FilteredLocalPCAIndex<NumberVector<?>>, SubspaceDistance> implements FilteredLocalPCABasedDistanceFunction<NumberVector<?>, FilteredLocalPCAIndex<NumberVector<?>>, SubspaceDistance> {
- /**
- * Constructor
- *
- * @param indexFactory Index factory
- */
- public LocalSubspaceDistanceFunction(IndexFactory<NumberVector<?>, FilteredLocalPCAIndex<NumberVector<?>>> indexFactory) {
- super(indexFactory);
- }
-
- @Override
- public SubspaceDistance getDistanceFactory() {
- return SubspaceDistance.FACTORY;
- }
-
- @Override
- public <V extends NumberVector<?>> Instance<V> instantiate(Relation<V> database) {
- // We can't really avoid these warnings, due to a limitation in Java Generics (AFAICT)
- @SuppressWarnings("unchecked")
- FilteredLocalPCAIndex<V> indexinst = (FilteredLocalPCAIndex<V>) indexFactory.instantiate((Relation<NumberVector<?>>)database);
- return new Instance<>(database, indexinst, this);
- }
-
- /**
- * The actual instance bound to a particular database.
- *
- * @author Erich Schubert
- */
- public static class Instance<V extends NumberVector<?>> extends AbstractIndexBasedDistanceFunction.Instance<V, FilteredLocalPCAIndex<V>, SubspaceDistance, LocalSubspaceDistanceFunction> implements FilteredLocalPCABasedDistanceFunction.Instance<V, FilteredLocalPCAIndex<V>, SubspaceDistance> {
- /**
- * @param database Database
- * @param index Index
- */
- public Instance(Relation<V> database, FilteredLocalPCAIndex<V> index, LocalSubspaceDistanceFunction distanceFunction) {
- super(database, index, distanceFunction);
- }
-
- /**
- * Note, that the pca of o1 must have equal ore more strong eigenvectors
- * than the pca of o2.
- *
- */
- @Override
- public SubspaceDistance distance(DBIDRef id1, DBIDRef id2) {
- PCAFilteredResult pca1 = index.getLocalProjection(id1);
- PCAFilteredResult pca2 = index.getLocalProjection(id2);
- V o1 = relation.get(id1);
- V o2 = relation.get(id2);
- return distance(o1, o2, pca1, pca2);
- }
-
- /**
- * Computes the distance between two given DatabaseObjects according to this
- * distance function. Note, that the first pca must have an equal number of
- * strong eigenvectors than the second pca.
- *
- * @param o1 first DatabaseObject
- * @param o2 second DatabaseObject
- * @param pca1 first PCA
- * @param pca2 second PCA
- * @return the distance between two given DatabaseObjects according to this
- * distance function
- */
- public SubspaceDistance distance(V o1, V o2, PCAFilteredResult pca1, PCAFilteredResult pca2) {
- if(pca1.getCorrelationDimension() != pca2.getCorrelationDimension()) {
- throw new IllegalStateException("pca1.getCorrelationDimension() != pca2.getCorrelationDimension()");
- }
-
- Matrix strong_ev1 = pca1.getStrongEigenvectors();
- Matrix weak_ev2 = pca2.getWeakEigenvectors();
- Matrix m1 = weak_ev2.getColumnDimensionality() == 0 ? strong_ev1.transpose() : strong_ev1.transposeTimes(weak_ev2);
- double d1 = m1.norm2();
-
- WeightedDistanceFunction df1 = new WeightedDistanceFunction(pca1.similarityMatrix());
- WeightedDistanceFunction df2 = new WeightedDistanceFunction(pca2.similarityMatrix());
-
- double affineDistance = Math.max(df1.distance(o1, o2).doubleValue(), df2.distance(o1, o2).doubleValue());
-
- return new SubspaceDistance(d1, affineDistance);
- }
- }
-
- /**
- * Parameterization class.
- *
- * @author Erich Schubert
- *
- * @apiviz.exclude
- */
- public static class Parameterizer extends AbstractIndexBasedDistanceFunction.Parameterizer<LocalProjectionIndex.Factory<NumberVector<?>, FilteredLocalPCAIndex<NumberVector<?>>>> {
- @Override
- protected void makeOptions(Parameterization config) {
- super.makeOptions(config);
- configIndexFactory(config, LocalProjectionIndex.Factory.class, KNNQueryFilteredPCAIndex.Factory.class);
- }
-
- @Override
- protected LocalSubspaceDistanceFunction makeInstance() {
- return new LocalSubspaceDistanceFunction(factory);
- }
- }
-} \ No newline at end of file
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DimensionSelectingDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/OnedimensionalDistanceFunction.java
index 5fbe1c73..581e9ebc 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/DimensionSelectingDistanceFunction.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/OnedimensionalDistanceFunction.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,14 +23,12 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import java.util.BitSet;
-
import de.lmu.ifi.dbs.elki.data.NumberVector;
import de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable;
import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation;
import de.lmu.ifi.dbs.elki.data.type.VectorTypeInformation;
-import de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractSpatialDoubleDistanceNorm;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.distance.distancefunction.AbstractSpatialNorm;
+import de.lmu.ifi.dbs.elki.utilities.BitsUtil;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizer;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.OptionID;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.CommonConstraints;
@@ -38,17 +36,12 @@ import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameteriz
import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.IntParameter;
/**
- * Provides a distance function that computes the distance between feature
- * vectors as the absolute difference of their values in a specified dimension.
+ * Distance function that computes the distance between feature vectors as the
+ * absolute difference of their values in a specified dimension only.
*
* @author Elke Achtert
*/
-public class DimensionSelectingDistanceFunction extends AbstractSpatialDoubleDistanceNorm implements DimensionSelectingSubspaceDistanceFunction<NumberVector<?>, DoubleDistance> {
- /**
- * Parameter for dimensionality.
- */
- public static final OptionID DIM_ID = new OptionID("dim", "an integer between 1 and the dimensionality of the " + "feature space 1 specifying the dimension to be considered " + "for distance computation.");
-
+public class OnedimensionalDistanceFunction extends AbstractSpatialNorm implements DimensionSelectingSubspaceDistanceFunction<NumberVector> {
/**
* The dimension to be considered for distance computation.
*/
@@ -59,7 +52,7 @@ public class DimensionSelectingDistanceFunction extends AbstractSpatialDoubleDis
*
* @param dim Dimension
*/
- public DimensionSelectingDistanceFunction(int dim) {
+ public OnedimensionalDistanceFunction(int dim) {
super();
this.dim = dim;
}
@@ -74,41 +67,34 @@ public class DimensionSelectingDistanceFunction extends AbstractSpatialDoubleDis
* distance function
*/
@Override
- public double doubleDistance(NumberVector<?> v1, NumberVector<?> v2) {
+ public double distance(NumberVector v1, NumberVector v2) {
if(dim >= v1.getDimensionality() || dim >= v2.getDimensionality() || dim < 0) {
throw new IllegalArgumentException("Specified dimension to be considered " + "is larger that dimensionality of FeatureVectors:" + "\n first argument: " + v1.toString() + "\n second argument: " + v2.toString() + "\n dimension: " + dim);
}
- double manhattan = v1.doubleValue(dim) - v2.doubleValue(dim);
- return Math.abs(manhattan);
+ double delta = v1.doubleValue(dim) - v2.doubleValue(dim);
+ return delta >= 0 ? delta : -delta;
}
@Override
- public double doubleMinDist(SpatialComparable mbr1, SpatialComparable mbr2) {
+ public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
if(dim >= mbr1.getDimensionality() || dim >= mbr2.getDimensionality() || dim < 0) {
throw new IllegalArgumentException("Specified dimension to be considered " + "is larger that dimensionality of FeatureVectors:" + "\n first argument: " + mbr1.toString() + "\n second argument: " + mbr2.toString() + "\n dimension: " + dim);
}
- double m1, m2;
- if(mbr1.getMax(dim) < mbr2.getMin(dim)) {
- m1 = mbr1.getMax(dim);
- m2 = mbr2.getMin(dim);
- }
- else if(mbr1.getMin(dim) > mbr2.getMax(dim)) {
- m1 = mbr1.getMin(dim);
- m2 = mbr2.getMax(dim);
+ final double max1 = mbr1.getMax(dim), min2 = mbr2.getMin(dim);
+ if(max1 < min2) {
+ return min2 - max1;
}
- else { // The mbrs intersect!
- m1 = 0;
- m2 = 0;
+ final double min1 = mbr1.getMin(dim), max2 = mbr2.getMax(dim);
+ if(min1 > max2) {
+ return min1 - max2;
}
- double manhattan = m1 - m2;
-
- return Math.abs(manhattan);
+ return 0;
}
@Override
- public double doubleNorm(NumberVector<?> obj) {
+ public double norm(NumberVector obj) {
return Math.abs(obj.doubleValue(dim));
}
@@ -123,31 +109,27 @@ public class DimensionSelectingDistanceFunction extends AbstractSpatialDoubleDis
@Override
@Deprecated
- public BitSet getSelectedDimensions() {
- BitSet bs = new BitSet(dim + 1);
- bs.set(dim);
+ public long[] getSelectedDimensions() {
+ long[] bs = BitsUtil.zero(dim);
+ BitsUtil.setI(bs, dim);
return bs;
}
@Override
- public void setSelectedDimensions(BitSet dimensions) {
- dim = dimensions.nextSetBit(0);
+ @Deprecated
+ public void setSelectedDimensions(long[] dimensions) {
+ dim = BitsUtil.nextSetBit(dimensions, 0);
if(dim == -1) {
throw new IllegalStateException("No dimension was set.");
}
- if(dimensions.nextSetBit(dim + 1) > 0) {
+ if(BitsUtil.nextSetBit(dimensions, dim + 1) > 0) {
throw new IllegalStateException("More than one dimension was set.");
}
}
@Override
- public VectorTypeInformation<? super NumberVector<?>> getInputTypeRestriction() {
- return new VectorFieldTypeInformation<>(NumberVector.class, dim, Integer.MAX_VALUE);
- }
-
- @Override
- public DoubleDistance getDistanceFactory() {
- return DoubleDistance.FACTORY;
+ public VectorTypeInformation<? super NumberVector> getInputTypeRestriction() {
+ return VectorFieldTypeInformation.typeRequest(NumberVector.class, dim, Integer.MAX_VALUE);
}
@Override
@@ -158,7 +140,7 @@ public class DimensionSelectingDistanceFunction extends AbstractSpatialDoubleDis
if(!this.getClass().equals(obj.getClass())) {
return false;
}
- return this.dim == ((DimensionSelectingDistanceFunction) obj).dim;
+ return this.dim == ((OnedimensionalDistanceFunction) obj).dim;
}
/**
@@ -169,21 +151,29 @@ public class DimensionSelectingDistanceFunction extends AbstractSpatialDoubleDis
* @apiviz.exclude
*/
public static class Parameterizer extends AbstractParameterizer {
+ /**
+ * Parameter for dimensionality.
+ */
+ public static final OptionID DIM_ID = new OptionID("dim", "an integer between 1 and the dimensionality of the " + "feature space 1 specifying the dimension to be considered " + "for distance computation.");
+
+ /**
+ * Selected dimension.
+ */
protected int dim = 0;
@Override
protected void makeOptions(Parameterization config) {
super.makeOptions(config);
- final IntParameter dimP = new IntParameter(DIM_ID);
- dimP.addConstraint(CommonConstraints.GREATER_EQUAL_ZERO_INT);
+ final IntParameter dimP = new IntParameter(DIM_ID)//
+ .addConstraint(CommonConstraints.GREATER_EQUAL_ZERO_INT);
if(config.grab(dimP)) {
dim = dimP.getValue();
}
}
@Override
- protected DimensionSelectingDistanceFunction makeInstance() {
- return new DimensionSelectingDistanceFunction(dim);
+ protected OnedimensionalDistanceFunction makeInstance() {
+ return new OnedimensionalDistanceFunction(dim);
}
}
}
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceEuclideanDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceEuclideanDistanceFunction.java
index d24fc62e..a48de183 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceEuclideanDistanceFunction.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceEuclideanDistanceFunction.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,14 +23,13 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import java.util.BitSet;
-
import de.lmu.ifi.dbs.elki.data.NumberVector;
import de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable;
+import de.lmu.ifi.dbs.elki.utilities.BitsUtil;
/**
- * Provides a distance function that computes the Euclidean distance between
- * feature vectors only in specified dimensions.
+ * Euclidean distance function between {@link NumberVector}s only in specified
+ * dimensions.
*
* @author Elke Achtert
*/
@@ -40,13 +39,12 @@ public class SubspaceEuclideanDistanceFunction extends SubspaceLPNormDistanceFun
*
* @param dimensions Selected dimensions
*/
- public SubspaceEuclideanDistanceFunction(BitSet dimensions) {
+ public SubspaceEuclideanDistanceFunction(long[] dimensions) {
super(2.0, dimensions);
}
/**
- * Provides the Euclidean distance between two given feature vectors in the
- * selected dimensions.
+ * Constructor.
*
* @param v1 first feature vector
* @param v2 second feature vector
@@ -54,13 +52,13 @@ public class SubspaceEuclideanDistanceFunction extends SubspaceLPNormDistanceFun
* selected dimensions
*/
@Override
- public double doubleDistance(NumberVector<?> v1, NumberVector<?> v2) {
+ public double distance(NumberVector v1, NumberVector v2) {
if(v1.getDimensionality() != v2.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of FeatureVectors\n " + "first argument: " + v1 + "\n " + "second argument: " + v2);
}
double sqrDist = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double delta = v1.doubleValue(d) - v2.doubleValue(d);
sqrDist += delta * delta;
}
@@ -68,13 +66,13 @@ public class SubspaceEuclideanDistanceFunction extends SubspaceLPNormDistanceFun
}
@Override
- protected double doubleMinDistObject(SpatialComparable mbr, NumberVector<?> v) {
+ protected double minDistObject(SpatialComparable mbr, NumberVector v) {
if(mbr.getDimensionality() != v.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of objects\n " + "first argument: " + mbr.toString() + "\n " + "second argument: " + v.toString());
}
double sqrDist = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double delta;
final double value = v.doubleValue(d);
final double omin = mbr.getMin(d);
@@ -96,12 +94,12 @@ public class SubspaceEuclideanDistanceFunction extends SubspaceLPNormDistanceFun
}
@Override
- public double doubleMinDist(SpatialComparable mbr1, SpatialComparable mbr2) {
+ public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
if(mbr1.getDimensionality() != mbr2.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of objects\n " + "first argument: " + mbr1.toString() + "\n " + "second argument: " + mbr2.toString());
}
double sqrDist = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double delta;
final double max1 = mbr1.getMax(d);
final double min2 = mbr2.getMin(d);
@@ -124,9 +122,9 @@ public class SubspaceEuclideanDistanceFunction extends SubspaceLPNormDistanceFun
}
@Override
- public double doubleNorm(NumberVector<?> obj) {
+ public double norm(NumberVector obj) {
double sqrDist = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double delta = obj.doubleValue(d);
sqrDist += delta * delta;
}
@@ -140,7 +138,7 @@ public class SubspaceEuclideanDistanceFunction extends SubspaceLPNormDistanceFun
*
* @apiviz.exclude
*/
- public static class Parameterizer extends AbstractDimensionsSelectingDoubleDistanceFunction.Parameterizer {
+ public static class Parameterizer extends AbstractDimensionsSelectingDistanceFunction.Parameterizer {
@Override
protected SubspaceEuclideanDistanceFunction makeInstance() {
return new SubspaceEuclideanDistanceFunction(dimensions);
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceLPNormDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceLPNormDistanceFunction.java
index 6c9579ad..34ea7eac 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceLPNormDistanceFunction.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceLPNormDistanceFunction.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,30 +23,28 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import java.util.BitSet;
-
import de.lmu.ifi.dbs.elki.data.NumberVector;
import de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable;
import de.lmu.ifi.dbs.elki.data.type.TypeUtil;
import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation;
import de.lmu.ifi.dbs.elki.database.query.distance.SpatialPrimitiveDistanceQuery;
import de.lmu.ifi.dbs.elki.database.relation.Relation;
-import de.lmu.ifi.dbs.elki.distance.distancefunction.DoubleNorm;
+import de.lmu.ifi.dbs.elki.distance.distancefunction.Norm;
import de.lmu.ifi.dbs.elki.distance.distancefunction.NumberVectorDistanceFunction;
-import de.lmu.ifi.dbs.elki.distance.distancefunction.SpatialPrimitiveDoubleDistanceFunction;
+import de.lmu.ifi.dbs.elki.distance.distancefunction.SpatialPrimitiveDistanceFunction;
import de.lmu.ifi.dbs.elki.distance.distancefunction.minkowski.LPNormDistanceFunction;
-import de.lmu.ifi.dbs.elki.distance.distancevalue.DoubleDistance;
+import de.lmu.ifi.dbs.elki.utilities.BitsUtil;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.constraints.CommonConstraints;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.Parameterization;
import de.lmu.ifi.dbs.elki.utilities.optionhandling.parameters.DoubleParameter;
/**
- * Provides a distance function that computes the Euclidean distance between
- * feature vectors only in specified dimensions.
+ * LP-Norm distance function between {@link NumberVector}s only in specified
+ * dimensions.
*
* @author Elke Achtert
*/
-public class SubspaceLPNormDistanceFunction extends AbstractDimensionsSelectingDoubleDistanceFunction<NumberVector<?>> implements SpatialPrimitiveDoubleDistanceFunction<NumberVector<?>>, DoubleNorm<NumberVector<?>>, NumberVectorDistanceFunction<DoubleDistance> {
+public class SubspaceLPNormDistanceFunction extends AbstractDimensionsSelectingDistanceFunction<NumberVector> implements SpatialPrimitiveDistanceFunction<NumberVector>, Norm<NumberVector>, NumberVectorDistanceFunction<NumberVector> {
/**
* Value of p
*/
@@ -58,7 +56,7 @@ public class SubspaceLPNormDistanceFunction extends AbstractDimensionsSelectingD
* @param dimensions Selected dimensions
* @param p p value
*/
- public SubspaceLPNormDistanceFunction(double p, BitSet dimensions) {
+ public SubspaceLPNormDistanceFunction(double p, long[] dimensions) {
super(dimensions);
this.p = p;
}
@@ -72,36 +70,27 @@ public class SubspaceLPNormDistanceFunction extends AbstractDimensionsSelectingD
return p;
}
- /**
- * Provides the Euclidean distance between two given feature vectors in the
- * selected dimensions.
- *
- * @param v1 first feature vector
- * @param v2 second feature vector
- * @return the Euclidean distance between two given feature vectors in the
- * selected dimensions
- */
@Override
- public double doubleDistance(NumberVector<?> v1, NumberVector<?> v2) {
+ public double distance(NumberVector v1, NumberVector v2) {
if(v1.getDimensionality() != v2.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of FeatureVectors\n " + "first argument: " + v1 + "\n " + "second argument: " + v2);
}
double sqrDist = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
double delta = Math.abs(v1.doubleValue(d) - v2.doubleValue(d));
sqrDist += Math.pow(delta, p);
}
return Math.pow(sqrDist, 1. / p);
}
- protected double doubleMinDistObject(SpatialComparable mbr, NumberVector<?> v) {
+ protected double minDistObject(SpatialComparable mbr, NumberVector v) {
if(mbr.getDimensionality() != v.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of objects\n " + "first argument: " + mbr.toString() + "\n " + "second argument: " + v.toString());
}
double sqrDist = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double delta;
final double value = v.doubleValue(d);
final double omin = mbr.getMin(d);
@@ -123,12 +112,12 @@ public class SubspaceLPNormDistanceFunction extends AbstractDimensionsSelectingD
}
@Override
- public double doubleMinDist(SpatialComparable mbr1, SpatialComparable mbr2) {
+ public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
if(mbr1.getDimensionality() != mbr2.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of objects\n " + "first argument: " + mbr1.toString() + "\n " + "second argument: " + mbr2.toString());
}
double sqrDist = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double delta;
final double max1 = mbr1.getMax(d);
final double min2 = mbr2.getMin(d);
@@ -151,19 +140,9 @@ public class SubspaceLPNormDistanceFunction extends AbstractDimensionsSelectingD
}
@Override
- public DoubleDistance minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
- return new DoubleDistance(doubleMinDist(mbr1, mbr2));
- }
-
- @Override
- public DoubleDistance norm(NumberVector<?> obj) {
- return new DoubleDistance(doubleNorm(obj));
- }
-
- @Override
- public double doubleNorm(NumberVector<?> obj) {
+ public double norm(NumberVector obj) {
double sqrDist = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
double delta = Math.abs(obj.doubleValue(d));
sqrDist += Math.pow(delta, p);
}
@@ -171,12 +150,12 @@ public class SubspaceLPNormDistanceFunction extends AbstractDimensionsSelectingD
}
@Override
- public <T extends NumberVector<?>> SpatialPrimitiveDistanceQuery<T, DoubleDistance> instantiate(Relation<T> database) {
+ public <T extends NumberVector> SpatialPrimitiveDistanceQuery<T> instantiate(Relation<T> database) {
return new SpatialPrimitiveDistanceQuery<>(database, this);
}
@Override
- public VectorFieldTypeInformation<? super NumberVector<?>> getInputTypeRestriction() {
+ public VectorFieldTypeInformation<? super NumberVector> getInputTypeRestriction() {
return TypeUtil.NUMBER_VECTOR_FIELD;
}
@@ -192,7 +171,7 @@ public class SubspaceLPNormDistanceFunction extends AbstractDimensionsSelectingD
*
* @apiviz.exclude
*/
- public static class Parameterizer extends AbstractDimensionsSelectingDoubleDistanceFunction.Parameterizer {
+ public static class Parameterizer extends AbstractDimensionsSelectingDistanceFunction.Parameterizer {
/**
* Value of p.
*/
@@ -200,7 +179,7 @@ public class SubspaceLPNormDistanceFunction extends AbstractDimensionsSelectingD
@Override
protected void makeOptions(Parameterization config) {
- final DoubleParameter paramP = new DoubleParameter(LPNormDistanceFunction.P_ID);
+ final DoubleParameter paramP = new DoubleParameter(LPNormDistanceFunction.Parameterizer.P_ID);
paramP.addConstraint(CommonConstraints.GREATER_THAN_ZERO_DOUBLE);
if(config.grab(paramP)) {
p = paramP.getValue();
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceManhattanDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceManhattanDistanceFunction.java
index ccca76da..ab54b88f 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceManhattanDistanceFunction.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceManhattanDistanceFunction.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,14 +23,13 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import java.util.BitSet;
-
import de.lmu.ifi.dbs.elki.data.NumberVector;
import de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable;
+import de.lmu.ifi.dbs.elki.utilities.BitsUtil;
/**
- * Provides a distance function that computes the Euclidean distance between
- * feature vectors only in specified dimensions.
+ * Manhattan distance function between {@link NumberVector}s only in specified
+ * dimensions.
*
* @author Elke Achtert
*/
@@ -40,40 +39,31 @@ public class SubspaceManhattanDistanceFunction extends SubspaceLPNormDistanceFun
*
* @param dimensions Selected dimensions
*/
- public SubspaceManhattanDistanceFunction(BitSet dimensions) {
+ public SubspaceManhattanDistanceFunction(long[] dimensions) {
super(1.0, dimensions);
}
- /**
- * Provides the Euclidean distance between two given feature vectors in the
- * selected dimensions.
- *
- * @param v1 first feature vector
- * @param v2 second feature vector
- * @return the Euclidean distance between two given feature vectors in the
- * selected dimensions
- */
@Override
- public double doubleDistance(NumberVector<?> v1, NumberVector<?> v2) {
+ public double distance(NumberVector v1, NumberVector v2) {
if(v1.getDimensionality() != v2.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of FeatureVectors\n " + "first argument: " + v1 + "\n " + "second argument: " + v2);
}
double sum = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
sum += Math.abs(v1.doubleValue(d) - v2.doubleValue(d));
}
return sum;
}
@Override
- protected double doubleMinDistObject(SpatialComparable mbr, NumberVector<?> v) {
+ protected double minDistObject(SpatialComparable mbr, NumberVector v) {
if(mbr.getDimensionality() != v.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of objects\n " + "first argument: " + mbr.toString() + "\n " + "second argument: " + v.toString());
}
double sum = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double value = v.doubleValue(d);
final double omin = mbr.getMin(d);
if(value < omin) {
@@ -93,12 +83,12 @@ public class SubspaceManhattanDistanceFunction extends SubspaceLPNormDistanceFun
}
@Override
- public double doubleMinDist(SpatialComparable mbr1, SpatialComparable mbr2) {
+ public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
if(mbr1.getDimensionality() != mbr2.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of objects\n " + "first argument: " + mbr1.toString() + "\n " + "second argument: " + mbr2.toString());
}
double sum = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double max1 = mbr1.getMax(d);
final double min2 = mbr2.getMin(d);
if(max1 < min2) {
@@ -119,9 +109,9 @@ public class SubspaceManhattanDistanceFunction extends SubspaceLPNormDistanceFun
}
@Override
- public double doubleNorm(NumberVector<?> obj) {
+ public double norm(NumberVector obj) {
double sum = 0;
- for(int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
sum += Math.abs(obj.doubleValue(d));
}
return sum;
@@ -134,7 +124,7 @@ public class SubspaceManhattanDistanceFunction extends SubspaceLPNormDistanceFun
*
* @apiviz.exclude
*/
- public static class Parameterizer extends AbstractDimensionsSelectingDoubleDistanceFunction.Parameterizer {
+ public static class Parameterizer extends AbstractDimensionsSelectingDistanceFunction.Parameterizer {
@Override
protected SubspaceManhattanDistanceFunction makeInstance() {
return new SubspaceManhattanDistanceFunction(dimensions);
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceMaximumDistanceFunction.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceMaximumDistanceFunction.java
index 60791159..d1f0485c 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceMaximumDistanceFunction.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/SubspaceMaximumDistanceFunction.java
@@ -4,7 +4,7 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
- Copyright (C) 2013
+ Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team
@@ -23,14 +23,13 @@ package de.lmu.ifi.dbs.elki.distance.distancefunction.subspace;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import java.util.BitSet;
-
import de.lmu.ifi.dbs.elki.data.NumberVector;
import de.lmu.ifi.dbs.elki.data.spatial.SpatialComparable;
+import de.lmu.ifi.dbs.elki.utilities.BitsUtil;
/**
- * Provides a distance function that computes the Euclidean distance between
- * feature vectors only in specified dimensions.
+ * Maximum distance function between {@link NumberVector}s only in specified
+ * dimensions.
*
* @author Elke Achtert
*/
@@ -40,29 +39,20 @@ public class SubspaceMaximumDistanceFunction extends SubspaceLPNormDistanceFunct
*
* @param dimensions Selected dimensions
*/
- public SubspaceMaximumDistanceFunction(BitSet dimensions) {
+ public SubspaceMaximumDistanceFunction(long[] dimensions) {
super(1.0, dimensions);
}
- /**
- * Provides the Euclidean distance between two given feature vectors in the
- * selected dimensions.
- *
- * @param v1 first feature vector
- * @param v2 second feature vector
- * @return the Euclidean distance between two given feature vectors in the
- * selected dimensions
- */
@Override
- public double doubleDistance(NumberVector<?> v1, NumberVector<?> v2) {
- if (v1.getDimensionality() != v2.getDimensionality()) {
+ public double distance(NumberVector v1, NumberVector v2) {
+ if(v1.getDimensionality() != v2.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of FeatureVectors\n " + "first argument: " + v1 + "\n " + "second argument: " + v2);
}
double agg = 0.;
- for (int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
double v = Math.abs(v1.doubleValue(d) - v2.doubleValue(d));
- if (v > agg) {
+ if(v > agg) {
agg = v;
}
}
@@ -70,24 +60,25 @@ public class SubspaceMaximumDistanceFunction extends SubspaceLPNormDistanceFunct
}
@Override
- protected double doubleMinDistObject(SpatialComparable mbr, NumberVector<?> v) {
- if (mbr.getDimensionality() != v.getDimensionality()) {
+ protected double minDistObject(SpatialComparable mbr, NumberVector v) {
+ if(mbr.getDimensionality() != v.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of objects\n " + "first argument: " + mbr.toString() + "\n " + "second argument: " + v.toString());
}
double agg = 0.;
- for (int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double value = v.doubleValue(d);
final double omin = mbr.getMin(d);
final double diff1 = omin - value;
- if (diff1 > 0.) {
- if (diff1 > agg) {
+ if(diff1 > 0.) {
+ if(diff1 > agg) {
agg = diff1;
}
- } else {
+ }
+ else {
final double omax = mbr.getMax(d);
final double diff2 = value - omax;
- if (diff2 > agg) {
+ if(diff2 > agg) {
agg = diff2;
}
}
@@ -96,24 +87,25 @@ public class SubspaceMaximumDistanceFunction extends SubspaceLPNormDistanceFunct
}
@Override
- public double doubleMinDist(SpatialComparable mbr1, SpatialComparable mbr2) {
- if (mbr1.getDimensionality() != mbr2.getDimensionality()) {
+ public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
+ if(mbr1.getDimensionality() != mbr2.getDimensionality()) {
throw new IllegalArgumentException("Different dimensionality of objects\n " + "first argument: " + mbr1.toString() + "\n " + "second argument: " + mbr2.toString());
}
double agg = 0.;
- for (int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
final double max1 = mbr1.getMax(d);
final double min2 = mbr2.getMin(d);
- if (max1 < min2) {
+ if(max1 < min2) {
double v = min2 - max1;
- if (v > agg) {
+ if(v > agg) {
agg = v;
}
- } else {
+ }
+ else {
final double min1 = mbr1.getMin(d);
final double max2 = mbr2.getMax(d);
double v = min1 - max2;
- if (v > agg) {
+ if(v > agg) {
agg = v;
}
}
@@ -122,11 +114,11 @@ public class SubspaceMaximumDistanceFunction extends SubspaceLPNormDistanceFunct
}
@Override
- public double doubleNorm(NumberVector<?> obj) {
+ public double norm(NumberVector obj) {
double agg = 0.;
- for (int d = dimensions.nextSetBit(0); d >= 0; d = dimensions.nextSetBit(d + 1)) {
+ for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
double v = Math.abs(obj.doubleValue(d));
- if (v > agg) {
+ if(v > agg) {
agg = v;
}
}
@@ -140,7 +132,7 @@ public class SubspaceMaximumDistanceFunction extends SubspaceLPNormDistanceFunct
*
* @apiviz.exclude
*/
- public static class Parameterizer extends AbstractDimensionsSelectingDoubleDistanceFunction.Parameterizer {
+ public static class Parameterizer extends AbstractDimensionsSelectingDistanceFunction.Parameterizer {
@Override
protected SubspaceMaximumDistanceFunction makeInstance() {
return new SubspaceMaximumDistanceFunction(dimensions);
diff --git a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/package-info.java b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/package-info.java
index 2b5db4c5..34f1bd33 100644
--- a/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/package-info.java
+++ b/src/de/lmu/ifi/dbs/elki/distance/distancefunction/subspace/package-info.java
@@ -1,11 +1,13 @@
/**
* <p>Distance functions based on subspaces.</p>
+ *
+ * @apiviz.exclude de.lmu.ifi.dbs.elki.math.dimensionsimilarity
*/
/*
This file is part of ELKI:
Environment for Developing KDD-Applications Supported by Index-Structures
-Copyright (C) 2013
+Copyright (C) 2014
Ludwig-Maximilians-Universität München
Lehr- und Forschungseinheit für Datenbanksysteme
ELKI Development Team