o
    }oi                      @  s   d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d d	lmZ e rLd d
lmZ d dlmZ d dlmZ edddddddd(ddZd)d"d#Zd)d$d%Zd)d&d'ZdS )*    )annotations)Callable)Sequence)experimental_func)Study)FrozenTrial)_get_pareto_front_info)_ParetoFrontInfo)_imports)Axes)Axes3D)pltz2.8.0NT)target_namesinclude_dominated_trials
axis_orderconstraints_functargetsstudyr   r   list[str] | Noner   boolr   list[int] | Noner   /Callable[[FrozenTrial], Sequence[float]] | Noner   return'Axes'c                C  s"   t   t| |||||}t|S )a  Plot the Pareto front of a study.

    .. seealso::
        Please refer to :func:`optuna.visualization.plot_pareto_front` for an example.

    Args:
        study:
            A :class:`~optuna.study.Study` object whose trials are plotted for their objective
            values. ``study.n_objectives`` must be either 2 or 3 when ``targets`` is :obj:`None`.
        target_names:
            Objective name list used as the axis titles. If :obj:`None` is specified,
            "Objective {objective_index}" is used instead. If ``targets`` is specified
            for a study that does not contain any completed trial,
            ``target_name`` must be specified.
        include_dominated_trials:
            A flag to include all dominated trial's objective values.
        axis_order:
            A list of indices indicating the axis order. If :obj:`None` is specified,
            default order is used. ``axis_order`` and ``targets`` cannot be used at the same time.

            .. warning::
                Deprecated in v3.0.0. This feature will be removed in the future. The removal of
                this feature is currently scheduled for v5.0.0, but this schedule is subject to
                change. See https://github.com/optuna/optuna/releases/tag/v3.0.0.
        constraints_func:
            An optional function that computes the objective constraints. It must take a
            :class:`~optuna.trial.FrozenTrial` and return the constraints. The return value must
            be a sequence of :obj:`float` s. A value strictly larger than 0 means that a
            constraint is violated. A value equal to or smaller than 0 is considered feasible.
            This specification is the same as in, for example,
            :class:`~optuna.samplers.NSGAIISampler`.

            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.

            .. warning::
                Deprecated in v4.0.0. This feature will be removed in the future. The removal of
                this feature is currently scheduled for v6.0.0, but this schedule is subject to
                change. See https://github.com/optuna/optuna/releases/tag/v4.0.0.
        targets:
            A function that returns a tuple of target values to display.
            The argument to this function is :class:`~optuna.trial.FrozenTrial`.
            ``targets`` must be :obj:`None` or return 2 or 3 values.
            ``axis_order`` and ``targets`` cannot be used at the same time.
            If the number of objectives is neither 2 nor 3, ``targets`` must be specified.

            .. note::
                Added in v3.0.0 as an experimental feature. The interface may change in newer
                versions without prior notice.
                See https://github.com/optuna/optuna/releases/tag/v3.0.0.

    Returns:
        A :class:`matplotlib.axes.Axes` object.
    )r
   checkr   _get_pareto_front_plot)r   r   r   r   r   r   info r   a/home/ubuntu/.local/lib/python3.10/site-packages/optuna/visualization/matplotlib/_pareto_front.pyplot_pareto_front   s
   Br   r   r	   c                 C  s,   | j dkr	t| S | j dkrt| S J d)N      FzMust not reach here)	n_targets_get_pareto_front_2d_get_pareto_front_3dr   r   r   r   r   ^   s
   

r   c                   sF  t jd t  \}}|d t d}| j jd   |	 j jd   d}t
 jdkrP|j fdd jD  fd	d jD d
dd d}t
 jdkrr|j fdd jD  fdd jD |d|d t
 jdkr|j fdd jD  fdd jD |ddd  jd ur| r|  |S )NggplotPareto-front Plottab10r      Trialc                      g | ]\}}| j d   qS r   r   .0_valuesr%   r   r   
<listcomp>t       z(_get_pareto_front_2d.<locals>.<listcomp>c                   r+   r)   r-   r.   r%   r   r   r2   u   r3   #ccccccInfeasible Trial)xycolorlabelFeasible Trialc                   r+   r,   r-   r.   r%   r   r   r2   |   r3   c                   r+   r4   r-   r.   r%   r   r   r2   }   r3   c                   r+   r,   r-   r.   r%   r   r   r2      r3   c                   r+   r4   r-   r.   r%   r   r   r2      r3   r!   
Best Trial)r   styleusesubplots	set_titleget_cmap
set_xlabelr   r   
set_ylabelleninfeasible_trials_with_valuesscatternon_best_trials_with_valuesbest_trials_with_valueshas_datalegend)r   r0   axcmaptrial_labelr   r%   r   r#   g   s@   

r#   c                   s  t jd t  }|jdd}|d t d}| j j	d   |
 j j	d   | j j	d   d	} jd urmt jdkrm|j fd
d jD  fdd jD  fdd jD ddd d} jd urt jdkr|j fdd jD  fdd jD  fdd jD |d|d  jd urt jr|j fdd jD  fdd jD  fdd jD |ddd  jd ur| r|  |S )Nr&   3d)
projectionr'   r(   r   r)   r    r*   c                   r+   r,   r-   r.   r%   r   r   r2      r3   z(_get_pareto_front_3d.<locals>.<listcomp>c                   r+   r4   r-   r.   r%   r   r   r2      r3   c                   r+   r    r-   r.   r%   r   r   r2      r3   r5   r6   )xsyszsr9   r:   r;   c                   r+   r,   r-   r.   r%   r   r   r2      r3   c                   r+   r4   r-   r.   r%   r   r   r2      r3   c                   r+   rP   r-   r.   r%   r   r   r2      r3   c                   r+   r,   r-   r.   r%   r   r   r2      r3   c                   r+   r4   r-   r.   r%   r   r   r2      r3   c                   r+   rP   r-   r.   r%   r   r   r2      r3   r!   r<   )r   r=   r>   figureadd_subplotr@   rA   rB   r   r   rC   
set_zlabelrE   rD   rF   rG   rH   rI   rJ   )r   figrK   rL   rM   r   r%   r   r$      sL   


r$   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r	   r   r   )
__future__r   collections.abcr   r   optuna._experimentalr   optuna.studyr   optuna.trialr   "optuna.visualization._pareto_frontr   r	   3optuna.visualization.matplotlib._matplotlib_importsr
   is_successfulr   r   r   r   r   r#   r$   r   r   r   r   <module>   s.    
I
	(