Beispiel #1
0
 public void Assign(nPoint obj)
 {
     for (int i = 0; i < Metrik.Length; i++)
     {
         this.Metrik[i] = obj.Metrik[i];
     }
 }
Beispiel #2
0
        public static double MaxRadius(List <nPoint> nPoints, nPoint center)
        {
            var maxValue = Enumerable.Range(0, nPoints.Count)
                           .Select(x => Length(nPoints.ElementAt(x), center))
                           .ToArray().Max();

            return(maxValue);
        }
Beispiel #3
0
        public static nPoint GetCenter(List <nPoint> nPoints)
        {
            nPoint centerPoint = new nPoint("C", nPoints.First().Metrik.Length);

            for (int i = 0; i < centerPoint.Metrik.Length; i++)
            {
                centerPoint.Metrik[i] = nPoints.Average(x => x.Metrik[i]);
            }
            return(centerPoint);
        }
Beispiel #4
0
        public static double Length(nPoint x1, nPoint x2)
        {
            double sum = 0;

            for (int i = 0; i < x1.Metrik.Length; i++)
            {
                sum += Math.Pow((x1.Metrik[i] - x2.Metrik[i]), 2);
            }
            return(Math.Pow(sum, (1.0 / x1.Metrik.Length)));
        }
Beispiel #5
0
 public Taxon(double radius, nPoint center, List <nPoint> points)
 {
     Points.AddRange(points);
     centerTaxon = GetCenter(Points);
     Radius      = MaxRadius(Points, centerTaxon);
 }
Beispiel #6
0
        private void btnToDo_Click(object sender, EventArgs e)
        {
            // clear result datagrid
            for (int i = 1; i <= number; i++)
            {
                for (int j = 1; j <= 3; j++)
                {
                    dataGridViewClassTable[j, i].Value = "";
                }
            }
            //

            List <nPoint> bufferAll      = new List <nPoint>();
            List <nPoint> bufferInternal = new List <nPoint>();

            for (int i = 0; i < number; i++)
            {
                var point = new nPoint(i, classDataset, testDataset, metrik);
                bufferAll.Add(point);
            }


            for (int i = 1; bufferAll.Count != 0; i++)
            {
                // step 1
                bufferInternal.AddRange(bufferAll);

                centerPoint = new double[metrik];
                for (int j = 0; j < metrik; j++)
                {
                    centerPoint[j] = bufferAll.Average(x => x.metrik[j]);
                }

                radius = MaxRadius(bufferAll, centerPoint);

                // step 2
                while (true)
                {
                    radius *= 0.9;

                    for (int j = 0; j < bufferInternal.Count; j++)
                    {
                        var point = bufferInternal.ElementAt(j);
                        if (GetLength(point.metrik, bufferInternal.First().metrik) > radius)
                        {
                            bufferInternal.Remove(point);
                        }
                    }

                    // step 3
                    var centerGravity = new double[metrik];
                    for (int j = 0; j < metrik; j++)
                    {
                        centerGravity[j] = bufferInternal.Average(x => x.metrik[j]);
                    }

                    // step 5
                    if (Equil(centerGravity, centerPoint))
                    {
                        bufferAll.RemoveAll(item => bufferInternal.Contains(item));
                        break;
                    }
                    else
                    {
                        for (int j = 0; j < metrik; j++)
                        {
                            centerPoint[j] = centerGravity[j];
                        }
                    }
                }

                // step 6
                dataGridViewClassTable[1, i].Value = string.Format("Class - " + bufferInternal.Average(x => x.classValue));
                dataGridViewClassTable[2, i].Value = string.Join(" ", bufferInternal.Select(x => x.index + 1));
                dataGridViewClassTable[3, i].Value = (bufferInternal.Count == 1) ? 0 : Math.Round(radius, 2);
                bufferInternal.RemoveRange(0, bufferInternal.Count);
            }
        }