cjekel / piecewise_linear_fit_py

fit piecewise linear data for a specified number of line segments
MIT License
289 stars 59 forks source link

Can I get y_values if I have only x and slopes values? #104

Open esakhib opened 1 year ago

esakhib commented 1 year ago

I did something like this:

x,y = read_from_file() my_pwlf = pwlf.PiecewiseLinFit(x, y) my_pwlf.fitfast(breaks_num=15, pop=500) x_out = np.linspace(min(x), max(x), num=10000) y_out = my_pwlf.predict(x_out)

And then I calculated and saved all 15 slopes values in the file. Now, I want to load x, y and slopes, and get y_out, can I get this or must calculate fitfast again? Also I have saved duration of each slope.

cjekel commented 1 year ago

This dumps the whole model (and data) https://jekel.me/piecewise_linear_fit_py/examples.html#model-persistence which you may or may not want to do.

These models don't really work with slopes, they work on model parameters (beta) and breakpoints. The difference between model parameters and slopes is how I formulate the piecewise problem. Take a look at https://github.com/cjekel/piecewise_linear_fit_py/issues/13#issuecomment-426719085 which save the beta and breakpoint values from a fitted model. After doing that predict call, it repopulates all the model parameters, and you can get the slopes from it.

Does this help?