In J we often have both arguments arrays

When the shape of one is a prefix of the shape of the other, the following 
gives a weighted mean and two functions with consistent monadic and dyadic 
use
NObs    =: # : (+/ @([+((0&*)@])))
 Mean    =: (+/%#) : ((+/@([*]))%([NObs]))

In the general case there is often a kernel function to generate the 
weights.  In that case
constructing a conjunction to specify the changing weights for each point is 
worth the effort.   It is then easy to explore the effect of different 
weighting functions adn to change the points at which weights are evaluated.

----- Original Message ----- 
From: "Brian Schott" <[email protected]>
To: "Programming forum" <[email protected]>
Sent: Sunday, November 29, 2009 11:41 AM
Subject: Re: [Jprogramming] Moving averages of data


> Here are some ideas for weighted average (wa) and weighted moving average 
> (wma)
>
>   wa
> * %&(+/) [
>   wma
> [ wa"1 #...@[ ]\ ]
>   1 2 wa 10 20
> 16.6667
>   1 1 wa 10 20
> 15
>   1 2 1 wa 10 20 30
> 20
>   1 2 1 wma 10 20 30 40 50
> 20 30 40
>
> A  recent thread discussed EWMA's
> http://www.jsoftware.com/pipermail/programming/2009-November/016898.html
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm 


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to