Esempio n. 1
0
        /// <summary>
        /// Simple Euclidean distance
        /// cf. http://en.wikipedia.org/wiki/Euclidean_distance
        /// Consider also: Manhattan, Chebyshev & Minkowski distances
        /// </summary>
        /// <param name="P1"></param>
        /// <param name="P2"></param>
        /// <returns></returns>
        private double GetEuclideanD(Case P1, Case P2)
        {
            EuclideanSimilarity sim = new EuclideanSimilarity(); // the Pythagorean theorem we calculate the distance between two points

            return(sim.Dissimilarity(P1, P2));                   // vyzvraschaem distance
            //return sim.Compare(P1, P2); // vyzvraschaem distance
        }
Esempio n. 2
0
        private double distance(Case a, Case b)                  // the distance between two points
        {
            EuclideanSimilarity sim = new EuclideanSimilarity(); // the Pythagorean theorem we calculate the distance between two points

            //    return sim.Compare(a, b); // vyzvraschaem distance 1/distance
            return(sim.Dissimilarity(a, b));
        }
        private void button3_Click_1(object sender, EventArgs e)
        {
            if (add_file())
            {
                List <Case> centroids = new List <Case>();
                centroids = Db.get_Centroids(choice.Tablename_Standardization, choice.CaseName);
                for (int i = 0; i < ListCases.Count; i++)
                {
                    // Case s_case = new Case(0, ListCases[0].GetCaseName(), ListCases[0].GetCaseDescription());
                    List <Case> restandrize_array = choice.Re_standrize(ListCases[i]);//, out s_case);
                    Case        s_case            = restandrize_array.Last();
                    Case        result_centroid   = choice.Updated_cluster_Min_Centroid(s_case, centroids, restandrize_array);
                    if (result_centroid != null)
                    {
                        Feature f = (Feature)result_centroid.GetFeatures()[0];
                        s_case.GetFeature("cluster").SetFeatureValue(f.GetFeatureValue()); // اسناد العنقود المناسب للعنصر الجديد
                        Db.update_cluster(choice.Tablename_Standardization, s_case.GetFeature("id").GetFeatureValue().ToString(), Convert.ToInt32(f.GetFeatureValue()));
                        Db.update_cluster(choice.TableName, s_case.GetFeature("id").GetFeatureValue().ToString(), Convert.ToInt32(f.GetFeatureValue()));
                        double ess = 0;
                        //   من ضمن الداتا سيت المقييسة يتم حساب المراكز لجميع العناقيد
                        for (int k = 0; k < Convert.ToInt32(choice.Clusters_Num); k++)
                        {
                            List <Case> S_Arr_Cluster = Db.get_cases_condition_cluster(choice.Tablename_Standardization, choice.CaseName, "cluster", k.ToString());
                            Feature     cen           = S_Arr_Cluster[0].GetFeature("cluster");
                            Case        new_centroid  = Kmeans.ReCalcCentroid(S_Arr_Cluster, Convert.ToInt32(cen.GetFeatureValue()));
                            Db.insert_case_to_table(new_centroid, choice.Tablename_Standardization);
                            EuclideanSimilarity es = new EuclideanSimilarity();
                            double d = 0;
                            foreach (Case c in S_Arr_Cluster)
                            {
                                d += es.Dissimilarity(c, new_centroid);
                            }

                            ess += d;
                        }
                        MessageBox.Show(ess.ToString());
                    }
                }
                dataGridView_old.DataSource = Db.get_table_contetnt(choice.TableName);
            }
        }
