Maybe my find could help someone. I was using HyperOpt to optimise parameters of a piecewise affine function.
Therefore I need nested parameters to properly set x parameters parts:
As nested parameters don't work (anymore) for HyperOpt, nor for Optuna... I recommend the pwlf library for all those who have the same problem.
This lib proposes 2 ways to extract the parameters of a piecewise linear function :
- By providing the number of parts
- By providing the breakpoint locations
If like me you are interested in finding the breakpoint locations you can provide the number of parts:
import pwlf
import pandas as pd
data = pd.DataFrame.from_dict({
"x": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
"y": [0, 4, 6, 7, 8, 9, 10, 7, 3, 1],
})
model = pwlf.PiecewiseLinFit(data.x, data.y)
nb_parts = 3
model.fit(nb_parts)
print(f"x part intersections: {model.fit_breaks}")
# x part intersections: [0. 1.99 6.00 9.]
print(f"linear coefficient of each part: {model.slopes}")
# linear coefficient of each part: [ 4.00, 1.00, -3.00]
print(f"linear bias of each part: {model.intercepts}")
# linear bias of each part: [-7.11e-06, 5.99e+00, 3.00e+01]
Hope it helps!