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 erJd d	lmZ d d
lmZ d dlmZ d dl
mZ e rZd dlmZ d dlmZ eeZdZdZedddde	fd&d d!Zd'd$d%ZdS )(    )annotations)TYPE_CHECKING)experimental_func)
get_logger)DEFAULT_MIN_N_TRIALS)_get_improvement_info)_get_y_range)_imports)Study)BaseErrorEvaluator)BaseImprovementEvaluator)_ImprovementInfo)Axes)pltg?g      ?z3.2.0FNstudyr
   
plot_errorboolimprovement_evaluatorBaseImprovementEvaluator | Noneerror_evaluatorBaseErrorEvaluator | Nonemin_n_trialsintreturn'Axes'c                 C  s    t   t| |||}t||S )a  Plot the potentials for future objective improvement.

    This function visualizes the objective improvement potentials, evaluated
    with ``improvement_evaluator``.
    It helps to determine whether we should continue the optimization or not.
    You can also plot the error evaluated with
    ``error_evaluator`` if the ``plot_error`` argument is set to :obj:`True`.
    Note that this function may take some time to compute
    the improvement potentials.

    .. seealso::
        Please refer to :func:`optuna.visualization.plot_terminator_improvement`.

    Args:
        study:
            A :class:`~optuna.study.Study` object whose trials are plotted for their improvement.
        plot_error:
            A flag to show the error. If it is set to :obj:`True`, errors
            evaluated by ``error_evaluator`` are also plotted as line graph.
            Defaults to :obj:`False`.
        improvement_evaluator:
            An object that evaluates the improvement of the objective function.
            Default to :class:`~optuna.terminator.RegretBoundEvaluator`.
        error_evaluator:
            An object that evaluates the error inherent in the objective function.
            Default to :class:`~optuna.terminator.CrossValidationErrorEvaluator`.
        min_n_trials:
            The minimum number of trials before termination is considered.
            Terminator improvements for trials below this value are
            shown in a lighter color. Defaults to ``20``.

    Returns:
        A :class:`matplotlib.axes.Axes` object.
    )r	   checkr   _get_improvement_plot)r   r   r   r   r   info r   k/home/ubuntu/.local/lib/python3.10/site-packages/optuna/visualization/matplotlib/_terminator_improvement.pyplot_terminator_improvement   s   *
r    r   r   c                 C  s  t | j}tjd t \}}|d |d |d t	d}|dkr0t
d |S |j| jd |d  | jd |d  d	|dt||krMdnd d
 ||krk|j| j|d  | j|d  d	|ddd | jd ur~|j| j| jd	|ddd |  |t| | |S )NggplotzTerminator Improvement PlotTrialzTerminator Improvementtab10r   zThere are no complete trials.   o)markercoloralphalabel)r&   r'   r)      Error)lentrial_numbersr   styleusesubplots	set_title
set_xlabel
set_ylabelget_cmap_loggerwarningplotimprovementsALPHAerrorslegendset_ylimr   )r   r   n_trials_axcmapr   r   r   r   O   sJ   





	
r   )r   r
   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )
__future__r   typingr   optuna._experimentalr   optuna.loggingr   'optuna.terminator.improvement.evaluatorr   ,optuna.visualization._terminator_improvementr   r   3optuna.visualization.matplotlib._matplotlib_importsr	   optuna.study.studyr
   optuna.terminatorr   r   r   is_successfulr   r   __name__r5   PADDING_RATIO_Yr9   r    r   r   r   r   r   <module>   s4    /