TSDecay function

The TSDecay function computes a decay function over its arguments.

Syntax

TSDecay(current_value smallfloat, 
        initial_value  smallfloat, 
        decay_factor   smallfloat) 
returns smallfloat;

TSDecay(current_value double precision, 
        initial_value  double precision, 
        decay_factor   double precision) 
returns double precision;
current_value
The current datum (vj in the sum shown next).
initial_value
The initial value (initial in the sum shown next).
decay_factor
The decay factor (decay in the sum shown next).

Description

All three arguments must be of the same type.

The function maintains a sum of all the arguments it has been called with so far. Every time it is called, the sum is multiplied by the supplied decay factor. Given a decay factor between 0 and 1, this causes the importance of older arguments to fall off over time. The first time that TSDecay is called, it includes the supplied initial value in the running sum. The actual function that TSDecay computes is:
                  i
((decayi)initial)+∑((vj)decayi-j)
                 j=i

In this computation, i is the number of times the function has been called so far, and vj is the value it was called with in its jth invocation.

This function is useful only when used within the Apply function.

Returns

The result of the decay function.

Example

The following example computes the decay:
create function ESA18(a smallfloat) returns smallfloat;
return (.18 * a) + TSDecay(.18 * a, a, .82);
end function;