jsat.linear.distancemetrics
Class PearsonDistance
- java.lang.Object
-
- jsat.linear.distancemetrics.PearsonDistance
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, DistanceMetric
public class PearsonDistance extends java.lang.Object implements DistanceMetric
A valid distance metric formed from the Pearson Correlation between two vectors. The distance in the range of [0, 1].- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description PearsonDistance()Creates a new standard Pearson Distance that does not ignore zero values and anti-correlated values are considered far away.PearsonDistance(boolean bothNonZero, boolean absoluteDistance)Creates a new Pearson Distance object
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description PearsonDistanceclone()static doublecorrelation(Vec a, Vec b, boolean bothNonZero)Computes the Pearson correlation between two vectors.doubledist(Vec a, Vec b)Computes the distance between 2 vectors.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.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.linear.distancemetrics.DistanceMetric
dist, dist, dist, getAccelerationCache, getAccelerationCache, getQueryInfo, isValidMetric, supportsAcceleration, toString
-
-
-
-
Constructor Detail
-
PearsonDistance
public PearsonDistance()
Creates a new standard Pearson Distance that does not ignore zero values and anti-correlated values are considered far away.
-
PearsonDistance
public PearsonDistance(boolean bothNonZero, boolean absoluteDistance)Creates a new Pearson Distance object- Parameters:
bothNonZero-trueif non zero values should be treated as "missing" or "no vote", and will not contribute. But this will not change the mean value used.falseproduces the standard Pearson value.absoluteDistance-trueto use the absolute correlation, meaning correlated and anti-correlated values will have the same distance.
-
-
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.
-
clone
public PearsonDistance clone()
- Specified by:
clonein interfaceDistanceMetric- Overrides:
clonein classjava.lang.Object
-
correlation
public static double correlation(Vec a, Vec b, boolean bothNonZero)
Computes the Pearson correlation between two vectors. If one of the vectors is all zeros, the result is undefined. In cases where both are zero vectors, 1 will be returned to indicate they are the same. In cases where one of the numerator coefficients is zero, its value will be bumped up to an epsilon to provide a near result.
In cases wherebothNonZeroistrue, and the vectors have no overlapping non zero values, 0 will be returned.- Parameters:
a- the first vectorb- the second vectorbothNonZero-falseis the normal Pearson correlation.truewill make the computation ignore all indexes where one of the values is zero, the mean will be from all non zero values in each vector.- Returns:
- the Pearson correlation in [-1, 1]
-
-
DataMelt 3.0 © DataMelt by jWork.ORG