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

Feature/hypervolume visualizations #92

Merged
merged 5 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blackboxopt/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "4.13.1"
__version__ = "4.13.2"

from parameterspace import ParameterSpace

Expand Down
89 changes: 89 additions & 0 deletions blackboxopt/visualizations/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import plotly.graph_objects as go
import plotly.io._html
import scipy.stats as sps
from pymoo.indicators.hv import HV
from pymoo.util.nds.efficient_non_dominated_sort import efficient_non_dominated_sort

from blackboxopt import Evaluation, Objective
from blackboxopt.utils import get_loss_vector
Expand Down Expand Up @@ -203,6 +205,93 @@ def multi_objective_visualization(
return fig


def compute_hypervolume(
evaluations: List[Evaluation],
objectives: Sequence[Objective],
reference_point: List[float],
) -> float:
losses = np.array(
[
get_loss_vector(
known_objectives=objectives, reported_objectives=e.objectives
)
for e in evaluations
]
)
pareto_front_idx = efficient_non_dominated_sort(losses)[0]
pareto_front = losses[pareto_front_idx]

hv = HV(reference_point)

return hv(pareto_front)


def hypervolume_over_iterations(
evaluations_per_optimizer: Dict[str, List[List[Evaluation]]],
objectives: Sequence[Objective],
reference_point: List[float],
):
colors = iter(px.colors.qualitative.Dark24)

plotly_data = []
for optimizer, studies in evaluations_per_optimizer.items():
hv_per_study = []
for evaluations in studies:
iteration_steps = len(evaluations)
hvs = [
compute_hypervolume(
evaluations[: (step + 1)], objectives, reference_point
)
for step in range(iteration_steps)
]
hv_per_study.append(hvs)

hv_means = np.mean(hv_per_study, axis=0)
hv_stds = np.std(hv_per_study, axis=0)

x_plotted = np.arange(len(hv_means))

r, g, b = plotly.colors.hex_to_rgb(next(colors))
color_line = f"rgb({r}, {g}, {b})"
color_fill = f"rgba({r}, {g}, {b}, 0.3)"

plotly_data.extend(
[
go.Scatter(
name=optimizer,
x=x_plotted,
y=hv_means,
mode="lines",
showlegend=True,
line=dict(color=color_line, simplify=True),
),
go.Scatter(
x=x_plotted,
y=hv_means - 1.96 * hv_stds,
mode="lines",
marker=dict(color=color_line),
line=dict(width=0, simplify=True),
showlegend=False,
hoverinfo="skip",
),
go.Scatter(
x=x_plotted,
y=hv_means + 1.96 * hv_stds,
mode="lines",
marker=dict(color=color_line),
line=dict(width=0, simplify=True),
showlegend=False,
hoverinfo="skip",
fillcolor=color_fill,
fill="tonexty",
),
]
)

fig = go.Figure(plotly_data)
return fig


def parallel_coordinate_plot_parameters(
evaluations: List[Evaluation],
columns: Optional[List[str]] = None,
Expand Down
Loading