Example #1
0
        public bool HistogramSet(List <string> testset, List <string> trainset, int order)
        {
            if (testset.Count > 0)
            {
                FreeContainer.FreeTable(HMatrix);
                for (int i = 0; i < trainset.Count + 1; i++)
                {
                    if (i == 0)
                    {
                        DataColumn dc = new DataColumn(" ");
                        HMatrix.Columns.Add(dc);
                    }
                    else
                    {
                        DataColumn dc = new DataColumn(trainset[i - 1]);
                        HMatrix.Columns.Add(dc);
                    }
                }
                for (int i = 0; i < testset.Count; i++)
                {
                    DataRow dr = HMatrix.NewRow();
                    dr[0] = testset[i];
                    List <double> l1 = new List <double>();
                    ReadHistogram(Config.uksoilhistogram, testset[i], out l1);
                    for (int j = 0; j < trainset.Count; j++)
                    {
                        AuxiliaryFunc.percent = Convert.ToInt32((i + 1) * (j + 1) / testset.Count / trainset.Count * 95);
                        List <double> l2 = new List <double>();
                        ReadHistogram(Config.soilhistogram, trainset[j], out l2);
                        switch (order)
                        {
                        case 0: dr[j + 1] = Distance_Fomula.Euclidean(l1, l2).ToString(); break;

                        case 1: dr[j + 1] = Distance_Fomula.X2(l1, l2).ToString(); break;

                        case 2: dr[j + 1] = Distance_Fomula.Dxy(l1, l2).ToString(); break;

                        default: break;
                        }
                    }
                    HMatrix.Rows.Add(dr);
                }
                return(true);
            }
            else
            {
                MessageBox.Show("测试集为空!");
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// 计算直方图距离矩阵
        /// </summary>
        /// <param name="testset"></param>
        /// <param name="trainset"></param>
        /// <param name="groups"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public bool HistogramMatrix(List <string> testset, List <string> trainset, int order)
        {
            FreeContainer.FreeTable(Matrix);
            for (int i = 0; i < trainset.Count + 1; i++)
            {
                if (i == 0)
                {
                    DataColumn dc = new DataColumn();
                    Matrix.Columns.Add(dc);
                }
                else
                {
                    DataColumn dc = new DataColumn(trainset[i - 1]);
                    Matrix.Columns.Add(dc);
                }
            }
            for (int i = 0; i < testset.Count; i++)
            {
                DataRow dr = Matrix.NewRow();
                dr[0] = testset[i];
                List <double> l1 = new List <double>();
                ReadHistogram(Config.soilhistogram, testset[i], out l1);
                for (int j = 0; j < trainset.Count; j++)
                {
                    List <double> l2 = new List <double>();
                    ReadHistogram(Config.soilhistogram, trainset[j], out l2);
                    if (l1.Count > 0 && l2.Count > 0)//防止剖面缺失
                    {
                        switch (order)
                        {
                        case 0: dr[j + 1] = Distance_Fomula.Euclidean(l1, l2).ToString(); break;

                        case 1: dr[j + 1] = Distance_Fomula.X2(l1, l2).ToString(); break;

                        case 2: dr[j + 1] = Distance_Fomula.Dxy(l1, l2).ToString(); break;

                        default: break;
                        }
                    }
                    else
                    {
                        dr[j + 1] = 9999.ToString();//9999表示剖面缺失
                    }
                }
                Matrix.Rows.Add(dr);
            }
            return(true);
        }