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

Feature Request - Is there a way to enforce an S-shape constraint ? #45

Open
marwan116 opened this issue Mar 10, 2020 · 3 comments
Open

Comments

@marwan116
Copy link

First off - Thank you so much for open sourcing Tensorflow lattice! It is great to make use of lattice interpolation to enforce predicate domain knowledge concerning monotonicity and convexity. Looking through the current documentation, I see it is possible to enforce an increasing and concave graph for diminishing returns, but what if I want to enforce an S-curve (i.e. an increasing convex curve with an inflection point that then turns concave)?

@mmilanifard
Copy link
Collaborator

If your inflection point is fixed (i.e. with known input value), then this can be done with the sum of two PWL's. Our PWL layers are flat outside the rage defined by the input keypoints, so you can just split your original input keypoint list at the inflection point and use a different PWL for each part. If there is enough symmetry, you might be able to do this with a single 2 dimensional layer and a couple of negations.

If the inflection point is not fixed, then I think this can still be done with 3 PWL's with some caveats. The generic form might not have a trivial solution.

Depending on your usecase and if your date already partially looks like an s-curve, you might also want to look at wrinkle regularization (see used in action here: https://www.tensorflow.org/lattice/tutorials/shape_constraints#smoothing_calibrators). It penalizes the changes in the second derivative (https://www.tensorflow.org/lattice/api_docs/python/tfl/pwl_calibration_layer/WrinkleRegularizer).

@marwan116
Copy link
Author

Thank you so much for your prompt response:

Yes, I agree if the inflection point is known beforehand, then I can imagine how crafting a combination of 2 PWLs or a single 2D layer would be a good workaround ... I guess it would be nice to add this as one of the examples (to show how combining constrained PWL layers leads to more complex shape definitions)

@mmilanifard
Copy link
Collaborator

That's a good idea. Might be a good tutorial to build various shape constraints using the current set of layers.

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