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

Adding new penalty terms #330

Open
weissercn opened this issue Mar 2, 2023 · 3 comments
Open

Adding new penalty terms #330

weissercn opened this issue Mar 2, 2023 · 3 comments

Comments

@weissercn
Copy link

Hi,
I came across this package and am really impressed! I was wondering how difficult it would be to add new penalty terms.

I know that pyGAM has constraints for the curvature being larger (convex) or smaller (concave) than zero. Would it be possible to constrain the curvature to be larger than a certain pre-specified value?

mask = sp.sparse.diags((np.diff(coef.ravel(), n=2) < 0).astype(float))

I have the same question for monotonicity.

mask = sp.sparse.diags((np.diff(coef.ravel()) < 0).astype(float))

In general, is there an intuitive answer as to why the penalty is computes in the same way, but with a different derivative for both cases? Would it be possible specify any rejection criteria for the mask and still have the pyGAM code work?

D = sparse_diff(sp.sparse.identity(n).tocsc(), n=derivative) * mask
penalty = D.dot(D.T).tocsc()

@dswah
Copy link
Owner

dswah commented Feb 8, 2024

wow thats a cool idea.
i think youre right!

i need to think about it a bit 🤔
what do you think?

@weissercn
Copy link
Author

i think it would be incredibly useful, but I don't know the math well enough to know how to do this.

@dswah
Copy link
Owner

dswah commented Feb 10, 2024

let's do a test!
can you design a simple dataset for a case where:

  • perfect solution requires a model with curvature >1 on a certain X interval
  • but we add a constraint were all curvatures are forced to be less than 1
  • using the method you suggested

if the fitted model fits poorly on the high curvature interval then we know the method works.

we could test analogously for monotonicity/slope.

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