o
    /wii                     @  s&  d dl mZ d dlmZ d dlmZ d dl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 d dlmZ e rnd 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
d	d;dddd<d d!Zd=d$d%Zd>d.d/Zd?d3d4Zd@d9d:Z dS )A    )annotations)defaultdict)CallableN)Any)experimental_func)Study)FrozenTrial)_get_slice_plot_info)_PlotValues)_SlicePlotInfo)_SliceSubplotInfo)_imports)Axes)Colormap)
matplotlib)PathCollection)pltz2.2.0zObjective Value)targettarget_namestudyr   paramslist[str] | Noner   %Callable[[FrozenTrial], float] | Noner   strreturn'Axes'c                C  s   t   tt| |||S )aV  Plot the parameter relationship as slice plot in a study with Matplotlib.

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

    Args:
        study:
            A :class:`~optuna.study.Study` object whose trials are plotted for their target values.
        params:
            Parameter list to visualize. The default is all parameters.
        target:
            A function to specify the value to display. If it is :obj:`None` and ``study`` is being
            used for single-objective optimization, the objective values are plotted.

            .. note::
                Specify this argument if ``study`` is being used for multi-objective optimization.
        target_name:
            Target's name to display on the axis label.


    Returns:
        A :class:`matplotlib.axes.Axes` object.
    )r   check_get_slice_plotr	   )r   r   r   r    r   c/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/optuna/visualization/matplotlib/_slice.py
plot_slice   s    r    infor   c                 C  s  t | jdkrt \}}|S td}d}tjd t | jdkr;t \}}|d t| jd |||| j}nAt	j
d d d }t	j
d d }	tjdt | jd	|t | j |	fd
\}}|d t| jD ]\}
}||
 }t||||| j}qj|j||d}|d |S )Nr   Bluesg?ggplot   z
Slice Plotzfigure.figsize   T)shareyfigsize)axTrial)lensubplotsr   get_cmapstyleuse	set_title_generate_slice_subplotr   r   rcParamssuptitle	enumeratecolorbar	set_label)r!   _r(   cmappadding_ratiofigaxsscmin_figwidthfighightisubplotaxcbr   r   r   r   >   s2   




r   subplot_infor   r(   r7   
'Colormap'r8   float'PathCollection'c                 C  sr  |j | j|d d }tg g g }tg g g }t| j| j| j| jD ]=\}}	}
}|d us7|dks7|	d us7|	dkr^|rL|j| |j|	 |j|
 q!|j| |j|	 |j|
 q!| j	ri|
d d}| jr||j}|j}|j}|j}|j}nt| |\}}}t| |\}}}d}t|| ||}||d |d  |j||||dd}|j||d	d
d |  |S )N)xlabelylabelNonelogcategoricalr   r$   grey)cr7   
edgecolorsz#cccccczInfeasible Trial)rK   label)set
param_namer
   zipxytrial_numbersconstraintsappendis_log
set_xscaleis_numerical_get_categorical_plot_values_calc_lim_with_paddingset_xlimscatterlabel_outer)rA   r(   r7   r8   r   scalefeasible
infeasiblerQ   rR   numrK   
feasible_x
feasible_y
feasible_cinfeasible_xinfeasible_yr6   xlimr;   r   r   r   r0   g   sD    
r0   valuesr
   (tuple[list[Any], list[float], list[int]]c           
      C  s   | j d usJ g }g }g }tt}t|j|j|jD ]\}}}|| ||f q| j D ]}	||	 D ]\}}|t|	 || || q2q,|||fS N)	x_labelsr   listrP   rQ   rR   rS   rU   r   )
rA   rh   value_xvalue_yvalue_cpoints_dictrQ   rR   numberx_labelr   r   r   rY      s   


rY   	list[Any]r^   
str | Nonetuple[float, float]c                 C  s   t | }t| }|dkr.t|t| | }tdt|| tdt|| fS |dkrEtt| d }|| }| || fS || | }|| || fS )NrH   
   rI   r$   )maxminmathlog10powr*   rN   )rh   r8   r^   	value_max	value_minpaddingwidthr   r   r   rZ      s   rZ   rj   )
r   r   r   r   r   r   r   r   r   r   )r!   r   r   r   )rA   r   r(   r   r7   rB   r8   rC   r   r   r   rD   )rA   r   rh   r
   r   ri   )rh   rs   r8   rC   r^   rt   r   ru   )!
__future__r   collectionsr   collections.abcr   ry   typingr   optuna._experimentalr   optuna.studyr   optuna.trialr   optuna.visualization._slicer	   r
   r   r   3optuna.visualization.matplotlib._matplotlib_importsr   is_successfulr   r   r   r   r   r    r   r0   rY   rZ   r   r   r   r   <module>   s:    
#
)
.