MATLAB实例:为匹配真实标签,对训练得到的标签进行调整
作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/
1. MATLAB程序
munkres.m
label_map.m
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
2. 结果
>> 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
注意:label_map()函数中输入参数“label”与“gnd”不能搞反,它是有顺序的。第一个参数代表自己训练得到的标签,第二个参数代表真实标签。
3. 参考文献
[1] Hua J, Li C. Distributed variational Bayesian algorithms over sensor networks[J]. IEEE Transactions on Signal Processing, 2015, 64(3): 783-798.
[2] Junhao Hua. Distributed Variational Bayesian Algorithms. Github, 2017.