dswah / pyGAM

[HELP REQUESTED] Generalized Additive Models in Python
https://pygam.readthedocs.io
Apache License 2.0
852 stars 156 forks source link

Adding new penalty terms #330

Open weissercn opened 1 year ago

weissercn commented 1 year ago

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? https://github.com/dswah/pyGAM/blob/b57b4cf8783a90976031e1857e748ca3e6ec650b/pygam/penalties.py#L170

I have the same question for monotonicity. https://github.com/dswah/pyGAM/blob/b57b4cf8783a90976031e1857e748ca3e6ec650b/pygam/penalties.py#L99

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 commented 5 months ago

wow thats a cool idea. i think youre right!

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

weissercn commented 4 months ago

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

dswah commented 4 months ago

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

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

we could test analogously for monotonicity/slope.