I wrote:
>  I need to "undo" an average.

Oleg wrote:
> How would you know what to }: each time?

This is the essence of my question.  

If this were just a straight, unweighted moving average, we could just pretend  
L  was  N  copies of the precomputed average, and drop off the first of those.  
For example, the moving average you posted last week depends on knowing  L  :

           4 (+/%#)\ ?.~ 10
        5 3.5 1.75 2.25 3.25 5 5.75
   
But it can be reforumulated so that it doesn't.  This version only needs 
previous average and the new value, and arrives at the same answer:

           prevAvg =: (+/%#)@:}:   NB.  Pre-computed average
           newVal  =: {:           NB.  Latest value

           4  (# %~ newVal + prevAvg * <:@:#)\ ?.~ 10
        5 3.5 1.75 2.25 3.25 5 5.75


This would be exactly what I need, if not for that weighting wrinkle.  That's 
throwing me.  How could we extend the reformulation above (depending on prevAvg 
and newVal) to handle the fact that the most recent value is weighted by a 
known factor?

-Dan

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

Reply via email to