forked from andrewkirillov/AForge.NET
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathEuclideanSimilarity.cs
57 lines (53 loc) · 1.87 KB
/
EuclideanSimilarity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// AForge Math Library
// AForge.NET framework
// http://www.aforgenet.com/framework/
//
// Copyright © AForge.NET, 2007-2010
// contacts@aforgenet.com
//
namespace AForge.Math.Metrics
{
using System;
/// <summary>
/// Euclidean similarity metric.
/// </summary>
///
/// <remarks><para>This class represents the
/// <a href="http://en.wikipedia.org/wiki/Euclidean_distance">Euclidean Similarity metric</a>,
/// which is calculated as 1.0 / ( 1.0 + EuclideanDistance ).</para>
///
/// <para>Sample usage:</para>
/// <code>
/// // instantiate new similarity class
/// EuclideanSimilarity sim = new EuclideanSimilarity( );
/// // create two vectors for inputs
/// double[] p = new double[] { 2.5, 3.5, 3.0, 3.5, 2.5, 3.0 };
/// double[] q = new double[] { 3.0, 3.5, 1.5, 5.0, 3.5, 3.0 };
/// // get simirarity between the two vectors
/// double similarityScore = sim.GetSimilarityScore( p, q );
/// </code>
/// </remarks>
///
public sealed class EuclideanSimilarity : ISimilarity
{
/// <summary>
/// Returns similarity score for two N-dimensional double vectors.
/// </summary>
///
/// <param name="p">1st point vector.</param>
/// <param name="q">2nd point vector.</param>
///
/// <returns>Returns Euclidean similarity between two supplied vectors.</returns>
///
/// <exception cref="ArgumentException">Thrown if the two vectors are of different dimensions (if specified
/// array have different length).</exception>
///
public double GetSimilarityScore( double[] p, double[] q )
{
double distance = 0;
EuclideanDistance dist = new EuclideanDistance( );
distance = 1.0 / ( 1.0 + dist.GetDistance( p, q ) );
return distance;
}
}
}