jsat.linear.distancemetrics
Class ManhattanDistance
- java.lang.Object
-
- jsat.linear.distancemetrics.ManhattanDistance
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, DenseSparseMetric, DistanceMetric
public class ManhattanDistance extends java.lang.Object implements DenseSparseMetric
Manhattan Distance is the L1 norm.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description ManhattanDistance()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description ManhattanDistanceclone()doubledist(double summaryConst, Vec main, Vec target)Efficiently computes the distance from one main vector that is used many times, to some sparse target vector.doubledist(Vec a, Vec b)Computes the distance between 2 vectors.doublegetVectorConstant(Vec vec)Computes a summary constant value for the vector that is based on the distance metric in use.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.java.lang.StringtoString()Returns a descriptive name of the Distance Metric in use-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsat.linear.distancemetrics.DistanceMetric
dist, dist, dist, getAccelerationCache, getAccelerationCache, getQueryInfo, isValidMetric, supportsAcceleration
-
-
-
-
Method Detail
-
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.
-
toString
public java.lang.String toString()
Description copied from interface:DistanceMetricReturns a descriptive name of the Distance Metric in use- Specified by:
toStringin interfaceDistanceMetric- Overrides:
toStringin classjava.lang.Object- Returns:
- the name of this metric
-
clone
public ManhattanDistance clone()
- Specified by:
clonein interfaceDistanceMetric- Overrides:
clonein classjava.lang.Object
-
getVectorConstant
public double getVectorConstant(Vec vec)
Description copied from interface:DenseSparseMetricComputes a summary constant value for the vector that is based on the distance metric in use. This value will be used to perform efficient dense to sparse computations.- Specified by:
getVectorConstantin interfaceDenseSparseMetric- Parameters:
vec- the vector that will be used in many distance computations- Returns:
- the summary value for the vector
-
dist
public double dist(double summaryConst, Vec main, Vec target)Description copied from interface:DenseSparseMetricEfficiently computes the distance from one main vector that is used many times, to some sparse target vector. If the target vector dose not return true forVec.isSparse(), the distance will be calculated usingDistanceMetric.dist(jsat.linear.Vec, jsat.linear.Vec)instead.- Specified by:
distin interfaceDenseSparseMetric- Parameters:
summaryConst- the summary constant for the main vector obtained withDenseSparseMetric.getVectorConstant(jsat.linear.Vec)main- the main vector the summary constant is fortarget- the target vector to compute the distance to- Returns:
- the distance between the two vectors dist(main, target)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG