Ejemplo n.º 1
0
        /// <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;
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        public void EuclideanDistanceTest( )
        {
            EuclideanDistance dist = new EuclideanDistance( );

            Assert.Throws<ArgumentException>( ( ) => dist.GetDistance( p0, q4 ) );

            double result = dist.GetDistance( p0, q0 );
            Assert.AreApproximatelyEqual( result, .70711, 0.00001 );

            result = dist.GetDistance( p1, q1 );
            Assert.AreApproximatelyEqual( result, 1.11803, 0.00001 );

            result = dist.GetDistance( p2, q2 );
            Assert.AreEqual( result, 0 );

            result = dist.GetDistance( p3, q3 );
            Assert.AreEqual( result, 0 );

            result = dist.GetDistance( p4, q4 );
            Assert.AreApproximatelyEqual( result, 2.39792, 0.00001 );

            result = dist.GetDistance( p5, q5 );
            Assert.AreApproximatelyEqual( result, 4.24264, 0.00001 );
        }