Skip to content
DeepForgeby svx
All problems
MediumTime Seriests-301

Piecewise Trend Value

Problem

Evaluate a piecewise linear trend in hinge form: base + slope * t + sum over j of delta_j * max(0, t - tau_j), pairing changepoints tau_j with slope changes delta_j.

Each changepoint adds delta_j to the slope for times beyond tau_j.

Hint

Only changepoints strictly before t contribute to the evaluated value.

Test cases

case 1
in: [1,0.5,[2,5],[1,-0.5],4]
expected: 5
case 2
in: [2,1,[],[],3]
expected: 5
case 3
in: [0,0,[1],[2],3]
expected: 4
case 4
in: [1,0.5,[5],[1],2]
expected: 2
Starter codePython
def piecewise_trend_value(base, slope, changepoints, deltas, t):
    # Your code here
    pass

4 test cases · run your code against them in the editor