def _get_pareto_front_3d( study: MultiObjectiveStudy, names: Optional[List[str]], include_dominated_trials: bool = False ) -> "go.Figure": if names is None: names = ["Objective 0", "Objective 1", "Objective 2"] elif len(names) != 3: raise ValueError("The length of `names` is supposed to be 3.") trials = study.get_pareto_front_trials() if len(trials) == 0: _logger.warning("Your study does not have any completed trials.") point_colors = ["blue"] * len(trials) if include_dominated_trials: non_pareto_trials = _get_non_pareto_front_trials(study, trials) point_colors += ["red"] * len(non_pareto_trials) trials += non_pareto_trials data = go.Scatter3d( x=[t.values[0] for t in trials], y=[t.values[1] for t in trials], z=[t.values[2] for t in trials], text=[_make_hovertext(t) for t in trials], mode="markers", hovertemplate="%{text}<extra></extra>", marker={"color": point_colors}, ) layout = go.Layout( title="Pareto-front Plot", scene={"xaxis_title": names[0], "yaxis_title": names[1], "zaxis_title": names[2]}, ) return go.Figure(data=data, layout=layout)
def _get_pareto_front_3d( study: MultiObjectiveStudy, names: Optional[List[str]], include_dominated_trials: bool = False, axis_order: Optional[List[int]] = None, ) -> "go.Figure": if names is None: names = ["Objective 0", "Objective 1", "Objective 2"] elif len(names) != 3: raise ValueError("The length of `names` is supposed to be 3.") trials = study.get_pareto_front_trials() if len(trials) == 0: _logger.warning("Your study does not have any completed trials.") point_colors = ["blue"] * len(trials) if include_dominated_trials: non_pareto_trials = _get_non_pareto_front_trials(study, trials) point_colors += ["red"] * len(non_pareto_trials) trials += non_pareto_trials if axis_order is None: axis_order = list(range(3)) else: if len(axis_order) != 3: raise ValueError( f"Size of `axis_order` {axis_order}. Expect: 3, Actual: {len(axis_order)}." ) if len(set(axis_order)) != 3: raise ValueError(f"Elements of given `axis_order` {axis_order} are not unique!.") if max(axis_order) > 2: raise ValueError( f"Given `axis_order` {axis_order} contains invalid index {max(axis_order)} " "higher than 2." ) if min(axis_order) < 0: raise ValueError( f"Given `axis_order` {axis_order} contains invalid index {min(axis_order)} " "lower than 0." ) data = go.Scatter3d( x=[t.values[axis_order[0]] for t in trials], y=[t.values[axis_order[1]] for t in trials], z=[t.values[axis_order[2]] for t in trials], text=[_make_hovertext(t) for t in trials], mode="markers", hovertemplate="%{text}<extra></extra>", marker={"color": point_colors}, ) layout = go.Layout( title="Pareto-front Plot", scene={ "xaxis_title": names[axis_order[0]], "yaxis_title": names[axis_order[1]], "zaxis_title": names[axis_order[2]], }, ) return go.Figure(data=data, layout=layout)
def _make_scatter_object( n_targets: int, axis_order: Sequence[int], include_dominated_trials: bool, trials_with_values: Optional[Sequence[Tuple[FrozenTrial, Sequence[float]]]], hovertemplate: str, infeasible: bool = False, dominated_trials: bool = False, ) -> Union["go.Scatter", "go.Scatter3d"]: trials_with_values = trials_with_values or [] assert n_targets in (2, 3) marker = _make_marker( [trial for trial, _ in trials_with_values], include_dominated_trials, dominated_trials=dominated_trials, infeasible=infeasible, ) if n_targets == 2: return go.Scatter( x=[values[axis_order[0]] for _, values in trials_with_values], y=[values[axis_order[1]] for _, values in trials_with_values], text=[_make_hovertext(trial) for trial, _ in trials_with_values], mode="markers", hovertemplate=hovertemplate, marker=marker, showlegend=False, ) else: assert n_targets == 3 return go.Scatter3d( x=[values[axis_order[0]] for _, values in trials_with_values], y=[values[axis_order[1]] for _, values in trials_with_values], z=[values[axis_order[2]] for _, values in trials_with_values], text=[_make_hovertext(trial) for trial, _ in trials_with_values], mode="markers", hovertemplate=hovertemplate, marker=marker, showlegend=False, )
def _make_scatter_object_base( n_dim: int, trials: Sequence[FrozenTrial], axis_order: List[int], include_dominated_trials: bool, hovertemplate: str, infeasible: bool = False, dominated_trials: bool = False, ) -> Union["go.Scatter", "go.Scatter3d"]: assert n_dim in (2, 3) marker = _make_marker( trials, include_dominated_trials, dominated_trials=dominated_trials, infeasible=infeasible, ) if n_dim == 2: return go.Scatter( x=[t.values[axis_order[0]] for t in trials], y=[t.values[axis_order[1]] for t in trials], text=[_make_hovertext(t) for t in trials], mode="markers", hovertemplate=hovertemplate, marker=marker, showlegend=False, ) else: assert n_dim == 3 return go.Scatter3d( x=[t.values[axis_order[0]] for t in trials], y=[t.values[axis_order[1]] for t in trials], z=[t.values[axis_order[2]] for t in trials], text=[_make_hovertext(t) for t in trials], mode="markers", hovertemplate=hovertemplate, marker=marker, showlegend=False, )
def _get_pareto_front_3d( study: Study, target_names: Optional[List[str]], include_dominated_trials: bool = False, axis_order: Optional[List[int]] = None, ) -> "go.Figure": if target_names is None: target_names = ["Objective 0", "Objective 1", "Objective 2"] elif len(target_names) != 3: raise ValueError("The length of `target_names` is supposed to be 3.") trials = study.best_trials n_best_trials = len(trials) if len(trials) == 0: _logger.warning("Your study does not have any completed trials.") if include_dominated_trials: non_pareto_trials = _get_non_pareto_front_trials(study, trials) trials += non_pareto_trials if axis_order is None: axis_order = list(range(3)) else: if len(axis_order) != 3: raise ValueError( f"Size of `axis_order` {axis_order}. Expect: 3, Actual: {len(axis_order)}." ) if len(set(axis_order)) != 3: raise ValueError(f"Elements of given `axis_order` {axis_order} are not unique!.") if max(axis_order) > 2: raise ValueError( f"Given `axis_order` {axis_order} contains invalid index {max(axis_order)} " "higher than 2." ) if min(axis_order) < 0: raise ValueError( f"Given `axis_order` {axis_order} contains invalid index {min(axis_order)} " "lower than 0." ) data = [ go.Scatter3d( x=[t.values[axis_order[0]] for t in trials[n_best_trials:]], y=[t.values[axis_order[1]] for t in trials[n_best_trials:]], z=[t.values[axis_order[2]] for t in trials[n_best_trials:]], text=[_make_hovertext(t) for t in trials[n_best_trials:]], hovertemplate="%{text}<extra>Trial</extra>", mode="markers", marker={ "line": {"width": 0.5, "color": "Grey"}, "color": [t.number for t in trials[n_best_trials:]], "colorscale": "Blues", "colorbar": { "title": "#Trials", }, }, showlegend=False, ), go.Scatter3d( x=[t.values[axis_order[0]] for t in trials[:n_best_trials]], y=[t.values[axis_order[1]] for t in trials[:n_best_trials]], z=[t.values[axis_order[2]] for t in trials[:n_best_trials]], text=[_make_hovertext(t) for t in trials[:n_best_trials]], hovertemplate="%{text}<extra>Best Trial</extra>", mode="markers", marker={ "line": {"width": 0.5, "color": "Grey"}, "color": [t.number for t in trials[:n_best_trials]], "colorscale": "Reds", "colorbar": { "title": "#Best trials", "x": 1.1 if include_dominated_trials else 1, "xpad": 40, }, }, showlegend=False, ), ] layout = go.Layout( title="Pareto-front Plot", scene={ "xaxis_title": target_names[axis_order[0]], "yaxis_title": target_names[axis_order[1]], "zaxis_title": target_names[axis_order[2]], }, ) return go.Figure(data=data, layout=layout)