Efficient multiclass weighted majority voting implementation in MATLAB

落花浮王杯 提交于 2019-11-30 07:36:09
w=[7 2 6];

votes = ['A' 'B' 'B'
         'C' 'A' 'A'
         'D' 'B' 'A'
         'A' 'A' 'C'];

options = ['A', 'B', 'C', 'D']';
%'//Make a cube of the options that is number of options by m by n
OPTIONS = repmat(options, [1, size(w, 2), size(votes, 1)]);

%//Compare the votes (streched to make surface) against a uniforma surface of each option
B = bsxfun(@eq, permute(votes, [3 2 1]) ,OPTIONS);

%//Find a weighted sum
W = squeeze(sum(bsxfun(@times, repmat(w, size(options, 1), 1), B), 2))'

%'//Find the options with the highest weighted sum
[xx, i] = max(W, [], 2);
options(i)

result:

B
A
D
A
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!