在MATLAB中高效的多类加权多数投票表决实现 [英] Efficient multiclass weighted majority voting implementation in MATLAB

查看:710
本文介绍了在MATLAB中高效的多类加权多数投票表决实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天来,我一直在想如何有效地在matlab中实施m位专家的加权多数投票.这是我想要的例子.假设我们有3个具有权重向量的专家

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 with weights vector

w=[7 2 6]

假设他们在选项A/B/C/D上进行了n次投票,因此,例如,我们得到以下n x m投票矩阵,其中各列是每位专家的投票.

Suppose they are voting n times on the options A/B/C/D, so we for example get the following n x m voting matrix, where the columns are votes of each expert.

A B B
C A A
D B A
A A C

现在,我想为每一行找到加权多数票.我们通过添加对每个选项投票的专家的权重并选择最大权重来进行计算.例如,在第一行中,选项A的累积权重为7(专家1的投票),而选项B的累积权重为8(专家2和3的投票),因此最终投票为B.以下累积权重矩阵和最终投票:

Now I'd like to find weighted majority vote for each row. We calculate it by adding the weights of experts which voted for each option, and selecting the maximal weight. For example, in the first row, the option A has cumulative weight of 7 (vote of expert 1) and B has cumulative weight of 8 (votes of expert 2 and 3), and hence the final vote is B. So we get the following cumulative weights matrix and final votes:

A B C D
- - - -
7 8 0 0 -> B
8 0 7 0 -> A
6 2 0 7 -> D
9 0 6 0 -> A

现在,使用for循环对行数n的实现或多或少是简单的.我现在正在寻找解决方案,它不需要这个可能很长的循环,而是使用矢量算法.我有一些想法,但是每个想法都遇到了一些问题,因此现在不再赘述.如果以前有过类似情况,请分享您的解决方案.

Now, the implementation of this using for loops over number of rows n is more or less straightforward. I am now looking for solution, which doesn't require this potentially lengthy loop and instead uses vector arithmetic. I have had a few ideas, but ran into some problems with each of them, so will not mention them now. If anyone have had similar situation before, please share your solutions.

谢谢.

推荐答案

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)

结果:

B
A
D
A

这篇关于在MATLAB中高效的多类加权多数投票表决实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