日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[code] em

發布時間:2025/3/21 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [code] em 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

EM_init 中調用多次kmeans, 取得其中最佳的聚類結果, 并賦值:

??? m_num_clusters = bestK.numberOfClusters();
??? m_weights = new double[inst.numInstances()][m_num_clusters];
??? m_model = new DiscreteEstimator[m_num_clusters][m_num_attribs];
??? m_modelNormal = new double[m_num_clusters][m_num_attribs][3];
??? m_priors = new double[m_num_clusters];

并得到最佳kmeans聚類的m_num_clusters個質心, 利用最佳kmeans的聚類結果初始化

1) 對離散屬性使用m_model[numInstance][numCluster];

2) 對數值屬性使用m_modelNormal[numInstance][numCluster][3], 其中第3維的 [0]表示均值,[1]表示方差, [2]表示該樣本該屬性的權重【權重默認都是1】

3) m_priors[numCluster] 保存了根據最佳kmeans結果得到的每個cluster的先驗概率?

4) m_weights[numInstance][numCluster] 未賦值, 都是初值0; 保存的是每個樣本屬于每個類的權重

?

然后迭代EM。

E?step:

?

double loglk = 0.0, sOW = 0.0;for (int l = 0; l < inst.numInstances(); l++) {Instance in = inst.instance(l);//in.weight始終為1, 樣本權重//sOW 相當于就是樣本個數//logDensityForInstance計算指定樣本in的概率密度的logloglk += in.weight() * logDensityForInstance(in); sOW += in.weight();//然后修正該樣本屬于每個類的權重//double m_weights[numInstance][numCluster]m_weights[l] = distributionForInstance(in);}// reestimate priors// 調整m_priorsestimate_priors(inst);return loglk / sOW;

?

?

E step:

logDensityForInstance ->logJointDensitiesForInstance->logDensityPerClusterForInstance

?

logDensityPerClusterForInstance計算每個樣本屬于每個類的weight; 其中會用到m_model[normal]變量

logJointDensitiesForInstance 計算每個樣本的聯合密度的log:

//weights的長度就是cluster的個數double[] weights = logDensityPerClusterForInstance(inst);//這里僅僅是一個getter操作double[] priors = clusterPriors();for (int i = 0; i < weights.length; i++) {if (priors[i] > 0) {weights[i] += Math.log(priors[i]);}}return weights;

?

logDensityForInstance? 計算給定樣本的密度。。?

double[] a = logJointDensitiesForInstance(instance);double max = a[Utils.maxIndex(a)];double sum = 0.0;for(int i = 0; i < a.length; i++) {sum += Math.exp(a[i] - max);}return max + Math.log(sum);

?

?

?使用 logJointDensitiesForInstance 重新計算m_weights

m_priors[ci] = sigma(instance.m_weights[ci]); 然后對m_priors正規化

?

?

?

M step:

根據m_weights 重新計算m_model與m_modelNormal

?

當E step的兩次返回值之差小于m_minStdDev時退出。E step的返回值肯定比上一次返回值要大(EM 算法決定的)?

總結

以上是生活随笔為你收集整理的[code] em的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。