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
Output: The output should be in the interval [minWeight, 1.0].
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:
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
Exponential, logarithmic or sigmoid functions...
Rescaling (min-max normalization) also satisfies a few of those properties:
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?
The problem can be simplified by introducing new axes, t'
and w'
, as illustrated 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
.