为什么平均值与原始权重相差不大?

Why are the mean values not much closer to the original weightings?

我运行下面的程序和一个典型的控制台输出如下

Mean percentage points for weighting 0 is: 57.935590153643616
Mean percentage points for weighting 1 is: 42.06440984635654

为什么这些打印的意思与 60 和 40 相差不大?

public static void main(String[] args) {
    Random rand = new Random();

    int numCycles = 5000;

    double[] weightings = {60.0, 40.0};
    double[] weightedRandoms = new double[weightings.length];
    double[] totPercentagePoints = {0.0, 0.0};

    for (int j = 0; j < numCycles; j++) {

        for (int k = 0; k < weightings.length; k++) {
            weightedRandoms[k] = (rand.nextInt(10) + 1) * weightings[k]; // +1 to the random integer to ensure that the weighting is not multiplied by 0
        }

        for (int k = 0; k < weightings.length; k++) {
            totPercentagePoints[k] += weightedRandoms[k] / DoubleStream.of(weightedRandoms).sum() * 100;
        }
    }

    for (int i = 0; i < weightings.length; i++) {
        System.out.println("Mean percentage points for weighting " + i + " is: " + totPercentagePoints[i] / numCycles);
    }
}

您正在估计 100*E(X/(X+Y)]100*E(Y/(X+Y)],其中 X = 60*U(1,10)Y = 40*U(1,10)(其中 U(1,10) 是 1,..,10 上的离散均匀分布).由于只有 10*10 = 100 种可能的方式来生成两个这样的统一变量,您可以计算每个这样的对的表达式,然后直接计算这些期望。在 Python 中定义:

def f(x,y): return 60*x/(60*x + 40*y)

然后:

>>> sum(f(x,y) for x in range(1,11) for y in range(1,11))
58.36068355253924

请注意,您乘以的 100 恰好抵消了计算期望值所需的因子 1/100。

类似地,如果你定义:

def g(x,y): return 40*y/(60*x + 40*y)

然后:

>>> sum(g(x,y) for x in range(1,11) for y in range(1,11))
41.639316447460756

这些确实与您所观察到的相吻合。