Recursive computation of a weighted mean

40 Views Asked by At

Background

Let $u=[u_1,\dots,u_N]'$ be a generic vector, its mean value is defined as $$ \bar{u}_N \triangleq \frac{1}{N}\sum_{i=1}^N u_i $$ in few simple steps one can prove the following recursion \begin{equation} \begin{aligned} \bar{u}_k &= \left(1-\frac{1}{k}\right)\bar{u}_{k-1}+\frac{1}{k}u_k & k=1,\dots,N\\ \bar{u}_0 &\triangleq 0 \end{aligned} \qquad(*) \end{equation} less trivially, for the more general weighted mean $$ \bar{u}_N^\lambda \triangleq \frac{1}{N}\sum_{i=1}^N \lambda^{N-i}u_i $$ where $\lambda\in\mathbb{R}$ is a given parameter, holds the recursion $$ \begin{aligned} \bar{u}_k^\lambda &= \lambda\,\left(1-\frac{1}{k}\right)\bar{u}_{k-1}^\lambda+\frac{1}{k}u_k & k=1,\dots,N\\ \bar{u}_0^\lambda &\triangleq 0 \end{aligned} $$ to see why, note that $$ \begin{aligned} \bar{u}_{N}^\lambda &= \frac{1}{N}\left(\sum_{i=1}^{N-1} \lambda^{N-i} u_i+u_N\right) =\frac{1}{N}\left(\lambda\sum_{i=1}^{N-1} \lambda^{(N-1)-i} u_i+u_N\right)\\ &=\frac{1}{N}\left(\lambda(N-1)\frac{1}{N-1} \sum_{i=1}^{N-1} \lambda^{(N-1)-i} u_i+u_N\right)\\ &=\frac{1}{N}\left(\lambda(N-1) \bar{u}_{N-1}^\lambda +u_N\right)=\lambda \left(1-\frac{1}{N}\right)\bar{u}_{N-1}^\lambda + \frac{1}{N} u_N \end{aligned} $$

Questions

I'm wondering if it possible to further generalize the previous result to the general case involving the generic weighted mean $$ \bar{u}_N^w \triangleq \sum_{i=1}^N w_i u_i $$ where the weights are normalized, i.e. $\sum_{i=1}^N w_i = 1$ and $w_i\geq 0$. More precisely, I'm wondering if it is possible to find a recursion of the type $$ \bar{u}_k^w =f(\bar{u}_{k-1}^w, u_k) $$ If this is not possible in general, I would like to know if, at least, it is possible in the special case where the weights are defined as follows $$ w_i \triangleq \begin{cases} \frac{1}{M} & \text{if } i > N-M \\ 0 & \text{otherwise} \end{cases} \qquad i=1,\dots,N $$ with $M$ being a given integer such that $1\leq M\leq N$. Note that for $M\triangleq N$ we have the first recursion $(*)$, while for $M \triangleq 1$ we have $$ \bar{u}_k^w = u_k \qquad k=1,\dots,N\\ $$

1

There are 1 best solutions below

0
On BEST ANSWER

Here my solution. Firstly, denote the unnormalized weights as $\tilde{w}_i \geq 0$, so that the normalized weights are given by \begin{equation*} w_i \triangleq \frac{\tilde{w}_i}{W_N} \qquad W_N\triangleq \sum_{i=1}^N \tilde{w}_i \end{equation*} then, the weighted mean $\bar{u}_n^w$ is given by the following couple of recursions \begin{equation*}\begin{aligned} \bar{u}_k^w &= \left(1-\frac{\tilde{w}_k}{W_k}\right) \bar{u}_{k-1}^w+\frac{\tilde{w}_k}{W_k} u_i\\ \bar{u}_0^w &=0 \end{aligned} \qquad \begin{aligned} W_k &= W_{k-1} + \tilde{w}_k \\ W_0 &= 0 \end{aligned} \end{equation*} Note that, as expected, in the uniform case $\tilde{w}_i = 1$ we get the back $(*)$. The recursion for the normalizer $W_k$ is trivial, while the recursion for the mean is given by the following facts \begin{equation*} \begin{aligned} \bar{u}_N^w &= \sum_{i=1}^{N} \frac{\tilde{w}_i}{W_N} u_i =\sum_{i=1}^{N-1} \frac{\tilde{w}_i}{W_N} u_i +\frac{\tilde{w}_N}{W_N} u_N\\ &=\frac{W_{N-1}}{W_N} \underbrace{\sum_{i=1}^{N-1} \frac{\tilde{w}_i}{W_{N-1}} u_i}_{=\bar{u}_{N-1}^w} +\frac{\tilde{w}_N}{W_N} u_N \\ &=\frac{W_{N}-\tilde{w}_N}{W_N} \bar{u}_{N-1}^w +\frac{\tilde{w}_N}{W_N} u_N \\ &=\left(1-\frac{\tilde{w}_N}{W_N}\right) \bar{u}_{N-1}^w +\frac{\tilde{w}_N}{W_N} u_N \end{aligned} \end{equation*}