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

Add feasibility builder for explicit constraints #660

Merged
merged 12 commits into from
Dec 1, 2022

Conversation

khurram-ghani
Copy link
Collaborator

Also includes initial notebook showing penalty-EI method. This notebook will be expanded further in the PR for constrained optimisation.

Copy link
Collaborator

@uri-granta uri-granta left a 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
Copy link
Collaborator

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

Suggested change
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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.
Copy link
Collaborator

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

Copy link
Collaborator Author

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
Copy link
Collaborator

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)

Copy link
Collaborator Author

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)
Copy link
Collaborator

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

Copy link
Collaborator Author

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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
Copy link
Collaborator

@uri-granta uri-granta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy with this

Base automatically changed from khurram/explicit_constr_space to develop December 1, 2022 15:04
@khurram-ghani khurram-ghani merged commit aeb7eab into develop Dec 1, 2022
@khurram-ghani khurram-ghani deleted the khurram/explicit_constr_feasibility branch December 1, 2022 16:48
@uri-granta uri-granta linked an issue Jun 29, 2023 that may be closed by this pull request
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

Successfully merging this pull request may close these issues.

cheap-to-evaluate constraint
2 participants