weighted_mean_variance

weighted_mean_variance(individual: ndarray, weights: ndarray | None) float[source]

Calculate the variance of a weighted mean of variables with given individual variances.

For independent random variables \(x_1, \ldots, x_n\) with individual variances \(\mathbb{V}[x_i]\) and arbitrary scalar weights \(w_1, \ldots, w_n\), the variance of the weighted mean is:

\[\mathbb{V}\left[\frac{\sum \limits_{i=1}^{n} w_i x_i}{\sum \limits_{j=1}^{n} w_j}\right] = \frac{\sum \limits_{i=1}^{n} w_i^2 \mathbb{V}\left[x_i\right]}{\left(\sum \limits_{j=1}^{n} w_j\right)^2}\]

The \(w_i^2\) term arises from the variance scaling property: \(\mathbb{V}[c \cdot X] = c^2 \cdot \mathbb{V}[X]\).

When \(w_i = \frac{1}{n}\) (uniform weights, used if no explicit weights are given), the weights are normalized such that \(\sum w_i = 1\).

Note

This implements scaling factor semantics: each variable is sampled once and scaled by its weight. This differs from repeat count semantics where weights would represent the number of independent samples, which would yield a linear (not quadratic) dependence on weights.

Parameters:
  • individual (ndarray) – the individual variables’ variances, \(\mathbb{V}[x_i]\)

  • weights (ndarray | None) – the individual variables’ scalar weights (not repeat counts)

Returns:

the variance of the weighted mean

Return type:

float