Click or drag to resize
Accord.NET (logo)

CosineDistance Method

Computes the distance d(x,y) between points x and y.

Namespace:  Accord.Math.Distances
Assembly:  Accord.Math (in Accord.Math.dll) Version: 3.8.0
Syntax
public double Distance(
	double[] x,
	double[] y
)
Request Example View Source

Parameters

x
Type: SystemDouble
The first point x.
y
Type: SystemDouble
The second point y.

Return Value

Type: Double
A double-precision value representing the distance d(x,y) between x and y according to the distance function implemented by this class.

Implements

IDistanceT, UDistance(T, U)
Examples
// The Cosine distance between (0, 2, 4) and (2, 5, 1) can be directly computed as:
double a = Distance.Cosine(new[] { 0.0, 2.0, 4.0 }, new[] { 2.0, 5.0, 1.0 }); // ~0.42845239335059182d

// Or could also be computed by instantiating the Cosine class beforehand as:
Cosine cos = new Cosine();
double b = cos.Distance(new[] { 0.0, 2.0, 4.0 }, new[] { 2.0, 5.0, 1.0 }); // ~0.42845239335059182d
See Also