jsat.linear.distancemetrics
Class DistanceCounter
- java.lang.Object
-
- jsat.linear.distancemetrics.DistanceCounter
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, DistanceMetric
public class DistanceCounter extends java.lang.Object implements DistanceMetric
This class exists primarily as a sanity/benchmarking utility. It takes a given base distance metric, which will be used as the actual method of measuring distances. This class will count how many times a distance calculation was queried. This class is thread safe.
NOTE: all clones of this object will share the same counter.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description DistanceCounter(DistanceCounter toCopy)Copies the given distance counter, while sharing the same underlying counter between the original and this new object.DistanceCounter(DistanceMetric base)Creates a new distance counter to wrap the given base metric
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description DistanceCounterclone()doubledist(int a, int b, java.util.List<? extends Vec> vecs, java.util.List<java.lang.Double> cache)Computes the distance between 2 vectors in the original list of vectors.doubledist(int a, Vec b, java.util.List<? extends Vec> vecs, java.util.List<java.lang.Double> cache)Computes the distance between one vector in the original list of vectors with that of another vector not from the original list.doubledist(int a, Vec b, java.util.List<java.lang.Double> qi, java.util.List<? extends Vec> vecs, java.util.List<java.lang.Double> cache)Computes the distance between one vector in the original list of vectors with that of another vector not from the original list, but had information generated byDistanceMetric.getQueryInfo(jsat.linear.Vec).doubledist(Vec a, Vec b)Computes the distance between 2 vectors.java.util.List<java.lang.Double>getAccelerationCache(java.util.List<? extends Vec> vecs, boolean parallel)Returns a cache of double values associated with the given list of vectors in the given order.longgetCallCount()java.util.List<java.lang.Double>getQueryInfo(Vec q)Pre computes query information that would have be generated if the query was a member of the original list of vectors when callingDistanceMetric.getAccelerationCache(java.util.List).booleanisIndiscemible()Returns true if this distance metric obeys the rule that, for any x and y ∈ S
d(x, y) = 0 if and only if x = ybooleanisSubadditive()Returns true if this distance metric obeys the rule that, for any x, y, and z ∈ S
d(x, z) ≤ d(x, y) + d(y, z)booleanisSymmetric()Returns true if this distance metric obeys the rule that, for any x, y, and z ∈ S
d(x, y) = d(y, x)doublemetricBound()All metrics must return values greater than or equal to 0.voidresetCounter()Resets the distance counter calls to zero.booleansupportsAcceleration()Indicates if this distance metric supports building an acceleration cache using theDistanceMetric.getAccelerationCache(java.util.List)and associated distance methods.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.linear.distancemetrics.DistanceMetric
getAccelerationCache, isValidMetric, toString
-
-
-
-
Constructor Detail
-
DistanceCounter
public DistanceCounter(DistanceMetric base)
Creates a new distance counter to wrap the given base metric- Parameters:
base- the base distance measure to use
-
DistanceCounter
public DistanceCounter(DistanceCounter toCopy)
Copies the given distance counter, while sharing the same underlying counter between the original and this new object.- Parameters:
toCopy- the object to get a copy of
-
-
Method Detail
-
getCallCount
public long getCallCount()
- Returns:
- the number of distance calls that have occurred
-
resetCounter
public void resetCounter()
Resets the distance counter calls to zero.
-
dist
public double dist(Vec a, Vec b)
Description copied from interface:DistanceMetricComputes the distance between 2 vectors. The smaller the value, the closer, and there for, more similar, the vectors are. 0 indicates the vectors are the same.- Specified by:
distin interfaceDistanceMetric- Parameters:
a- the first vectorb- the second vector- Returns:
- the distance between them
-
isSymmetric
public boolean isSymmetric()
Description copied from interface:DistanceMetricReturns true if this distance metric obeys the rule that, for any x, y, and z ∈ S
d(x, y) = d(y, x)- Specified by:
isSymmetricin interfaceDistanceMetric- Returns:
- true if this distance metric is symmetric, false if it is not
-
isSubadditive
public boolean isSubadditive()
Description copied from interface:DistanceMetricReturns true if this distance metric obeys the rule that, for any x, y, and z ∈ S
d(x, z) ≤ d(x, y) + d(y, z)- Specified by:
isSubadditivein interfaceDistanceMetric- Returns:
- true if this distance metric supports the triangle inequality, false if it does not.
-
isIndiscemible
public boolean isIndiscemible()
Description copied from interface:DistanceMetricReturns true if this distance metric obeys the rule that, for any x and y ∈ S
d(x, y) = 0 if and only if x = y- Specified by:
isIndiscemiblein interfaceDistanceMetric- Returns:
- true if this distance metric is indicemible, false otherwise.
-
metricBound
public double metricBound()
Description copied from interface:DistanceMetricAll metrics must return values greater than or equal to 0. The upper bound on the value returned is different for different metrics. This method returns the theoretical maximal value that could be returned by this distance metric. That meansDouble.POSITIVE_INFINITYis a valid return value.- Specified by:
metricBoundin interfaceDistanceMetric- Returns:
- the maximal distance for any two points in that could exist by this distance metric.
-
supportsAcceleration
public boolean supportsAcceleration()
Description copied from interface:DistanceMetricIndicates if this distance metric supports building an acceleration cache using theDistanceMetric.getAccelerationCache(java.util.List)and associated distance methods. By default this method will returnfalse. Iftrue, then a cache can be obtained from this distance metric and used in conjunction withDistanceMetric.dist(int, jsat.linear.Vec, java.util.List, java.util.List)andDistanceMetric.dist(int, int, java.util.List, java.util.List)to perform distance computations.- Specified by:
supportsAccelerationin interfaceDistanceMetric- Returns:
trueif cache acceleration is supported for this metric,falseotherwise.
-
getAccelerationCache
public java.util.List<java.lang.Double> getAccelerationCache(java.util.List<? extends Vec> vecs, boolean parallel)
Description copied from interface:DistanceMetricReturns a cache of double values associated with the given list of vectors in the given order. This can be used by the distance metric to increase runtime at the cost of memory. This is an optional method.
If this metric does not support acceleration,nullwill be returned.- Specified by:
getAccelerationCachein interfaceDistanceMetric- Parameters:
vecs- the list of vectors to build an acceleration cache forparallel-trueif multiple threads should be used to perform clustering.falseif it should be done in a single threaded manner.- Returns:
- the list of double for the cache
-
dist
public double dist(int a, int b, java.util.List<? extends Vec> vecs, java.util.List<java.lang.Double> cache)Description copied from interface:DistanceMetricComputes the distance between 2 vectors in the original list of vectors.
If the cache input isnull, thenDistanceMetric.dist(jsat.linear.Vec, jsat.linear.Vec)will be called directly.- Specified by:
distin interfaceDistanceMetric- Parameters:
a- the index of the first vectorb- the index of the second vectorvecs- the list of vectors used to build the cachecache- the cache associated with the given list of vectors- Returns:
- the distance between the two vectors
-
dist
public double dist(int a, Vec b, java.util.List<? extends Vec> vecs, java.util.List<java.lang.Double> cache)Description copied from interface:DistanceMetricComputes the distance between one vector in the original list of vectors with that of another vector not from the original list.
If the cache input isnull, thenDistanceMetric.dist(jsat.linear.Vec, jsat.linear.Vec)will be called directly.- Specified by:
distin interfaceDistanceMetric- Parameters:
a- the index of the vector in the cacheb- the other vectorvecs- the list of vectors used to build the cachecache- the cache associated with the given list of vectors- Returns:
- the distance between the two vectors
-
getQueryInfo
public java.util.List<java.lang.Double> getQueryInfo(Vec q)
Description copied from interface:DistanceMetricPre computes query information that would have be generated if the query was a member of the original list of vectors when callingDistanceMetric.getAccelerationCache(java.util.List). This can then be used if a large number of distance computations are going to be done against points in the original set for a point that is outside the original space.
If this metric does not support acceleration,nullwill be returned.- Specified by:
getQueryInfoin interfaceDistanceMetric- Parameters:
q- the query point to generate cache information for- Returns:
- the cache information for the query point
-
dist
public double dist(int a, Vec b, java.util.List<java.lang.Double> qi, java.util.List<? extends Vec> vecs, java.util.List<java.lang.Double> cache)Description copied from interface:DistanceMetricComputes the distance between one vector in the original list of vectors with that of another vector not from the original list, but had information generated byDistanceMetric.getQueryInfo(jsat.linear.Vec).
If the cache input isnull, thenDistanceMetric.dist(jsat.linear.Vec, jsat.linear.Vec)will be called directly.- Specified by:
distin interfaceDistanceMetric- Parameters:
a- the index of the vector in the cacheb- the other vectorqi- the query information about bvecs- the list of vectors used to build the cachecache- the cache associated with the given list of vectors- Returns:
- the distance between the two vectors
-
clone
public DistanceCounter clone()
- Specified by:
clonein interfaceDistanceMetric- Overrides:
clonein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG