k中心点法的聚类数据挖掘算法的C实现

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

alldata[(int)centerList[i]]);
//} ///////////////////////// for (int i = 0; i < pointClusterList; i++) { oRandom = random.Next(alldata.Count); if (PowerUtil.countEM(alldata, centerList, pointClusterList, oRandom, i))
rayList)(newPointClusterList[minCenter]); cluster.Add(i); }
////////////////////////////// //开始算 EM for (int i = 0; i < pointClusterList; i++) { cluster = (ArrayList)pointClusterList[i]; for (int j = 0; j < cluster; j++)
} } } return (powerA + powerB) / 2; } public static bool countEM(ArrayList alldata, ArrayList centerList, ArrayList pointClusterList,int oRandom,int position)
alldata[(int)newCenterList[i]]); }
} double s=randPower-sumPower; if (s < 0) { return true; } else { return false; }
} }
#region IDataWorker Members public void work() { throw new Exception("The method or operation is not implemented."); } #endregion private int k = 10; public int K { get { return k; } set { k = value; } } private ArrayList centerList = new ArrayList(); private ArrayList pointClusterList = new ArrayList(); private ArrayList cluster = new ArrayList(); private bool isChanged = false; private int minCenter = 0; private double minPower = 0; private double tempPower = 1; private double sumPower = 0; private double randPower = 0; private int oRandom = 0; private void genCluster(ArrayList alldata) {
double powerA=1.0; double powerB=1.0;
double power=0; int lengthA = a.Count; int lengthB = b.Count;
for(int i=0;i<a.Count;i++){ for(int j=0;j<b.Count;j++){ if (((string)a[i]).Equals((string)b[i]) && !((string)a[i]).Equals("")) { powerA = powerA - 1 / lengthA; } else { if(((string)a[i]).Equals("")){ lengthA--; } } } } for(int i=0;i<b.Count;i++){ for(int j=0;j<a.Count;j++){ if (((string)b[i]).Equals((string)a[i]) && !((string)a[i]).Equals("")) { powerB = powerB - 1 / lengthB; } else { if (((string)b[i]).Equals("")) { lengthB--; }
centerList.Clear(); //初始化 clusterList Random random = new Random(); for (int i = 0; i < k; i++) { centerList.Add(random.Next(alldata.Count)); pointClusterList.Add(new ArrayList()); } do { isChanged = false; /////////////////////////////指派每个剩余的对象给离它最近的中心点所代表的簇 for (int i = 0; i < alldata.Count; i++) { for (int j = 0; j < centerList.Count; j++) { tempPower = PowerUtil.countPower(alldata[i], alldata[(int)centerList[j]]); if (tempPower < minPower) { minCenter = j; minPower = tempPower; } } cluster = (ArrayList)(pointClusterList[minCenter]); cluster.Add(i); } /////////////////////////////////////////////////// ////////////////////针对每个簇提出一个随机的非中心点对象 //for (int i = 0; i < pointClusterList; i++) { // // // // // alldata(oRandom)); // // // // // // } } if (randPower < sumPower) { centerList[i] = oRandom; isChanged = true; cluster = (ArrayList)pointClusterList[i]; oRandom = random.Next(alldata.Count); for (int j = 0; j < cluster; j++) { sumPower randPower += += PowerUtil.countPower(alldata((int)(cluster[j])), PowerUtil.countPower(alldata((int)(cluster[j])),
{ wk.baidu.comumPower += PowerUtil.countPower(alldata((int)(cluster[j])), alldata[(int)centerList[i]]); }
} for (int i = 0; i < pointClusterList; i++) { cluster = (ArrayList)newPointClusterList[i]; for (int j = 0; j < cluster; j++) { randPower += PowerUtil.countPower(alldata((int)(cluster[j])),
{ centerList[i] = oRandom; isChanged = true; break;//? } } ///////////////////////////
///////////////////////////////// } while (!isChanged); } } using System; using System.Collections.Generic; using System.Text; using System.Collections; class PowerUtil { public static double countPower(ArrayList a,ArrayList b) {
{ int minCenter = 0; double minPower = 0; double tempPower = 1; double sumPower = 0; double randPower = 0; ArrayList cluster = new ArrayList(); ArrayList newCenterList = centerList.Clone(); newCenterList[position] = oRandom; ArrayList newPointClusterList = new ArrayList(); for (int i = 0; i < pointClusterList.Count; i++) { newPointClusterList.Add(new ArrayList()); } for (int i = 0; i < alldata.Count; i++) { for (int j = 0; j < centerList.Count; j++) { tempPower = PowerUtil.countPower(alldata[i], alldata[(int)newCenterList[j]]); if (tempPower < minPower) { minCenter = j; minPower = tempPower; } } cluster = (Ar
k-中心点法的聚类数据挖掘算法的 C#实现
?using System; using System.Collections.Generic; using System.Text; using System.Collections; using System.Data.Odbc; class ClusterGenerator : IDataWorker {
相关文档
最新文档