Class Cosine
Cosine distance. For a proper distance metric, see Angular.
Inheritance
System.Object
Cosine
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Mars.Numerics.Distances
Assembly: Mars.Numerics.dll
Syntax
[Serializable]
public class Cosine : IDistance<double[]>, IDistance<double[], double[]>, ISimilarity<double[]>, ISimilarity<double[], double[]>, ICloneable
Remarks
Intuition behind selecting float as a carrier.
1. In practice we work with vectors of dimensionality 100 and each component has value in range [-1; 1]
There certainly is a possibility of underflow.
But we assume that such cases are rare and we can rely on such underflow losses.
2. According to the article http://www.ti3.tuhh.de/paper/rump/JeaRu13.pdf
the floating point rounding error is less then 100 * 2^-24 * sqrt(100) * sqrt(100) < 0.0005960
We deem such precision is satisfactory for out needs.
Methods
| Improve this Doc View SourceClone()
Creates a new object that is a copy of the current instance.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object | A new object that is a copy of this instance. |
Remarks
Intuition behind selecting float as a carrier.
1. In practice we work with vectors of dimensionality 100 and each component has value in range [-1; 1]
There certainly is a possibility of underflow.
But we assume that such cases are rare and we can rely on such underflow losses.
2. According to the article http://www.ti3.tuhh.de/paper/rump/JeaRu13.pdf
the floating point rounding error is less then 100 * 2^-24 * sqrt(100) * sqrt(100) < 0.0005960
We deem such precision is satisfactory for out needs.
See Also
| Improve this Doc View SourceDistance(Double[], Double[])
Computes the distance
d(x,y)
between points
x
and y
.
Declaration
public double Distance(double[] x, double[] y)
Parameters
Type | Name | Description |
---|---|---|
System.Double[] | x | The first point x . |
System.Double[] | y | The second point y . |
Returns
Type | Description |
---|---|
System.Double |
A double-precision value representing the distance d(x,y)
between x and y according
to the distance function implemented by this class.
|
Remarks
Intuition behind selecting float as a carrier.
1. In practice we work with vectors of dimensionality 100 and each component has value in range [-1; 1]
There certainly is a possibility of underflow.
But we assume that such cases are rare and we can rely on such underflow losses.
2. According to the article http://www.ti3.tuhh.de/paper/rump/JeaRu13.pdf
the floating point rounding error is less then 100 * 2^-24 * sqrt(100) * sqrt(100) < 0.0005960
We deem such precision is satisfactory for out needs.
See Also
| Improve this Doc View SourceDistanceSimd(Single[], Single[])
Calculates cosine distance optimized using SIMD instructions.
Declaration
public float DistanceSimd(float[] u, float[] v)
Parameters
Type | Name | Description |
---|---|---|
System.Single[] | u | Left vector. |
System.Single[] | v | Right vector. |
Returns
Type | Description |
---|---|
System.Single | Cosine distance between u and v. |
Remarks
Intuition behind selecting float as a carrier.
1. In practice we work with vectors of dimensionality 100 and each component has value in range [-1; 1]
There certainly is a possibility of underflow.
But we assume that such cases are rare and we can rely on such underflow losses.
2. According to the article http://www.ti3.tuhh.de/paper/rump/JeaRu13.pdf
the floating point rounding error is less then 100 * 2^-24 * sqrt(100) * sqrt(100) < 0.0005960
We deem such precision is satisfactory for out needs.
See Also
| Improve this Doc View SourceSimilarity(Double[], Double[])
Gets a similarity measure between two points.
Declaration
public double Similarity(double[] x, double[] y)
Parameters
Type | Name | Description |
---|---|---|
System.Double[] | x | The first point to be compared. |
System.Double[] | y | The second point to be compared. |
Returns
Type | Description |
---|---|
System.Double | A similarity measure between x and y. |
Remarks
Intuition behind selecting float as a carrier.
1. In practice we work with vectors of dimensionality 100 and each component has value in range [-1; 1]
There certainly is a possibility of underflow.
But we assume that such cases are rare and we can rely on such underflow losses.
2. According to the article http://www.ti3.tuhh.de/paper/rump/JeaRu13.pdf
the floating point rounding error is less then 100 * 2^-24 * sqrt(100) * sqrt(100) < 0.0005960
We deem such precision is satisfactory for out needs.
See Also
| Improve this Doc View SourceSimilarity(Single[], Single[])
Gets a similarity measure between two points.
Declaration
public float Similarity(float[] x, float[] y)
Parameters
Type | Name | Description |
---|---|---|
System.Single[] | x | The first point to be compared. |
System.Single[] | y | The second point to be compared. |
Returns
Type | Description |
---|---|
System.Single | A similarity measure between x and y. |
Remarks
Intuition behind selecting float as a carrier.
1. In practice we work with vectors of dimensionality 100 and each component has value in range [-1; 1]
There certainly is a possibility of underflow.
But we assume that such cases are rare and we can rely on such underflow losses.
2. According to the article http://www.ti3.tuhh.de/paper/rump/JeaRu13.pdf
the floating point rounding error is less then 100 * 2^-24 * sqrt(100) * sqrt(100) < 0.0005960
We deem such precision is satisfactory for out needs.
See Also
Implements
System.ICloneable