Efficient multiclass weighted majority voting implementation in MATLAB

前端 未结 1 1395
盖世英雄少女心
盖世英雄少女心 2020-12-30 16:29

For a few days I was wondering on how to efficiently implement weighted majority voting of m experts in matlab. Here is an example of what I want. Suppose we have 3 experts

相关标签:
1条回答
  • 2020-12-30 17: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
    
    0 讨论(0)
提交回复
热议问题