/// <summary>
        /// Calculate the euclidean distance between a centroid and data.
        /// </summary>
        ///
        /// <param name="c">The centroid to use.</param>
        /// <param name="data">The data to use.</param>
        /// <returns>The distance.</returns>
        public static double CalculateEuclideanDistance(Centroid c,
                                                        IMLData data)
        {
            double[] d   = data.Data;
            double   sum = c.Centers.Select((t, i) => Math.Pow(d[i] - t, 2)).Sum();

            return(Math.Sqrt(sum));
        }
 /// <summary>
 /// Setup the initial centroids.
 /// </summary>
 ///
 private void SetInitialCentroids()
 {
     for (int n = 1; n <= _clusters.Length; n++)
     {
         var temp = new double[_set.InputSize];
         for (int j = 0; j < temp.Length; j++)
         {
             temp[j] = (((GetMaxValue(j) - GetMinValue(j)) / (_clusters.Length + 1)) * n)
                       + GetMinValue(j);
         }
         var c1 = new Centroid(temp);
         _clusters[n - 1].Centroid = c1;
         c1.Cluster = _clusters[n - 1];
     }
 }
 /// <summary>
 /// Setup the initial centroids.
 /// </summary>
 ///
 private void SetInitialCentroids()
 {
     for (int n = 1; n <= _clusters.Length; n++)
     {
         var temp = new double[_set.InputSize];
         for (int j = 0; j < temp.Length; j++)
         {
             temp[j] = (((GetMaxValue(j) - GetMinValue(j))/(_clusters.Length + 1))*n)
                       + GetMinValue(j);
         }
         var c1 = new Centroid(temp);
         _clusters[n - 1].Centroid = c1;
         c1.Cluster = _clusters[n - 1];
     }
 }
        /// <summary>
        /// Calculate the euclidean distance between a centroid and data.
        /// </summary>
        ///
        /// <param name="c">The centroid to use.</param>
        /// <param name="data">The data to use.</param>
        /// <returns>The distance.</returns>
        public static double CalculateEuclideanDistance(Centroid c,
                                                        IMLData data)
        {
            double[] d = data.Data;
            double sum = c.Centers.Select((t, i) => Math.Pow(d[i] - t, 2)).Sum();

            return Math.Sqrt(sum);
        }
Exemple #5
0
 private void x318cf87d7d6afed3()
 {
     double[] numArray;
     int num2;
     int num = 1;
     Label_0039:
     if (num <= this._x0068961b43401a6f.Length)
     {
         numArray = new double[this._xa1ca3186bd369811.InputSize];
         num2 = 0;
         goto Label_008D;
     }
     return;
     Label_0060:
     numArray[num2] = (((this.xe6459878eee52706(num2) - this.x2cf6175701bf1768(num2)) / ((double) (this._x0068961b43401a6f.Length + 1))) * num) + this.x2cf6175701bf1768(num2);
     num2++;
     Label_008D:
     if (num2 < numArray.Length)
     {
         goto Label_0060;
     }
     Centroid centroid = new Centroid(numArray);
     this._x0068961b43401a6f[num - 1].Centroid = centroid;
     if (8 == 0)
     {
         if ((((uint) num) + ((uint) num)) > uint.MaxValue)
         {
             goto Label_0039;
         }
         goto Label_0060;
     }
     centroid.Cluster = this._x0068961b43401a6f[num - 1];
     num++;
     goto Label_0039;
 }
Exemple #6
0
 public static double CalculateEuclideanDistance(Centroid c, IMLData data)
 {
     double[] d = data.Data;
     return Math.Sqrt(c.Centers.Select<double, double>((t, i) => Math.Pow(d[i] - t, 2.0)).Sum());
 }