public class WeightedEuclideanDistance extends Object implements DistanceMetric
EuclideanDistance
.Constructor and Description |
---|
WeightedEuclideanDistance(Vec w)
Creates a new weighted Euclidean distance metric using the
given set of weights.
|
Modifier and Type | Method and Description |
---|---|
WeightedEuclideanDistance |
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
DistanceMetric.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
DistanceMetric.getAccelerationCache(java.util.List) . |
Vec |
getWeight()
Returns the weight vector used by this object.
|
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.
|
void |
setWeight(Vec w)
Sets the weight vector to use for the distance function
|
boolean |
supportsAcceleration()
Indicates if this distance metric supports building an acceleration cache
using the
DistanceMetric.getAccelerationCache(java.util.List) and associated
distance methods. |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
toString
public WeightedEuclideanDistance(Vec w)
w
- the weight to apply to each variablepublic Vec getWeight()
setWeight(jsat.linear.Vec)
. If you do not want to
alter it, you will need to clone the returned object and modify that.public void setWeight(Vec w)
w
- the weight vector to useNullPointerException
- if w
is nullpublic double dist(Vec a, Vec b)
DistanceMetric
dist
in interface DistanceMetric
a
- the first vectorb
- the second vectorpublic boolean isSymmetric()
DistanceMetric
isSymmetric
in interface DistanceMetric
public boolean isSubadditive()
DistanceMetric
isSubadditive
in interface DistanceMetric
public boolean isIndiscemible()
DistanceMetric
isIndiscemible
in interface DistanceMetric
public double metricBound()
DistanceMetric
Double.POSITIVE_INFINITY
is a valid return value.metricBound
in interface DistanceMetric
public WeightedEuclideanDistance clone()
clone
in interface DistanceMetric
clone
in class Object
public boolean supportsAcceleration()
DistanceMetric
DistanceMetric.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 DistanceMetric.dist(int, jsat.linear.Vec,
java.util.List, java.util.List)
and DistanceMetric.dist(int, int,
java.util.List, java.util.List)
to perform distance computations.supportsAcceleration
in interface DistanceMetric
true
if cache acceleration is supported for this metric,
false
otherwise.public List<Double> getAccelerationCache(List<? extends Vec> vecs)
DistanceMetric
null
will be
returned.getAccelerationCache
in interface DistanceMetric
vecs
- the list of vectors to build an acceleration cache forpublic List<Double> getAccelerationCache(List<? extends Vec> vecs, ExecutorService threadpool)
DistanceMetric
null
will be
returned.getAccelerationCache
in interface DistanceMetric
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.public double dist(int a, int b, List<? extends Vec> vecs, List<Double> cache)
DistanceMetric
null
, then
DistanceMetric.dist(jsat.linear.Vec, jsat.linear.Vec)
will be called directly.dist
in interface DistanceMetric
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 vectorspublic double dist(int a, Vec b, List<? extends Vec> vecs, List<Double> cache)
DistanceMetric
null
, then
DistanceMetric.dist(jsat.linear.Vec, jsat.linear.Vec)
will be called directly.dist
in interface DistanceMetric
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 vectorspublic List<Double> getQueryInfo(Vec q)
DistanceMetric
DistanceMetric.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.getQueryInfo
in interface DistanceMetric
q
- the query point to generate cache information forpublic double dist(int a, Vec b, List<Double> qi, List<? extends Vec> vecs, List<Double> cache)
DistanceMetric
DistanceMetric.getQueryInfo(jsat.linear.Vec)
.
null
, then
DistanceMetric.dist(jsat.linear.Vec, jsat.linear.Vec)
will be called directly.dist
in interface DistanceMetric
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 vectorsCopyright © 2017. All rights reserved.