weightedMean

Computes the weighted arithmetic mean of the values using the given weights.

Each value is multiplied by its corresponding weight, the products are summed, and the result is divided by the total weight. Weights must be non-negative and their sum must be positive. The values and weights iterables must have the same number of elements. Uses compensated summation for both the weighted sum and the total weight.

Example:

listOf(1.0, 2.0, 3.0).weightedMean(listOf(3.0, 1.0, 1.0)) // 1.6

Return

the weighted arithmetic mean.

Parameters

weights

the weights corresponding to each value. Must be non-negative.


Computes the weighted arithmetic mean of the values using the given weights.

Each value is multiplied by its corresponding weight, the products are summed, and the result is divided by the total weight. Weights must be non-negative and their sum must be positive. The arrays must have the same size. Uses compensated summation.

Example:

doubleArrayOf(1.0, 2.0, 3.0).weightedMean(doubleArrayOf(3.0, 1.0, 1.0)) // 1.6

Return

the weighted arithmetic mean.

Parameters

weights

the weights corresponding to each value. Must be non-negative.