Repository navigation
Refactor pareto front and support constraints_func in plot_pareto_front - #3128
Conversation
|
|
8451b66 to
2f1f5f7
Compare
Codecov Report
@@ Coverage Diff @@
## master #3128 +/- ##
==========================================
+ Coverage 91.22% 91.23% +0.01%
==========================================
Files 146 146
Lines 11918 11929 +11
==========================================
+ Hits 10872 10884 +12
+ Misses 1046 1045 -1
Continue to review full report at Codecov.
|
|
This pull request has not seen any recent activity. |
2f1f5f7 to
d24d23c
Compare
constraints_func in plot_pareto_front
toshihikoyanase
left a comment
There was a problem hiding this comment.
Thank you for your PR! It basically looks great, but let me check carefully since it introduced many conditional branches.
Here are some early comments.
toshihikoyanase
left a comment
There was a problem hiding this comment.
Let me add my second comment. I went through the changes in the optuna module. I'll check the test code, next.
hvy
left a comment
There was a problem hiding this comment.
The code is a bit complex to be honest but it mostly LGTM.
I left some nitpicks on details and internals.
| feasible_trials = [] | ||
| infeasible_trials = [] | ||
| for trial in study.get_trials(states=(TrialState.COMPLETE,)): | ||
| if all(map(lambda x: x <= 0.0, constraints_func(trial))): |
There was a problem hiding this comment.
Not necessary in this PR, but it might soon make sense to encapsulate this logic into some reusable function.
There was a problem hiding this comment.
Sounds reasonable. I think FrozenTrial.is_feasible(constraints_func) is a simple choice. It can be a follow-up task.
There was a problem hiding this comment.
I'm a bit conservative to add a new method to FrozenTrial sinceTrial does not have the corresponding method. And also the type signature will have a nested structure i.e., the method of FrozenTrial instance takes a function of FrozenTrial instance.
There was a problem hiding this comment.
I guess it can be discussed in a different ticket, but just to elaborate my initial thought, was to create a private free function.
|
[Opinion wanted] The current Pareto-front plot uses gradations to visualize the |
|
I personally find gradients quite informative during analysis. If possible, I'd vote for rendering them in this case too. |
toshihikoyanase
left a comment
There was a problem hiding this comment.
I added some comments about the test cases. If you have any questions or comments, please let me know.
6130148 to
ff33baa
Compare
ff33baa to
a0db84e
Compare
Co-authored-by: Hiroyuki Vincent Yamazaki <[email protected]>
hvy
left a comment
There was a problem hiding this comment.
LGTM, thanks a lot for the long-running work. The code looks simpler now and I'm sure this'll be useful for multi-objective analysis.
HideakiImamura
left a comment
There was a problem hiding this comment.
Thank you for the great improvement of the plot_pareto_front! The code looks good to me. I have several suggestions, but they can be done as follow-up tasks. So, let me approve this PR.
| axis_order: | ||
| A list of indices indicating the axis order. If :obj:`None` is specified, | ||
| default order is used. | ||
| constraints_func: |
There was a problem hiding this comment.
I think it is useful to add an example using this option. It can be a follow-up task.
| If given, trials are classified into three categories: feasible and best, feasible but | ||
| non-best, and infeasible. Categories are shown in different colors. Here, whether a | ||
| trial is best (on Pareto front) or not is determined ignoring all infeasible trials. |
There was a problem hiding this comment.
It would be easier to understand if it is clearly stated that infeasible points are colored in gray. It can be a follow-up task.
| feasible_trials = [] | ||
| infeasible_trials = [] | ||
| for trial in study.get_trials(states=(TrialState.COMPLETE,)): | ||
| if all(map(lambda x: x <= 0.0, constraints_func(trial))): |
There was a problem hiding this comment.
Sounds reasonable. I think FrozenTrial.is_feasible(constraints_func) is a simple choice. It can be a follow-up task.
|
The current code produces the following plots. I found that there is no explanation of infeasible points in the plot. It can be improved in the followup PR. code: import optuna
def objective(trial):
x = trial.suggest_float("x", 0, 5)
y = trial.suggest_float("y", 0, 3)
v0 = 4 * x ** 2 + 4 * y ** 2
v1 = (x - 5) ** 2 + (y - 5) ** 2
c0 = v0 - 60
trial.set_user_attr("constraint", (c0,))
return v0, v1
def constraints(trial):
return trial.user_attrs["constraint"]
sampler = optuna.samplers.NSGAIISampler(constraints_func=constraints)
study = optuna.create_study(directions=["minimize", "minimize"], sampler=sampler)
study.optimize(objective, n_trials=50)
fig = optuna.visualization.plot_pareto_front(study)
fig.write_image("without.png")
fig = optuna.visualization.plot_pareto_front(study, constraints_func=constraints)
fig.write_image("with.png") |
toshihikoyanase
left a comment
There was a problem hiding this comment.
Sorry for the delayed response. LGTM!




Motivation
Implementation in #3125 is repetitious (10 times of
go.Scatterandgo.Scatter3din total), so it will be desirable to be refactored. This refactoring is strongly tied with the enhancement ofplot_pareto_front, so I did both in this PR.Description of the changes
_get_pareto_front_2dand_get_pareto_front_3d._make_scatter_object_baseand used it inplot_pareto_frontbecause each invocation ofgo.Scatterandgo.Scatter3dshares several parameters in common.constraints_funcproperty to plot_parent_front so that infeasible trials can be explicitly marked in case of training with objective constraints. Infeasible trials are excluded from the computation of pareto front._get_pareto_front_trials_by_trialsto_multi_objective.pyso that we don't have to create anotherStudyin order to compute the pareto front of a part of trials in aStudy.