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

forcing fits through points with degrees > 1 #54

Closed
TobI-SE opened this issue Jan 17, 2020 · 5 comments · Fixed by #56
Closed

forcing fits through points with degrees > 1 #54

TobI-SE opened this issue Jan 17, 2020 · 5 comments · Fixed by #56
Labels

Comments

@TobI-SE
Copy link

TobI-SE commented Jan 17, 2020

Hi, I am trying to force a fit through a point using the pwlf library. If I force the fit through a certain data point with a degree=1 everything works perfectly, but as soon as I set the degree=2 the following error comes up:

ValueError: could not broadcast input array from shape (5,1) into shape (11,1)

This is the code I used:

import numpy as np
import pwlf


#generate sin wave data
x = np.linspace(0, 10, num=100)
y = np.sin(x * np.pi / 2)
# add noise to the data
y = np.random.normal(0, 0.15, 100) + y

#linear fit
my_pwlf_1 = pwlf.PiecewiseLinFit(x, y, degree=1)
my_pwlf_1.fit(n_segments=6, x_c = [0], y_c = [0])
y_predict_1 = my_pwlf_1.predict(x)

# quadratic fit
my_pwlf_2 = pwlf.PiecewiseLinFit(x, y, degree=2)
my_pwlf_2.fit(n_segments=5, x_c = [0], y_c = [0])
y_predict_2 = my_pwlf_2.predict(x)
@cjekel cjekel added the bug label Jan 18, 2020
@cjekel
Copy link
Owner

cjekel commented Jan 18, 2020

Thanks Tobi. I guess I missed this test case when I've implemented this, and I think is a higher priority on my todo list since this is intended to work.

However, It's probably a week until I can look at this in detail.

Any help until then as to why this isn't working as intended is appreciated.

@cjekel
Copy link
Owner

cjekel commented Jan 22, 2020

Hi @TobI-SE

Thank you for the issue, and easy to reproduce code. I believe I've fixed the issue, and I have added your code as a test case. Do you mind checking this PR to see if it indeeds solves your issue? #56

Thanks,
CJ

@cjekel cjekel reopened this Jan 23, 2020
@cjekel
Copy link
Owner

cjekel commented Jan 23, 2020

I think this fixed the issue, but I'll leave this open for now. At the moment I'm going to release a new pwlf version which includes these changes.

@TobI-SE
Copy link
Author

TobI-SE commented Jan 27, 2020

Hi cjekel, sorry for the late response.
It all works perfectly, thank you.

@cjekel cjekel closed this as completed Jan 27, 2020
@cjekel
Copy link
Owner

cjekel commented Jan 27, 2020

Thanks for making me aware of the issue and giving me a basic example to work with!

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

Successfully merging a pull request may close this issue.

2 participants