-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add feasibility builder for explicit constraints #660
Conversation
Includes two new classes for linear and nonlinear constraints.
Include constraints and ctol.
Also added example notebook showing penalty-EI method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
@@ -468,6 +468,84 @@ def acquisition(x: TensorType) -> TensorType: | |||
return acquisition | |||
|
|||
|
|||
class FastConstraintsFeasibility(SingleModelAcquisitionBuilder[ProbabilisticModel]): | |||
""" | |||
Uses the :func:`fast_constraints_feasibility` function to build a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to mention that it uses fast_constraints_feasibility
(which after all is an implementation detail)?
Uses the :func:`fast_constraints_feasibility` function to build a | |
Builder for a probability of feasiblity acquisition function that uses the residuals of | |
direct constraints defined in the search space. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied that style from ProbabilityOfFeasibility, but I can remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 1e41a57.
default is CDF of the Normal distribution with a small scale. | ||
""" | ||
self._search_space = search_space | ||
self._smoothing_function = smoothing_function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check that search_space.has_constraints
here and raise an exception if it doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I'll add that in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 1e41a57.
:param search_space: The global search space over which the feasibility of the constraints | ||
is defined. | ||
:param smoothing_function: The smoothing function used for constraints residuals. The | ||
default is CDF of the Normal distribution with a small scale. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(explicitly state the default scale so people don't have to dig through the code?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 1e41a57.
@@ -15,7 +15,7 @@ | |||
from __future__ import annotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also want to also add an integration test case to test_bayesian_optimization.py
? (something similar to the notebook setup perhaps)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will take a bit longer to implement. I'll look into it and maybe add it as part of the next PR where we will have more optimisation methods.
grid_density=30, | ||
contour=True, | ||
) | ||
plot_bo_points(query_points, ax[0, 0], num_initial_points, arg_min_idx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plot is a bit unclear for me: maybe make the dots a bit bigger and the purple one brighter? (Alternatively, ask @vpicheny for a second opinion!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is an existing plotting function. I don't think the point size can be changed from its args but the colour can be, which I now have. Also, I have made the overall figure larger. Hopefully that is good enough.
:return: The function for probability of feasibility of constraints. | ||
""" | ||
|
||
@tf.function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the notebook, it looks like this is being retraced every loop, which is not ideal! I think the issue is because ExpectedConstrainedImprovement calls the constraint function with the query points, which change shape each time. We may be able to specify an input_signature here to handle this. If you can't quickly figure it out don't worry though: I'll raise an issue since I expect it's happening for the normal ProbabilityOfFeasibility too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ProbabilityOfFeasibility
has that problem too. I did spend a little bit of time looking at it, but didn't try changing the signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've raised an issue, thanks: #661
Improve documentation text Raise if search_space has no constraints Improve plot of BO points in notebook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy with this
Also includes initial notebook showing penalty-EI method. This notebook will be expanded further in the PR for constrained optimisation.