-
Notifications
You must be signed in to change notification settings - Fork 62
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
Allow a Mixture of Degrees #41
Comments
I think this would be a nice addition! I won't be able to work on it any time soon though. |
I'll take a look at it and do a PR at some point. |
Hey, I just got an email about this. Going to try an implementation today. It will work easiest with degrees 1 and 0 since they have the same number of parameters. |
Check out the mixed_degree branch. Documentation on setting degree as list """
degree : int, list, optional
The degree of polynomial to use. The default is degree=1 for
linear models. Use degree=0 for constant models. Use a list for
mixed degrees (only supports degrees 1 or 0). List should be read
from left to right, degree=[1, 0, 1] corresponds to a mixed degree
model, where the left most segment has degree=1, the middle
segment degree=0, and the right most segment degree=1.
""" Mixed degree example: import numpy as np
import matplotlib.pyplot as plt
import pwlf
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [1, 2, 3, 4, 4.25, 3.75, 4, 5, 6, 7]
degree_list = [1, 0, 1]
my_pwlf = pwlf.PiecewiseLinFit(x, y, degree=degree_list)
breaks = my_pwlf.fit(3)
# generate predictions
x_hat = np.linspace(min(x), max(x), 1000)
y_hat = my_pwlf.predict(x_hat)
plt.figure()
plt.plot(x, y, 'o')
plt.plot(x_hat, y_hat)
plt.show() Current issues:
There are probably more issues with this... The entire assemble_with_breaks should probably be rewritten to accommodate this feature in a cleaner manner. |
Here is the commit that added the changes: ef58aaa |
I've been playing around with the latest commit and with the code segment, but I keep getting an error. Its on python 3.6 and I tried converting it to an np array as well.
|
@cyriltw You'll need to install that experimental branch first.
|
@cjekel you beat me to it, for some reason the branch wasn't checked out so causing the trouble. Now it works. Doing more testing. Thanks for including this |
I think it would be really helpful to allow a mixture of degrees for a model. This could be passed as a list or numpy array to the degree parameter. This has real-life applications: https://pdfs.semanticscholar.org/a6cf/634e8788586ba1d37c10c744db6a2f790109.pdf
In this scenario, a mixture of [0, 1] and [1, 0] degrees would be needed. However, it might be interesting to see if mixtures of higher degrees could be useful.
The text was updated successfully, but these errors were encountered: