static List<int> Algorithm0(int kNumber, double pNumber) { List<int> chosedNum = new List<int>(); int k = kNumber;//特征数 double p = pNumber;//系数 for (int i = 0; i < k; i++) { if (chosedNum.Count == 0) { List<double> miList = new List<double>(); for (int j = 0; j < attCount; j++) { double IXiC = getMiC(j.ToString());// I(Xi;C) miList.Add(IXiC); } #region 找最大 int miBest = -1; double miBestValue = -100; for (int n = 0; n < attCount; n++) { if (miBestValue > miList[n]) continue; else { miBest = n; miBestValue = miList[n]; } } // Console.WriteLine(miBest.ToString()); chosedNum.Add(miBest); #endregion } else { List<cmiValue> cmiList = new List<cmiValue>(); for (int j = 0; j < attCount; j++) { int vector = 1; foreach (int a in chosedNum) { if (j == a) vector = 0; } if (vector == 1) { double IXiC = getMiC(j.ToString());// I(Xi;C) double sum = 0; //sum(S) I(Xi;C|Xj)+I(Xi;C|Xj) foreach (int a in chosedNum) { sum += getCmiC(j.ToString(), a.ToString()) + getCmiC(a.ToString(), j.ToString()); } double Jcmi = IXiC + p * sum;//系数 cmiValue cv = new cmiValue(); cv.number = j; cv.value = Jcmi; cmiList.Add(cv); } } #region 找最大 int cmiBest = -1; double cmiBestValue = -100; for (int n = 0; n < cmiList.Count; n++) { if (cmiBestValue > cmiList[n].value) continue; else { cmiBest = cmiList[n].number; cmiBestValue = cmiList[n].value; } } //Console.WriteLine(cmiBest.ToString()); chosedNum.Add(cmiBest); #endregion } } return chosedNum; }
static List<int> Algorithm2(int kNumber, double pNumber) { List<int> chosedNum = new List<int>(); int k = kNumber;//特征数 double p = pNumber;//系数 for (int i = 0; i < k; i++) { if (chosedNum.Count == 0) { List<double> miList = new List<double>(); for (int j = 0; j < attCount; j++) { double IXiC = getMiC(j.ToString());// I(Xi;C) miList.Add(IXiC); } #region 找最大 int miBest = -1; double miBestValue = -100; for (int n = 0; n < attCount; n++) { if (miBestValue > miList[n]) continue; else { miBest = n; miBestValue = miList[n]; } } // Console.WriteLine(miBest.ToString()); chosedNum.Add(miBest); #endregion } else { List<cmiValue> gList = new List<cmiValue>(); for (int j = 0; j < attCount; j++) { int vector = 1; foreach (int a in chosedNum) { if (j == a) vector = 0; } if (vector == 1) { double IXiC = getMiC(j.ToString());// I(Xi;C) double sum = 0; //sum(S) I(Xi;C|Xj)+I(Xi;C|Xj) foreach (int a in chosedNum) { Distance d = getDistance(j.ToString(), a.ToString()); Distance dc = getDistanceC(d); sum += 1.0 / 2.0 * d.value - 1.0 / 4.0 * dc.value; } Console.WriteLine(IXiC.ToString()); Console.WriteLine(sum.ToString()); double gValue = 1 / 2 * IXiC + p * sum;//系数 cmiValue cv = new cmiValue(); cv.number = j; cv.value = gValue; gList.Add(cv); } } #region 找最大 int gBest = -1; double gBestValue = -100; for (int n = 0; n < gList.Count; n++) { if (gBestValue > gList[n].value) continue; else { gBest = gList[n].number; gBestValue = gList[n].value; } } // Console.WriteLine(gBest.ToString()); chosedNum.Add(gBest); #endregion } } return chosedNum; }