Search code examples
functionmathtime-seriesscalingweighted

Scaling / parametric weighting function for time series analysis


I have some time series data and I would like to weight my data, so that recent observations are weighted higher than older observations. Therefor I'm looking for a parametric weighting function, which satisfy a few properties. It should look like this:

weighting(time, minTime, maxTime, minWeight, slope) = ?

whereby

  • time is obviously the time of the observation to weight and should be between minTime and maxTime (time >= minTime, time <= maxTime),
  • minTime is the oldest observation time,
  • maxTime is the newest observation time,
  • minWeight is the minimum weight to return (and also the intercept with the weight axis; interval: [0,1]),
  • slope adjusts the shape of the curve.

Output: The output should be in the interval [minWeight, 1.0].

<image2>

Does anyone have an idea, how this weighting function might look like, or some hints or code examples / pseudocode?


Some functions I have looked at:

  • A root or power functions like

f(x) = x^(n/m), if n < m -- root function

f(x) = x^(n/m), if n = m -- linear function

f(x) = x^(n/m), if n > m -- power function

enter image description here

rescaling(time, minTime, maxTime) = (time - minTime) / (maxTime - minTime)

This weighting function provides a weight in the interval [0, 1]. But the curve shape is always linear (and cannot be adjusted) and the minimum value is always 0 (I also would like to adjust that).

I guess I'm too stupid to get all the parts together. Can someone help?


Solution

  • The problem can be simplified by introducing new axes, t' and w', as illustrated here

    enter image description here

    With these coordinates the equations are simple:

    w'^2 = t'       - high-score
    w' = t'         - normal-score
    w' = t'^2       - low-score
    

    so, it only remains to replace w' with: (w - w0)/(1 - w0) and t' with: (t - t0)/(t1 - t0) to get:

    (w - w0)^2/(1 - w0)^2 = (t - t0)/(t1 - t0)      - high-score
    (w - w0)/(1 - w0) = (t - t0)/(t1 - t0)          - normal-score
    (w - w0)/(1 - w0) = (t - t0)^2 / (t1 - t0)^2    - low-score
    

    Now we have to solve for w:

    w = w0 + (1 - w0)sqrt((t - t0)/(t1 - t0))       - high-slope
    w = w0 + (1 - w0)(t - t0)/(t1 - t0)             - normal-slope
    w = w0 + (1 - w0)(t - t0)^2 / (t1 - t0)^2       - low-slope
    

    The very same technique can be used if you choose another functions instead of sqrt() and ^2.