public interface DistanceMetric extends Cloneable, Serializable
symmetry
, indisceribility
,
and the triangle inequality
. A metric that does
not meet all, (or none) or these properties is called a pseudo-metric. Many
learning algorithms rely on these properties to accelerate computations,
though may not need all the properties to hold.
supportsAcceleration()
method. The associated methods are
defined such that the cache calls can be used in a seamless way that will
automatically invoke the caching behavior when supported. Simply initiate
with List<Double> distCache = dm.getAccelerationCache(vecList);
double dist = dm.dist(indx1, indx2, vecList, distCache);
distCache
, at which point the
implementation will call the standard
dist(jsat.linear.Vec, jsat.linear.Vec)
using the list and indices.
The other cache accelerated methods behave in the same way, including
getQueryInfo(jsat.linear.Vec)
Modifier and Type | Method and Description |
---|---|
DistanceMetric |
clone() |
double |
dist(int a,
int b,
List<? extends Vec> vecs,
List<Double> cache)
Computes the distance between 2 vectors in the original list of vectors.
|
double |
dist(int a,
Vec b,
List<? extends Vec> vecs,
List<Double> cache)
Computes the distance between one vector in the original list of vectors
with that of another vector not from the original list.
|
double |
dist(int a,
Vec b,
List<Double> qi,
List<? extends Vec> vecs,
List<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 by
getQueryInfo(jsat.linear.Vec) . |
double |
dist(Vec a,
Vec b)
Computes the distance between 2 vectors.
|
List<Double> |
getAccelerationCache(List<? extends Vec> vecs)
Returns a cache of double values associated with the given list of
vectors in the given order.
|
List<Double> |
getAccelerationCache(List<? extends Vec> vecs,
ExecutorService threadpool)
Returns a cache of double values associated with the given list of
vectors in the given order.
|
List<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 calling
getAccelerationCache(java.util.List) . |
boolean |
isIndiscemible()
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 = y |
boolean |
isSubadditive()
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) |
boolean |
isSymmetric()
Returns true if this distance metric obeys the rule that, for any x, y, and z ∈ S
d(x, y) = d(y, x) |
double |
metricBound()
All metrics must return values greater than or equal to 0.
|
boolean |
supportsAcceleration()
Indicates if this distance metric supports building an acceleration cache
using the
getAccelerationCache(java.util.List) and associated
distance methods. |
String |
toString()
Returns a descriptive name of the Distance Metric in use
|
double dist(Vec a, Vec b)
a
- the first vectorb
- the second vectorboolean isSymmetric()
boolean isSubadditive()
boolean isIndiscemible()
double metricBound()
Double.POSITIVE_INFINITY
is a valid return value.boolean supportsAcceleration()
getAccelerationCache(java.util.List)
and associated
distance methods. By default this method will return false
. If
true
, then a cache can be obtained from this distance metric and
used in conjunction with dist(int, jsat.linear.Vec,
java.util.List, java.util.List)
and dist(int, int,
java.util.List, java.util.List)
to perform distance computations.true
if cache acceleration is supported for this metric,
false
otherwise.List<Double> getAccelerationCache(List<? extends Vec> vecs)
null
will be
returned.vecs
- the list of vectors to build an acceleration cache forList<Double> getAccelerationCache(List<? extends Vec> vecs, ExecutorService threadpool)
null
will be
returned.vecs
- the list of vectors to build an acceleration cache forthreadpool
- source of threads for parallel computation of result.
This may be null
, which means the
singled threaded
version
may be used.double dist(int a, int b, List<? extends Vec> vecs, List<Double> cache)
null
, then
dist(jsat.linear.Vec, jsat.linear.Vec)
will be called directly.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 vectorsdouble dist(int a, Vec b, List<? extends Vec> vecs, List<Double> cache)
null
, then
dist(jsat.linear.Vec, jsat.linear.Vec)
will be called directly.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 vectorsList<Double> getQueryInfo(Vec q)
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.
null
will be
returned.q
- the query point to generate cache information fordouble dist(int a, Vec b, List<Double> qi, List<? extends Vec> vecs, List<Double> cache)
getQueryInfo(jsat.linear.Vec)
.
null
, then
dist(jsat.linear.Vec, jsat.linear.Vec)
will be called directly.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 vectorsString toString()
DistanceMetric clone()
Copyright © 2017. All rights reserved.