如何根据输入值及其概率来计算最可能的输出?

时间:2018-11-10 20:04:49

标签: javascript algorithm math

我有一组具有适当的真实性概率的值。 我需要根据所有可用的输入值找到最可能的值。 注意:概率是主观的,并且可能会冲突-但是它们代表最终输出的真实性。

例如这样的数据集。

data = [
  {value: 1, probability: 1},
  {value: 1, probability: 0.5}
];
// i would expect to output 1, because all input agree on the value and 1 is certain in its value.
data = [
  {value: 1, probability: 1},
  {value: 0.5, probability: 1}
];
// Id expect the value to be half way between 1 and 0.5. Both values are equally likely - so final output is in between the 2.
data = [
  {value: 1, probability: 1},
  {value: 0.5, probability: 0.1}
];
// Id expect the value to be almost 1 but not quite.
data = [
  {value: 1, probability: 1},
  {value: 1, probability: 0.1},
  {value: 0.1, probability: 1},
  {value: 0, probability: 0.5},
  {value: 0, probability: 0.9},
  ... thousands of more values here ...
  quickly gets complicated and cpu intensive
];

1 个答案:

答案 0 :(得分:0)

好像您正在寻找weighted average。将每个值乘以其概率,计算乘积之和,然后除以概率之和。

First example:  (1.0*1.0 + 1.0*0.5) / (1.0+0.5) = 1.5/1.5  = 1.00 
Second example: (1.0*1.0 + 0.5*1.0) / (1.0+1.0) = 1.5/2.0  = 0.75   
Third example:  (1.0*1.0 + 0.5*0.1) / (1.0+0.1) = 1.05/1.1 = 0.95