-
Notifications
You must be signed in to change notification settings - Fork 15
Fit surrogate model on existing population #158
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
base: dev
Are you sure you want to change the base?
Conversation
Notes from Call with @maxsiskaNormalization / StandardScaler
|
| X_scaler = StandardScaler().fit(X) | ||
| Y_scaler = StandardScaler().fit(Y) | ||
|
|
||
| gpr = GaussianProcessRegressor() |
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.
Consider allowing specification of hyper parameters via kwargs (with reasonable defaults).
Important parameters:
kernel: default isConstantKernel(1.0, constant_value_bounds="fixed") * RBF(1.0, **length_scale_bounds="fixed")(consider moving to separate method, or expose their parameters in signature)alpha: Parameter to handle noisy data, default=1e-10optimizer: Custom optimizer for the kernel’s parameters (could improve performance, e.g. GA)normalize_y(do we need to inverse transform when evaluating?)
Other suggestions:
- Consider check if fit was "OK" (could also be part of some validation method)
- Implement heuristic for length scale based on bounds (e.g. length_scale = 0.5 * (ub - lb))
| ) -> Any: | ||
|
|
||
| X = np.array(X) | ||
| X_2d = np.array(X, ndmin=2) |
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.
Technically, this does not "ensure 2D" (only ndmin=2). Consequently, we should instead reshape to really ensure 2d.
Also, consider moving function out of class since it duplicates what is done in the OptimizationProblem class.
| X_test = surrogate.population.feasible.x[0:2] | ||
|
|
||
| F_test = surrogate.population.feasible.f[0:2] | ||
| F_est = surrogate.estimate_objectives(X_test) |
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.
Here, we need to use a different validation set to test if surrogate does predict well enough.
2759b01 to
5252709
Compare
35e0c67 to
d97cf31
Compare
Co-authored-by: Johannes Schmölder <[email protected]>
This plot could potentially replace the corner plot.
With this commit, also the behavior for deriving alternative solution objects changes. Instead of modifying the original array, the following methods / properties now return a new SolutionIO object: - resample() - normalize() - (anti)derivative - smooth_data()
* Do not round hopsy problem when computing chebyshev center --------- Co-authored-by: r.jaepel <[email protected]>
5252709 to
41cf95c
Compare
37fe8fb to
c51ffb5
Compare
This PR implements a
Surrogateclass for fitting GPs on existing data from optimizations.Supersedes #45
To do
Note, there is some WIP in #152 which will also affect this PR. Should we already rebase onto that branch s.t. we can adapt the corresponding interfaces but risk some friction should there be some more changes upstream?
Open questions
Alternative surrogate modeling approches
Currently, only GPs are implemented. However, other surrogate models can be envisioned (e.g. ANNs). To improve a more modular architecture, we could subclasses a
SurrogateBase.Follow-up projects
Once this is merged, we can also start working on other features which would improve or apply the surrogate models. Eventually, these should be moved to their own issues / PRs but for now, this is just a collection of ideas.
The interface
Currently, the
SurrogateModelclass somewhat mimics anOptimizationProblemas it also provides methods for estimating objectives, nonlinear constraints etc. To demonstrate this, compare theOptimizationProblemsequenceDiagram User->>+OptimizationProblem: evaluate_objectives(x) OptimizationProblem->>+User: f(x)with the
SurrogateModelsequenceDiagram User->>+SurrogateModel: estimate_objectives(x) SurrogateModel->>+User: f*(x)However, it is important to note that the
SurrogateModelwill never provide all functionality of theOptimizationProblem, such as specifying variables, constraints etc. Hence, it cannot directly be used as anOptimizationProbleme.g. to interface with anOptimizer.To me, this means we should rethink the architecture and consider what exactly does the
SurrogateModelreplace? In the context of anOptimizationProblem, I would say, it actually replaces the evaluation toolchain (that which returns the values x->f/g/m/...).Consequently, we should consider moving the evaluation toolchain from the
OptimizationProblemto its own module (which in the process would also make theOptimizationProblemless of a "god class" and would even allow reusing the toolchain in other places) and introduce anEvaluationInterface.The architecture would then look something like the following:
sequenceDiagram User->>+OptimizationProblem: evaluate_objectives(x) OptimizationProblem->>+EvaluationInterface: evaluate(x) EvaluationInterface->>+OptimizationProblem: f(x) OptimizationProblem->>+User: f(x)Where the
EvaluationInterfaceis then implemented by both theEvaluationPipeline(i.e. the current "toolchain") and theSurrogateModel:classDiagram class OptimizationProblem { evaluate_objectives(np.ndarray): np.ndarray } OptimizationProblem "1" *-- "1" EvaluationInterface class EvaluationInterface { <<interface>> +evaluate(np.ndarray): np.ndarray } SurrogateModel <|-- EvaluationInterface EvaluationPipeline <|-- EvaluationInterfaceConditioned optimization problems
One of the original ideas for this projects came from optimization problems where we want to fix the value of one of the variables and then run the optimization to find the best point given this value.
For this purpose, we should implement a
ConditionedOptimizationProblemwhich wraps the originalOptimizationProblemand provides an interface where the fixed variables are removed. While this is trivial to implement for bound constrained problems, it becomes potentially more complicated for problems with linear and nonlinear constraints.Plots
For process design, we are often not really interested in just the optimal point but in the general topology of the parameter space. E.g. we are interested in the contours of regions with a given purity. Finely sampling the parameter space would be very expensive so the idea could be to use a surrogate model for this purpose. See also partial dependence plots and #33.