% Initialize centroids centroids = kMeansInitCentroids(X, K); for iter = 1:iterations % Cluster assignment step: Assign each data point to the % closest centroid. idx(i) corresponds to cˆ(i), the index % of the centroid assigned to example i idx = findClosestCentroids(X, centroids); % Move centroid step: Compute means based on centroid % assignments centroids = computeMeans(X, idx, K); end
function centroids = computeCentroids(X, idx, K)% Useful variables [m n] = size(X);% You need to return the following variables correctly. centroids = zeros(K, n);for i = 1:Kindex = find(idx==i);for j = 1:size(index,1)newXi(j,:) = X(index(j),:);endcentroids(i, :) = mean(newXi,1);newXi = zeros(1,n); end end
运行程序有:
Centroids computed after initial finding of closest centroids: 2.428301 3.157924 5.813503 2.633656 7.119387 3.616684 the centroids should be[ 2.428301 3.157924 ][ 5.813503 2.633656 ][ 7.119387 3.616684 ]
本文对比了杜甫《喜晴》的两种英文翻译版本:a. Pleased with Sunny Weather 和 b. Rejoicing in Clearing Weather。a 版由 alexcwlin 翻译并经 Adam Lam 编辑,b 版则由哈佛大学的宇文所安教授 (Prof. Stephen Owen) 翻译。 ...
[详细]