做者:凱魯嘎吉 - 博客園 http://www.cnblogs.com/kailugaji/html
見:MATLAB實例:Munkres指派算法git
function [ new_label ] = label_map( label, gnd ) %爲匹配真實標籤,對標籤從新調整 K = length(unique(gnd)); cost_mat = zeros(K,K); for i=1:K idx = find(label==i); for j=1:K cost_mat(i,j) = length(find(gnd(idx)~=j)); end end [assignment,cost] = munkres(cost_mat); [assignedrows,dum]=find(assignment'); new_label = label; for i=1:K idx = find(label==i); new_label(idx) = assignedrows(i); end
>> label=[1 1 2 1 1 2 2 2 3 2 2 3 1 3 3 2 3]; >> gnd=[2 2 2 2 2 2 3 3 3 3 3 3 1 1 1 1 1 ]; >> [ new_label ] = label_map( label, gnd ) new_label = 2 2 3 2 2 3 3 3 1 3 3 1 2 1 1 3 1
[1] Hua J, Li C. Distributed variational Bayesian algorithms over sensor networks[J]. IEEE Transactions on Signal Processing, 2015, 64(3): 783-798.github
[2] Junhao Hua. Distributed Variational Bayesian Algorithms. Github, 2017.算法
[3] MATLAB實例:Munkres指派算法post