Esempio n. 4
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            textBox1.Text = Db.Get_CostFunction(listBox1.SelectedValue.ToString()).ToString();
            string t   = listBox1.SelectedValue.ToString().ToString();
            double sse = 0;
            EuclideanSimilarity sim = new EuclideanSimilarity();
            string      c           = listBox1.Text;
            List <Case> cases       = Db.get_cases_condition(Db.get_standriazation(t), c);
            List <Case> centroids   = Db.get_Centroids(Db.get_standriazation(t), c);

            foreach (Case a in cases)
            {
                foreach (Case ce in centroids)
                {
                    if (a.GetFeature("cluster").GetFeatureValue().ToString() == ce.GetFeature("id").GetFeatureValue().ToString())
                    {
                        sse += sim.Dissimilarity(a, ce); break;
                    }
                }
            }
            textBox1.Text = sse.ToString();
        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            if (add_file())
            {
                List <Case> centroids = new List <Case>();
                centroids = Db.get_Centroids(choice.Tablename_Standardization, choice.CaseName);
                List <string> Ids = new List <string>();
                for (int i = 0; i < ListCases.Count; i++)
                {
                    //Case s_case = new Case(0, ListCases[0].GetCaseName(), ListCases[0].GetCaseDescription());
                    // تقييس الداتا سيت بناءا على العنصر الجديد
                    var watch = System.Diagnostics.Stopwatch.StartNew();

                    List <Case> restandrize_array = choice.Re_standrize(ListCases[i]);
                    // العنصر الجديد بعد التقييس
                    Case s_case = restandrize_array.Last();

                    // نرى إلى أي عنقود ستمم اضافته
                    Case result_centroid = choice.Updated_cluster(s_case, centroids, restandrize_array);
                    watch.Stop();
                    var elapsedMs = watch.ElapsedMilliseconds;
                    label2.Text = "with clustring time  " + elapsedMs.ToString();
                    // سيتم انضمامه لعنقود موجود
                    if (result_centroid != null)
                    {
                        Feature f = (Feature)result_centroid.GetFeatures()[0];
                        s_case.GetFeature("cluster").SetFeatureValue(f.GetFeatureValue()); // اسناد العنقود المناسب للعنصر الجديد
                        Db.update_cluster(choice.Tablename_Standardization, s_case.GetFeature("id").GetFeatureValue().ToString(), Convert.ToInt32(f.GetFeatureValue()));
                        Db.update_cluster(choice.TableName, s_case.GetFeature("id").GetFeatureValue().ToString(), Convert.ToInt32(f.GetFeatureValue()));
                        Ids.Add(f.GetFeatureValue().ToString());
                    }    // end if
                    else // عنقود جديد
                    {
                        int k = Convert.ToInt32(choice.Clusters_Num) + 1;
                        // اضافة عنقود جديد
                        Db.update_cluster(choice.Tablename_Standardization, s_case.GetFeature("id").GetFeatureValue().ToString(), k);
                        Db.update_cluster(choice.TableName, s_case.GetFeature("id").GetFeatureValue().ToString(), k);
                        Case new_centroid = s_case;
                        new_centroid.GetFeature("cluster").SetFeatureValue(-1);
                        Db.insert_case_to_table(new_centroid, choice.Tablename_Standardization);
                        choice.Clusters_Num = k.ToString();
                        Db.update_clusterNum(choice.CaseName, k);
                    }
                } // end for all new cases
                if (Ids != null)
                {
                    Db.del_centroids(choice.Tablename_Standardization, Ids);
                    double ess = 0;
                    //   من ضمن الداتا سيت المقييسة يتم حساب المراكز لجميع العناقيد
                    foreach (string id in Ids)
                    {
                        List <Case>         S_Arr_Cluster = Db.get_cases_condition_cluster(choice.Tablename_Standardization, choice.CaseName, "cluster", id);
                        Feature             cen           = S_Arr_Cluster[0].GetFeature("cluster");
                        Case                new_centroid  = Kmeans.ReCalcCentroid(S_Arr_Cluster, Convert.ToInt32(cen.GetFeatureValue()));
                        EuclideanSimilarity es            = new EuclideanSimilarity();
                        double              d             = 0;
                        foreach (Case c in S_Arr_Cluster)
                        {
                            d += es.Dissimilarity(c, new_centroid);
                        }

                        ess += d;

                        Db.insert_case_to_table(new_centroid, choice.Tablename_Standardization);
                    }
                    //  حساب distorion error
                    MessageBox.Show(ess.ToString());
                }
                dataGridView_old.DataSource = Db.get_table_contetnt(choice.TableName);
            }
        }