dswah/pyGAM

Adding new penalty terms

weissercn opened this issue · 3 comments

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()

wow thats a cool idea.
i think youre right!

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

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

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.