//weight+threshold函数---- public void beginfileWT() { InDatasouce F = new DataIO(); List <string> inputlist = new List <string>(); inputlist = F.inputdata(inputfilepath); List <double> ax = new List <double>(); List <double> ay = new List <double>(); // ------------------------------------------------------------------------------------获得初始数据 #region // MessageBox.Show("开始读入数据"); for (int i = 0; i < inputlist.Count; i++)//获得初始数据 { string[] inputa = inputlist[i].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); StringBuilder s = new StringBuilder(); System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); int intAsciiCodea = (int)asciiEncoding.GetBytes(inputa[1].ToString())[0]; s.Append(intAsciiCodea.ToString()); s.Append("."); s.Append(inputa[0].ToString()); s.Append("("); s.Append(System.Convert.ToDouble(inputa[2])); s.Append(","); s.Append(System.Convert.ToDouble(inputa[3])); s.Append(")"); begindataList.Add(s.ToString()); ax.Add(System.Convert.ToDouble(inputa[2])); ay.Add(System.Convert.ToDouble(inputa[3])); } MessageBox.Show("数据读取完毕,进入物化阶段"); //字典序排序 //-----------------------------------------------------------------------------------------全局变量赋值 begindataList.Sort();//begindataList 放的是有序的特征实例及其位置,TypeCountList放每个特征的个数,也是有序的 begindataList.Insert(0, "begin"); int k = 1; int s3no = 1; begindataList.Add("over");//begindataList有一个over结尾,避免无法将其中的最后一个特征加不进TypeCountList的情况 // s2.Add("0"); TypeCountList.Add(0); TypeInsList.Add(0); TypeInsList.Add(1); DataGrid dg = new DataGrid();//=========================================================datagrad对象 dg.instancelized(begindataList); for (int i = 1; i < begindataList.Count - 1; i++) { string[] a = begindataList[i].Split('.'); string[] b = begindataList[i + 1].Split('.'); if (!b[0].Equals(a[0])) { s3no++; TypeInsList.Add(s3no); //TypeInsList放的是实例对应的特征 如:[1]=1,[2]=1,[3]=2 说明实例1,2都是特征1的实例 实例3是特征2的实例 TypeCountList.Add(k); //TypeCountList放的是特征对应的个数 如:[0]=0,[1]=5,[2]=7说明特征1有5个实例,特征2有2个实例 两个数组差为特征的实例范围 k++; } else { TypeInsList.Add(s3no); k++; } } #endregion //--------------------------------------------------------------------------------------物化 int maxx = (int)ax.Max() / ((int)rand); //获得最大行数 int maxy = (int)ay.Max() / ((int)rand); //获得最大列数 StringBuilder[,] co = dg.Grid(maxx, maxy, (int)rand, dg.instancelized(begindataList)); //格化 //--------------------------------------------------------------------------------------建立实例邻居表 INs = dg.InstanceNeighbor(maxx, maxy, (int)rand, dg.Grid(maxx, maxy, (int)rand, dg.instancelized(begindataList)), dg.instancelized(begindataList)); //--------------------------------------------------------------------------------------产生模式 Prevalence classprevalence = new Prevalence(); Constraint_Weight classcons = new Constraint_Weight(); T2 = classcons.TwoSize(INs, prev, TypeCountList, TypeInsList, w, occ);//得到二阶模式 //================================================================输出头文件行1特征表行2min_prev //foreach (var item1 in T2) //{ // if (!item1.Key.Contains("extend")) // { // StringBuilder fs2string = new StringBuilder(); // string h1 = item1.Key; // string hpi = T2[h1][T2[h1].Count() - 1][0].ToString(); // string hoi = T2[h1][T2[h1].Count() - 1][1].ToString(); // string hwpo = T2[h1][T2[h1].Count() - 1][2].ToString(); // fs2string.Append(h1); // fs2string.Append("=PI:"); // fs2string.Append((double.Parse(hpi) / 100.00).ToString()); // fs2string.Append(" OI:"); // fs2string.Append((double.Parse(hoi) / 100.00).ToString()); // fs2string.Append(" Quality:"); // fs2string.Append((double.Parse(hwpo) / 100.00).ToString()); // printf11.Add(fs2string.ToString()); // } // else { } //} //=======================================================================================================输出二阶aaaaa if (!System.IO.File.Exists(outputname)) { FileStream files1 = new FileStream(outputname, FileMode.Create, FileAccess.Write);//创建写入文件 StreamWriter sw = new StreamWriter(files1); sw.WriteLine("min_prev=" + prev.ToString()); sw.WriteLine("d=" + rand.ToString()); sw.WriteLine("min_occ=" + occ.ToString()); sw.WriteLine("weight=" + w.ToString()); /*foreach (var item in printf11)//获得初始数据 * { * sw.WriteLine(item);//开始写入值 * }*/ sw.Close(); files1.Close(); } //======================================================================================================输出多阶 SortedList <int, string> listfn = new SortedList <int, string>(); List <SortedList <string, List <List <int> > > > fnn = new List <SortedList <string, List <List <int> > > >(); fnn.Add(T2); SortedList <string, List <List <int> > > T3 = new SortedList <string, List <List <int> > >(); //二阶模式表实例集 T3 = classcons.MoreSize(T2, INs, prev, TypeCountList, TypeInsList, w, occ); //得到k+1阶 SortedList <string, List <List <int> > > T4 = new SortedList <string, List <List <int> > >(); //二阶模式表实例集 T4 = classcons.MoreSize(T3, INs, prev, TypeCountList, TypeInsList, w, occ); //得到k+1阶 int o = 0; /* * * foreach (var item1 in T3) * { * if (!item1.Key.Contains("extend")) * { * StringBuilder fs2string = new StringBuilder(); * string h1 = item1.Key; * string hpi = T3[h1][T3[h1].Count() - 1][0].ToString(); * string hoi = T3[h1][T3[h1].Count() - 1][1].ToString(); * string hwpo = T3[h1][T3[h1].Count() - 1][2].ToString(); * fs2string.Append(h1); * fs2string.Append("=pi:"); * fs2string.Append((double.Parse(hpi) / 100.00).ToString()); * fs2string.Append(" oi:"); * fs2string.Append((double.Parse(hoi) / 100.00).ToString()); * fs2string.Append(" quality:"); * fs2string.Append((double.Parse(hwpo) / 100.00).ToString()); * //printf11.Add(fs2string.ToString()); * } * else { } * } * * SortedList<string, List<List<int>>> T4 = new SortedList<string, List<List<int>>>();//二阶模式表实例集 * T4 = classcons.MoreSize(T3, INs, prev, TypeCountList, TypeInsList, w, occ);//得到k+1阶 * int o = 0; * foreach (var item1 in T4) * { * if (!item1.Key.Contains("extend")) * { * StringBuilder fs2string = new StringBuilder(); * string h1 = item1.Key; * string hpi = T4[h1][T4[h1].Count() - 1][0].ToString(); * string hoi = T4[h1][T4[h1].Count() - 1][1].ToString(); * string hwpo = T4[h1][T4[h1].Count() - 1][2].ToString(); * fs2string.Append(h1); * fs2string.Append("=pi:"); * fs2string.Append((double.Parse(hpi) / 100.00).ToString()); * fs2string.Append(" oi:"); * fs2string.Append((double.Parse(hoi) / 100.00).ToString()); * fs2string.Append(" quality:"); * fs2string.Append((double.Parse(hwpo) / 100.00).ToString()); * //printf11.Add(fs2string.ToString()); * } * else { } * } * */ while (fnn[0].Count != 0) { SortedList <string, List <List <int> > > CNk = new SortedList <string, List <List <int> > >(); CNk = classcons.MoreSize(fnn[0], INs, prev, TypeCountList, TypeInsList, w, occ);//得到k+1阶 //if (fnn[0].Count == 0) { break; } fnn.Add(CNk); //按阶输出多阶 List <string> printfm = new List <string>(); //输出上一阶模式 #region foreach (var item1 in fnn[0].Take(fnn[0].Count - 1)) { //if (!item1.Key.Contains("extend")) //{ StringBuilder fsstring = new StringBuilder(); string h1 = item1.Key; string hpi = fnn[0][h1][fnn[0][h1].Count() - 1][0].ToString(); string hoi = fnn[0][h1][fnn[0][h1].Count() - 1][1].ToString(); string hwpo = fnn[0][h1][fnn[0][h1].Count() - 1][2].ToString(); fsstring.Append(h1); fsstring.Append("=PI:"); fsstring.Append((double.Parse(hpi) / 100.00).ToString()); fsstring.Append(" OI:"); fsstring.Append((double.Parse(hoi) / 100.00).ToString()); fsstring.Append(" Quality:"); fsstring.Append((double.Parse(hwpo) / 100.00).ToString()); printfm.Add(fsstring.ToString()); Console.WriteLine(fsstring); // } } FileStream files2 = new FileStream(outputname, FileMode.Append); StreamWriter sw2 = new StreamWriter(files2); foreach (var item in printfm) //获得初始数据 { sw2.WriteLine(item); //开始写入值 } sw2.Close(); #endregion fnn.RemoveAt(0); } }
//skyline函数----- public void beginfileSkyline() { InDatasouce F = new DataIO(); List <string> inputlist = new List <string>(); inputlist = F.inputdata(inputfilepath); List <double> ax = new List <double>(); List <double> ay = new List <double>(); // ------------------------------------------------------------------------------------获得初始数据 #region // MessageBox.Show("开始读入数据"); for (int i = 0; i < inputlist.Count; i++)//获得初始数据 { string[] inputa = inputlist[i].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); StringBuilder s = new StringBuilder(); System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); int intAsciiCodea = (int)asciiEncoding.GetBytes(inputa[1].ToString())[0]; s.Append(intAsciiCodea.ToString()); s.Append("."); s.Append(inputa[0].ToString()); s.Append("("); s.Append(System.Convert.ToDouble(inputa[2])); s.Append(","); s.Append(System.Convert.ToDouble(inputa[3])); s.Append(")"); begindataList.Add(s.ToString()); ax.Add(System.Convert.ToDouble(inputa[2])); ay.Add(System.Convert.ToDouble(inputa[3])); } MessageBox.Show("数据读取完毕,进入物化阶段"); //字典序排序 //-----------------------------------------------------------------------------------------全局变量赋值 begindataList.Sort();//begindataList 放的是有序的特征实例及其位置,TypeCountList放每个特征的个数,也是有序的 begindataList.Insert(0, "begin"); int k = 1; int s3no = 1; begindataList.Add("over");//begindataList有一个over结尾,避免无法将其中的最后一个特征加不进TypeCountList的情况 // s2.Add("0"); TypeCountList.Add(0); TypeInsList.Add(0); TypeInsList.Add(1); DataGrid dg = new DataGrid();//=========================================================datagrad对象 dg.instancelized(begindataList); for (int i = 1; i < begindataList.Count - 1; i++) { string[] a = begindataList[i].Split('.'); string[] b = begindataList[i + 1].Split('.'); if (!b[0].Equals(a[0])) { s3no++; TypeInsList.Add(s3no); //TypeInsList放的是实例对应的特征 如:[1]=1,[2]=1,[3]=2 说明实例1,2都是特征1的实例 实例3是特征2的实例 TypeCountList.Add(k); //TypeCountList放的是特征对应的个数 如:[0]=0,[1]=5,[2]=7说明特征1有5个实例,特征2有2个实例 两个数组差为特征的实例范围 k++; } else { TypeInsList.Add(s3no); k++; } } #endregion //--------------------------------------------------------------------------------------物化 int maxx = (int)ax.Max() / ((int)rand); //获得最大行数 int maxy = (int)ay.Max() / ((int)rand); //获得最大列数 StringBuilder[,] co = dg.Grid(maxx, maxy, (int)rand, dg.instancelized(begindataList)); //格化 //--------------------------------------------------------------------------------------建立实例邻居表 INs = dg.InstanceNeighbor(maxx, maxy, (int)rand, dg.Grid(maxx, maxy, (int)rand, dg.instancelized(begindataList)), dg.instancelized(begindataList)); //--------------------------------------------------------------------------------------产生模式 Prevalence classprevalence = new Prevalence(); T2 = classprevalence.TwoSize(INs, prev, TypeCountList, TypeInsList);//得到二阶模式 //================================================================输出头文件行1特征表行2min_prev foreach (var item1 in T2) { if (!item1.Key.Contains("extend")) { StringBuilder fs2string = new StringBuilder(); string h1 = item1.Key; string h2 = T2[h1][T2[h1].Count() - 1].First().ToString(); fs2string.Append(h1); for (int ii = 0; ii < T2[h1].Count; ii++) { fs2string.Append("("); foreach (var item11 in T2[h1][ii])//获得初始数据 { fs2string.Append(item11); fs2string.Append("-"); } //fs2string.Append(T2[h1][ii].Last()); fs2string.Append(")"); } fs2string.Append("="); fs2string.Append((double.Parse(h2) / 100.00).ToString()); printf11.Add(fs2string.ToString()); } else { } } //=======================================================================================================输出二阶aaaaa if (!System.IO.File.Exists(outputname)) { FileStream files1 = new FileStream(outputname, FileMode.Create, FileAccess.Write);//创建写入文件 StreamWriter sw = new StreamWriter(files1); sw.WriteLine("min_prev=" + prev.ToString()); sw.WriteLine("d=" + rand.ToString()); sw.WriteLine("min_occ=" + occ.ToString()); foreach (var item in printf11) //获得初始数据 { sw.WriteLine(item); //开始写入值 } sw.Close(); files1.Close(); } //======================================================================================================输出多阶 SortedList <string, List <List <int> > > CNk1 = new SortedList <string, List <List <int> > >(); CNk1 = classprevalence.MoreSize1(T2, INs, prev, TypeCountList, TypeInsList); //输出多阶 List <string> printfm = new List <string>(); foreach (var item1 in CNk1) { if (!item1.Key.Contains("extend")) { StringBuilder fsstring = new StringBuilder(); string h1 = item1.Key; string h2 = CNk1[h1][CNk1[h1].Count() - 1].First().ToString(); fsstring.Append(h1); for (int ii = 0; ii < CNk1[h1].Count - 1; ii++) { fsstring.Append("("); foreach (var item11 in CNk1[h1][ii])//获得初始数据 { fsstring.Append(item11); fsstring.Append("-"); } //fs2string.Append(T2[h1][ii].Last()); fsstring.Append(")"); } fsstring.Append("="); fsstring.Append((double.Parse(h2) / 100.00).ToString()); printfm.Add(fsstring.ToString()); FileStream files2 = new FileStream(outputname, FileMode.Append); StreamWriter sw2 = new StreamWriter(files2); foreach (var item in printfm) //获得初始数据 { sw2.WriteLine(item); //开始写入值 } sw2.Close(); } } }
public void beginfile() { InDatasouce F = new DataIO(); List <string> inputlist = new List <string>(); inputlist = F.inputdata(inputfilepath); List <double> ax = new List <double>(); List <double> ay = new List <double>(); // ------------------------------------------------------------------------------------获得初始数据 #region // MessageBox.Show("开始读入数据"); for (int i = 0; i < inputlist.Count; i++)//获得初始数据 { string[] inputa = inputlist[i].Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); // string s = inputa[1].ToString() + "." + inputa[0].ToString() + "(" + System.Convert.ToDouble(inputa[2]) + "," + System.Convert.ToDouble(inputa[3]) + ")"; StringBuilder s = new StringBuilder(); System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); int intAsciiCodea = (int)asciiEncoding.GetBytes(inputa[1].ToString())[0]; s.Append(intAsciiCodea.ToString()); s.Append("."); s.Append(inputa[0].ToString()); s.Append("("); s.Append(System.Convert.ToDouble(inputa[2])); s.Append(","); s.Append(System.Convert.ToDouble(inputa[3])); begindataList.Add(s.ToString()); ax.Add(System.Convert.ToDouble(inputa[2])); ay.Add(System.Convert.ToDouble(inputa[3])); } MessageBox.Show("数据读取完毕,进入物化阶段"); //字典序排序 //-----------------------------------------------------------------------------------------全局变量赋值 begindataList.Sort();//begindataList 放的是有序的特征实例及其位置,TypeCountList放每个特征的个数,也是有序的 begindataList.Insert(0, "begin"); int k = 1; int s3no = 1; begindataList.Add("over");//begindataList有一个over结尾,避免无法将其中的最后一个特征加不进TypeCountList的情况 // s2.Add("0"); TypeCountList.Add(0); TypeInsList.Add(0); TypeInsList.Add(1); DataGrid dg = new DataGrid();//=========================================================datagrad对象 dg.instancelized(begindataList); for (int i = 1; i < begindataList.Count - 1; i++) { string[] a = begindataList[i].Split('.'); string[] b = begindataList[i + 1].Split('.'); if (!b[0].Equals(a[0])) { s3no++; TypeInsList.Add(s3no); //TypeInsList放的是实例对应的特征 如:[1]=1,[2]=1,[3]=2 说明实例1,2都是特征1的实例 实例3是特征2的实例 TypeCountList.Add(k); //TypeCountList放的是特征对应的个数 如:[0]=0,[1]=5,[2]=7说明特征1有5个实例,特征2有2个实例 两个数组差为特征的实例范围 k++; } else { TypeInsList.Add(s3no); k++; } } #endregion //--------------------------------------------------------------------------------------物化 int maxx = (int)ax.Max() / ((int)rand); //获得最大行数 int maxy = (int)ay.Max() / ((int)rand); //获得最大列数 //dg.Grid(maxx, maxy, (int)rand, dg.instancelized(begindataList));//格化 //--------------------------------------------------------------------------------------建立实例邻居表 INs = dg.InstanceNeighbor(maxx, maxy, (int)rand, dg.Grid(maxx, maxy, (int)rand, dg.instancelized(begindataList)), dg.instancelized(begindataList)); //--------------------------------------------------------------------------------------产生模式 }