Exemplo n.º 1
0
 private void voBtnKMedoid_Click(object sender, EventArgs e)
 {
     try
     {
         // define distance function
         Func <Point, Point, double> koEuclidean = (a, b) => Math.Sqrt(Math.Pow((a.X - b.X), 2) + Math.Pow((a.Y - b.Y), 2));
         this.voKM = new KMedoid <Point>(koEuclidean);
         int kiK = int.Parse(this.voTbK.Text);
         this.voKM.MCompute(kiK, this.voPList);
         Visualization.MDrawClusters(this.voPB, this.voPList, this.voKM.VoClusters, kiK,
                                     this.voKM.VdMedoids.ToList( ), 0.7);
         this.voTbResult.Text = mComputeAndShowVarianceResults(kiK);
     }
     catch (Exception koEx)
     {
         MessageBox.Show(koEx.Message);
     }
 }
Exemplo n.º 2
0
 private void btnKMedoid_Click(object sender, EventArgs e)
 {
     try
     {
         // define distance function
         Func <Point, Point, double> euclidean = (a, b) => Math.Sqrt(Math.Pow((a.X - b.X), 2) + Math.Pow((a.Y - b.Y), 2));
         km = new KMedoid <Point>(euclidean);
         int k = int.Parse(txtClusters.Text);
         compute.Start();
         km.Compute(k, PList);
         compute.Stop();
         MessageBox.Show("Time elapsed to compute (ms): " + compute.ElapsedMilliseconds);
         Visualization.DrawClusters(pic1, PList, km.Clusters, k, km._medoids, 0.7);
         txtResult.Text = ComputeAndShowVarianceResults(k);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemplo n.º 3
0
 private void voBtnRedraw_Click(object sender, EventArgs e)
 {
     Visualization.MDrawClusters(this.voPB, this.voPList, this.voKM.VoClusters,
                                 int.Parse(this.voTbK.Text), this.voKM.VdMedoids.ToList( ), 0.5);
 }
Exemplo n.º 4
0
        private void btnInitialize_Click(object sender, EventArgs e)
        {
            PList.Clear();
            Random rand       = new Random();
            int    dataLength = 1000; // number of data points
                                      // create 4 distributions with different means and std devs
            double meanx0   = 150;
            double meanx1   = 250;
            double meanx2   = 375;
            double meanx3   = 475;
            double meany0   = 175;
            double meany1   = 250;
            double meany2   = 350;
            double meany3   = 450;
            double stddevx0 = 240;
            double stddevx1 = 270;
            double stddevx2 = 220;
            double stddevx3 = 260;
            double stddevy0 = 250;
            double stddevy1 = 240;
            double stddevy2 = 280;
            double stddevy3 = 245;
            int    index    = 0;

            Parallel.For(0, (dataLength / 4), (i) =>
                         //for (int i = 0; i < dataLength / 4; i++)
            {
                Point pt    = new Point();
                double rnum = rand.NextDouble();
                if (rnum < 0.5)
                {
                    pt.X = (int)(rand.NextDouble() * stddevx0 / 2 + meanx0);
                }
                else
                {
                    pt.X = (int)(-1 * rand.NextDouble() * stddevx0 / 2 + meanx0);
                }
                if (rnum < 0.5)
                {
                    pt.Y = (int)(rand.NextDouble() * stddevy0 / 2 + meany0);
                }
                else
                {
                    pt.Y = (int)(-1 * rand.NextDouble() * stddevy0 / 2 + meany0);
                }
                index++;
                PList.Add(pt);
            });

            Parallel.For(0, (dataLength / 4), (i) =>
                         //for (int i = 0; i < dataLength / 4; i++)
            {
                Point pt    = new Point();
                double rnum = rand.NextDouble();
                if (rnum < 0.5)
                {
                    pt.X = (int)(rand.NextDouble() * stddevx1 / 2 + meanx1);
                }
                else
                {
                    pt.X = (int)(-1 * rand.NextDouble() * stddevx1 / 2 + meanx1);
                }
                if (rnum < 0.5)
                {
                    pt.Y = (int)(rand.NextDouble() * stddevy1 / 2 + meany1);
                }
                else
                {
                    pt.Y = (int)(-1 * rand.NextDouble() * stddevy1 / 2 + meany1);
                }
                index++;
                PList.Add(pt);
            });

            Parallel.For(0, (dataLength / 4), (i) =>
                         //for (int i = 0; i < dataLength / 4; i++)
            {
                double rnum = rand.NextDouble();
                Point pt    = new Point();
                if (rnum < 0.5)
                {
                    pt.X = (int)(rand.NextDouble() * stddevx2 / 2 + meanx2);
                }
                else
                {
                    pt.X = (int)(-1 * rand.NextDouble() * stddevx2 / 2 + meanx2);
                }
                if (rnum < 0.5)
                {
                    pt.Y = (int)(rand.NextDouble() * stddevy2 / 2 + meany2);
                }
                else
                {
                    pt.Y = (int)(-1 * rand.NextDouble() * stddevy2 / 2 + meany2);
                }
                PList.Add(pt);
                index++;
            });

            Parallel.For(0, (dataLength / 4), (i) =>
                         //for (int i = 0; i < dataLength / 4; i++)
            {
                double rnum = rand.NextDouble();
                Point pt    = new Point();
                if (rnum < 0.5)
                {
                    pt.X = (int)(rand.NextDouble() * stddevx3 / 2 + meanx3);
                }
                else
                {
                    pt.X = (int)(-1 * rand.NextDouble() * stddevx3 / 2 + meanx3);
                }
                if (rnum < 0.5)
                {
                    pt.Y = (int)(rand.NextDouble() * stddevy3 / 2 + meany3);
                }
                else
                {
                    pt.Y = (int)(-1 * rand.NextDouble() * stddevy3 / 2 + meany3);
                }
                index++;
                PList.Add(pt);
            });

            Visualization.DrawPoints(pic1, PList, 0.7);
            MessageBox.Show("Data initialized for " + PList.Count + " points");
        }
Exemplo n.º 5
0
 private void btnRedraw_Click(object sender, EventArgs e)
 {
     Visualization.DrawClusters(pic1, PList, km.Clusters, int.Parse(txtClusters.Text), km._medoids, 0.5);
 }