Beispiel #1
0
        /**
         * <summary> The calculateMetric method takes an {@link Instance} and a String as inputs. It multiplies Matrix Wi with Vector xi
         * then calculates the dot product of it with xi. Then, again it finds the dot product of wi and xi and returns the summation with w0i.</summary>
         *
         * <param name="instance">{@link Instance} input.</param>
         * <param name="ci">      String input.</param>
         * <returns>The result of Wi.multiplyWithVectorFromLeft(xi).dotProduct(xi) + wi.dotProduct(xi) + w0i.</returns>
         */
        protected override double CalculateMetric(Instance.Instance instance, string ci)
        {
            var xi  = instance.ToVector();
            var Wi  = _W[ci];
            var wi  = w[ci];
            var w0i = w0[ci];

            return(Wi.MultiplyWithVectorFromLeft(xi).DotProduct(xi) + wi.DotProduct(xi) + w0i);
        }
        /**
         * <summary> Calculates Mahalanobis distance between two instances. (x^(1) - x^(2)) S (x^(1) - x^(2))^T</summary>
         *
         * <param name="instance1">First instance.</param>
         * <param name="instance2">Second instance.</param>
         * <returns>Mahalanobis distance between two instances.</returns>
         */
        public double Distance(Instance.Instance instance1, Instance.Instance instance2)
        {
            var v1 = instance1.ToVector();
            var v2 = instance2.ToVector();

            v1.Subtract(v2);
            var v3 = _covarianceInverse.MultiplyWithVectorFromLeft(v1);

            return(v3.DotProduct(v1));
        }
 /**
  * <summary> The createInputVector method takes an {@link Instance} as an input. It converts given Instance to the {@link java.util.Vector}
  * and insert 1.0 to the first element.</summary>
  *
  * <param name="instance">Instance to insert 1.0.</param>
  */
 protected void CreateInputVector(Instance.Instance instance)
 {
     x = instance.ToVector();
     x.Insert(0, 1.0);
 }