Skip to content

Fix visualization.matplotlib.plot_optimization_history for multi-objective#2532

Merged
toshihikoyanase merged 2 commits intooptuna:masterfrom
nzw0301:fix-plot-history
Apr 2, 2021
Merged

Fix visualization.matplotlib.plot_optimization_history for multi-objective#2532
toshihikoyanase merged 2 commits intooptuna:masterfrom
nzw0301:fix-plot-history

Conversation

@nzw0301
Copy link
Copy Markdown
Member

@nzw0301 nzw0301 commented Mar 27, 2021

Motivation

See #2531

Description of the changes

Unify the logic to Plotly's one.

Results


import optuna


def objective(trial):
    # Binh and Korn function.
    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
    return v0, v1


study = optuna.study.create_study(directions=["minimize", "minimize"])
study.optimize(objective, n_trials=10)

optuna.visualization.plot_optimization_history(study, target=lambda t: t.values[0])
optuna.visualization.matplotlib.plot_optimization_history(study, target=lambda t: t.values[0])

Matplotlib

download (1)

Plotly as reference

newplot (1)

@github-actions github-actions Bot added the optuna.visualization Related to the `optuna.visualization` submodule. This is automatically labeled by github-actions. label Mar 27, 2021
@nzw0301 nzw0301 changed the title Fix matplotlib.plot_optimization_history for multi-objective Fix visualization.matplotlib.plot_optimization_history for multi-objective Mar 27, 2021
@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #2532 (b986258) into master (0b334f1) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2532   +/-   ##
=======================================
  Coverage   89.80%   89.80%           
=======================================
  Files         135      135           
  Lines       11330    11330           
=======================================
  Hits        10175    10175           
  Misses       1155     1155           
Impacted Files Coverage Δ
.../visualization/matplotlib/_optimization_history.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b334f1...b986258. Read the comment docs.

@nzw0301
Copy link
Copy Markdown
Member Author

nzw0301 commented Mar 27, 2021

By the way, it might be great to add a multi-objective example or more description for the target argument because specifying target was unclear for me.

@nzw0301
Copy link
Copy Markdown
Member Author

nzw0301 commented Apr 1, 2021

Any update? :)

@HideakiImamura
Copy link
Copy Markdown
Member

Sorry for the late reply. I've just started to review this PR.

Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. In the else case, I think we will not get the legend, is this what we expect?

@HideakiImamura HideakiImamura added the bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself. label Apr 1, 2021
@nzw0301
Copy link
Copy Markdown
Member Author

nzw0301 commented Apr 1, 2021

@HideakiImamura Thank you for your feedback! Yes, since Plotly's function also doesn't show the legend.

Copy link
Copy Markdown
Member

@HideakiImamura HideakiImamura left a comment

Choose a reason for hiding this comment

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

Sure! I confirmed the behavior by seeing visualization/plot_optimimzation_history. LGTM!

Copy link
Copy Markdown
Member

@toshihikoyanase toshihikoyanase left a comment

Choose a reason for hiding this comment

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

Thank you for your PR. I confirmed that the change resolved #2531. I also confirmed that it does not affect plots for single objective optimization. LGTM!

image

@keisuke-umezawa Let me review this PR since we'll freeze the code for v2.7 today.

@toshihikoyanase toshihikoyanase merged commit 011a0d4 into optuna:master Apr 2, 2021
@nzw0301 nzw0301 deleted the fix-plot-history branch April 2, 2021 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Issue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself. optuna.visualization Related to the `optuna.visualization` submodule. This is automatically labeled by github-actions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants