[英]generate probabilities from a series of numbers
如果存在这样的数字系列:11.5、6.7、3.2和5.11
一个人如何将这些数字转换为概率,以使结果的总和为1?
谢谢。
如果数字系列还包含负数:-1.2,-100.34、3.67和2.1,该怎么办?
是的,它们是与一个实例的4个可能的类别关联的权重。
好。 这是我的解决方案。 如有任何改进,请随时提出建议。
1)通过方法将数字范围在1到任意n(我选择100)之间。
2)使用答案中列出的解决方案。
在步骤1)中将下限选择为1的原因是在应用范围转换公式后不放松最小值。
解决的例子:
Say there 2 instances that can take on 2 possible class values with weights as shown below.
Instance1: -11.0 -2.0
Instance2: 4.0 52.0
old_max = 52.0, old_min = -11.0, new_max = 100, and new_min = 1
After applying step1), the weights are now in range 1 to 100.
Instance1: 1 15.1
Instance2: 24.5 100
On applying step2), the following probabilities are obtained.
Instance1: 0.0708 0.937
Instance2: 0.19 0.803
您可以将每个数字除以总和:
double arr[] = {11.5, 6.7, 3.2, 5.11};
double total = 11.5 + 6.7 + 3.2 + 5.11;
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i] / total);
}
这是有效的,因为总和除以1。
加权总和?
x1= 11.5, x2 = 6.7, x3 = 3.2, x4= 5.11
sum = x1+x2+x3+x4
p(x1) = x1/sum
p(x4) = x4/sum
....
p(total) = p(x1) + p(x2) + p(x3) + p(x4) = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.