intprb_muvblockupdate — Update the mean and the variance of x, given the mean and the value of disjoint parts of x.
[ mu , v ] = intprb_muvblockupdate ( na , nb , mua , mub , va , vb )
a 1 x 1 matrix of floating point integers, the number of values in xa
a 1 x 1 matrix of floating point integers, the number of values in xb
a 1 x 1 matrix of doubles, the mean of the matrix xa
a 1 x 1 matrix of doubles, the mean of the matrix xb
a 1 x 1 matrix of doubles, the variance of the matrix xa, as the sum of squares divided by with na-1
a 1 x 1 matrix of doubles, the variance of the matrix xb, as the sum of squares divided by with nb-1
a 1 x 1 matrix of doubles, the mean of x, the union of xa and xb
a 1 x 1 matrix of doubles, the sample variance, as a sum of squares divided by with n-1
The algorithm uses an updating scheme of the mean and the variance in order to update them block by block. It uses a decomposition of the array x into the two arrays xa and xb, with their associated means mua and mub and their variances va and vb. The purpose of the computation is to show that the mean and the variance can be computed without accessing to the whole array x at once. The routine has no direct use, since the vectorization used in the built-in variance function is faster. But it can be used as a template for other uses.
// Compare our algorithm with the functions (mean,variance) na = 10 nb = 10 xa = (1 : na)' xb = (11 : 20)' mua = mean(xa) mub = mean(xb) va = variance(xa) vb = variance(xb) [ mu , v ] = intprb_muvblockupdate ( na , nb , mua , mub , va , vb ) x = [xa' xb']' disp ( [ mean(x) mu ] ) disp ( [ variance(x) v ] )