Should be shorter

>       movingAvg =: dyad define
>               (+/%#) (x*y) , }:L
>       )

I don't think it's possible to get rid of L.
How would you know what to }: each time?


--- Dan Bron <[EMAIL PROTECTED]> wrote:

> I need to "undo" an average.  The problem is I don't have the whole series of 
> data; I have only
> the initial average and, periodically, a new value to be averaged in.
> 
> So, let's say a user hands me a pre-computed average.  I want to take that 
> average, and whenever
> I get a new value of the series, I want to "expand" the precomputed average, 
> drop off its
> leading (oldest) value, append the new value, and redo the average.  Then I 
> would use this new
> average as my "precomputed" average.
> 
> One wrinkle is that the average is weighted.  In particular, the newest value 
> is always weighted
> by some user-specified factor (all other weights are 1).  The initial 
> user-provided precomputed
> average has already taken this into account for the first iteration, and my 
> code is responsible
> for taking it into account for any new values.
> 
> 
> Concretely, I would like to emulate this J verb:
> 
>       L         =:  ?.~10        NB.  Original list -- I won't have access to 
> this.
>       wmr       =:  3            NB. Weight Most Recent value by a factor of 3
>       
>       movingAvg =: dyad define
>               (+/%#) (x*y) , }:L
>       )
>       
>          wmr movingAvg 10
>       7
>          wmr movingAvg 5
>       5.8
>          wmr movingAvg 8
>       6.4
>          wmr movingAvg 9
>       7.2
> 
> 
> except that I do not have access to the original series of data  L  .  In my 
> scenario, my
> initial inputs would be  wmr  and  (+/%#) (wmr*{.L) , }.L   and, later, the 
> values  10 5 8 9 
> (spread out over time).   Ideally, I would like to avoid keeping any kind of 
> list (e.g., of the
> new values as they come in).
> 
> Is this possible?  




      
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total 
Access, No Cost.  
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to