
    ,YHhi                       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j,                         r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
d      	 dddd	 	 	 	 	 	 	 	 	 dd       ZddZ	 	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 d dZ y)!    )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_namec               X    t        j                          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
   )studyparamsr   r   s       _/var/www/html/planif/env/lib/python3.12/site-packages/optuna/visualization/matplotlib/_slice.py
plot_slicer      s&    @ NN/vv{STT    c           	     n   t        | j                        dk(  rt        j                         \  }}|S t        j                  d      }d}t        j                  j                  d       t        | j                        dk(  rOt        j                         \  }}|j                  d       t        | j                  d   |||| j                        }nt        j                  d   d   dz  }t        j                  d   d   }	t        j                  dt        | j                        d	|t        | j                        z  |	f
      \  }}|j                  d       t        | j                        D ]#  \  }
}||
   }t        ||||| j                        }% |j                  |      }|j                  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)info_r%   cmappadding_ratiofigaxsscmin_figwidthfighightisubplotaxcbs                r   r   r   >   s}   
4==Q2	 << DMIIMM(
4==Q<<>Sl# %T]]1%5sD-QUQaQab "**+;<Q?!C&&'78;<<!C$66A	
S 	\" $DMM2 	]JAwQB("dM4K[K[\B	] <<s<#DNN7Jr   c                :   |j                  | j                  |       d }t        g g g       }t        g g g       }t        | j                  | j
                  | j                  | j                        D ]  \  }}	}
}||dk7  s|	|	dk7  s|rR|j                  j                  |       |j
                  j                  |	       |j                  j                  |
       k|j                  j                  |       |j
                  j                  |	       |j                  j                  |
        | j                  r|j                  d       d}| j                  r=|j                  }|j
                  }|j                  }|j                  }|j
                  }n"t        | |      \  }}}t        | |      \  }}}d}t        ||z   ||      }|j                  |d   |d          |j                  ||||d      }|j                  ||d	d
       |j!                          |S )N)xlabelylabelNonelogcategoricalr   r!   grey)cr5   
edgecolorsz#cccccczInfeasible Trial)rF   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)subplot_infor%   r5   r6   r   scalefeasible
infeasiblerL   rM   numrF   
feasible_x
feasible_y
feasible_cinfeasible_xinfeasible_yr4   xlimr9   s                       r   r-   r-   g   s    FF,))+F>E2r2&HRR(J(B(BLD\D\ 51c1 =AK1=AK

!!!$

!!!$&&--c2##A&##A&((//45 
e  ZZ
ZZ
++
!||!||-I,X`-a*
J
(D\S](^%lA!*|";]ERDKKQa!	J
jtPV	WBJJ|\Y>PJQNNIr   c                   | j                   J g }g }g }t        t              }t        |j                  |j
                  |j                        D ]  \  }}}||   j                  ||f        | j                   D ]K  }	||	   D ]A  \  }}|j                  t        |	             |j                  |       |j                  |       C M |||fS N)	x_labelsr   listrK   rL   rM   rN   rP   str)
rY   valuesvalue_xvalue_yvalue_cpoints_dictrL   rM   numberx_labels
             r   rT   rT      s       ,,,GGGd#KFHHfhh0D0DE +1fAq&k*+(( #$W- 	#IAvNN3w<(NN1NN6"	##
 GW$$r   c                   t        |       }t        |       }|dk(  rt        j                  |      t        j                  |      z
  |z  }t        j                  dt        j                  |      |z
        t        j                  dt        j                  |      |z         fS |dk(  r$t        t        |             dz
  }||z  }| ||z   fS ||z
  |z  }||z
  ||z   fS )NrC   
   rD   r!   )maxminmathlog10powr'   rI   )ri   r6   rZ   	value_max	value_minpaddingwidths          r   rU   rU      s     FIFI~::i(4::i+@@MQHHRI.89HHRI.89
 	
 
-	CK 1$-'x((y(M97"I$777r   re   )
r   r   r   zlist[str] | Noner   z%Callable[[FrozenTrial], float] | Noner   rh   return'Axes')r3   r   r{   r|   )rY   r   r%   r|   r5   z
'Colormap'r6   floatr   rh   r{   z'PathCollection')rY   r   ri   r   r{   z(tuple[list[Any], list[float], list[int]])ri   z	list[Any]r6   r}   rZ   z
str | Noner{   ztuple[float, float])!
__future__r   collectionsr   collections.abcr   rt   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   r-   rT   rU    r   r   <module>r      s3   " # $   2  $ < 3 6 9 H 8HLNRG 7  $ U 59( U U U 2	 U
  U  U  UF&R+#++ + 	+
 + +\%#%-8%-%$88&+84>88r   