Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the slope of each segment of the curve #105

Open
KXX-Change opened this issue Aug 6, 2022 · 1 comment
Open

Limit the slope of each segment of the curve #105

KXX-Change opened this issue Aug 6, 2022 · 1 comment

Comments

@KXX-Change
Copy link

when find the best number of line segments,how to limit the slope of each segment? For example, make the slope of each segment in the final result less than 3.

@cjekel
Copy link
Owner

cjekel commented Aug 6, 2022

I don't have a nice way to do this, because the model parameters are fit with a least squares fit. The model parameters aren't the slope themselves, but the change in slope from the previous slopes.

That is not to say that this formulation is impossible.

It might be possible to write a constraint on the breakpoints such that the slope never hits 3 -- but I would think you would also want fits for known breakpoints where the slope never hits 3. These are two very different formulations.

Anyways, I just hacked up a constrained optimization problem that moves breakpoints such that the slope is less than a max_slope value. This still solve the least squares fit for given breakpoint locations. Take a look at https://github.com/cjekel/piecewise_linear_fit_py/blob/master/examples/slope_constraint_demo.ipynb and let me know if this works and if you have questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants