-
Notifications
You must be signed in to change notification settings - Fork 0
Constraint violation modification + direct evolution of parameters #22
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
Conversation
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.
Pull Request Overview
This PR updates the evolutionary algorithm to incorporate constraint violation as a pseudo‐objective and adds a new direct prescriptor for evolving parameters directly. Key changes include:
- Modifying evaluator functions to return metrics together with a constraint violation value (cv) across evaluators and tests.
- Updating CSV output and corresponding test assertions to account for the new cv field.
- Introducing the DirectPrescriptor and DirectFactory classes for direct parameter evolution.
Reviewed Changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_parallel.py | Updated test to account for the new tuple output in evaluate_candidate. |
| tests/test_cv.py | Added tests for constraint violation prioritization in domination. |
| tests/test_cartpole.py | Modified CSV reading and assertions to validate new output shape and cv. |
| tests/dummy_evaluator.py | Updated evaluator to return a tuple (metrics, cv). |
| presp/prescriptor/direct.py | Added DirectPrescriptor and DirectFactory for direct parameter evolution. |
| presp/prescriptor/base.py | Introduced the cv attribute in the base prescriptor. |
| presp/prescriptor/init.py | Imported DirectPrescriptor and DirectFactory. |
| presp/nsga2_utils.py | Updated domination logic to account for constraint violations. |
| presp/evolution.py | Updated result recording now including cv and refined CSV output. |
| presp/evaluator/base.py | Adjusted evaluation functions to return (metrics, cv). |
| examples/cartpole/direct_evaluator.py | Evaluator now returns tuple (metrics, cv) for CartPole. |
| examples/bnh/demo.ipynb | Updated demo notebook to reflect changes in CSV output and prescriptor usage. |
| examples/bnh/config.yml | Added configuration for evolution and prescriptor parameters. |
| examples/bnh/bnh_evaluator.py | New evaluator implementation that computes constraint violations. |
| c6 = self.c6(x2) | ||
|
|
||
| g = np.array([c1, c2, c3, c4, c5, c6]) | ||
| g = np.sum(np.maximum(0, g)) |
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.
Constraints are handled within the evaluator, evolution just needs to know the final number
| for candidate, metrics in zip(pop_subset, pop_results): | ||
| for candidate, (metrics, cv) in zip(pop_subset, pop_results): | ||
| candidate.metrics = metrics | ||
| candidate.cv = cv |
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.
We must set the cv parameter now
| if candidate1.cv > candidate2.cv: | ||
| return False | ||
|
|
||
| # If both candidates are feasible or have the same constraint violation, we compare metrics |
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.
Domination starts with constraint violation. If they are tied, we go into rank and distance.
| self.cand_id = "" | ||
| self.parents = None | ||
| self.metrics = None | ||
| self.cv = 0 |
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.
Default CV is 0
| Creates a randomly initialized vector of floats between xl and xu uniformly. | ||
| """ | ||
| genome = np.random.rand(*self.xl.shape) | ||
| genome = genome * (self.xu - self.xl) + self.xl |
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.
Random uniform initialization between xl and xu
We modify our evolution to softly handle constraint violation by using it as a pseudo-objective that is prioritized first.
We also create a direct prescriptor class that directly evolves parameters within a given range.
Finally, we combine the two to optimize a multi-objective problem with constraints.