Files
2026-07-13 13:30:25 +08:00

11 lines
365 B
Matlab
Executable File

function [label, energy] = kmeansPred(mu, X)
% Prediction for kmeans clusterng
% Input:
% model: dx k cluster center matrix
% X: d x n testing data
% Output:
% label: 1 x n cluster label
% energy: optimization target value
% Written by Mo Chen (sth4nth@gmail.com).
[val,label] = min(dot(X,X,1)+dot(mu,mu,1)'-2*mu'*X,[],1); % assign labels
energy = sum(val);