
    (^i                    D   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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  ee      ZdZ G d de      Z G d de      Zddd	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 ddZy)    )annotations)Callable)Sequence)cast)
NamedTupleN)
get_logger)Study)FrozenTrial)
TrialState)_imports)_check_plot_args)_filter_nonfinite)god   c                  "    e Zd ZU ded<   ded<   y)_EDFLineInfostr
study_name
np.ndarrayy_valuesN__name__
__module____qualname____annotations__     Z/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/optuna/visualization/_edf.pyr   r      s    Or   r   c                  "    e Zd ZU ded<   ded<   y)_EDFInfozlist[_EDFLineInfo]linesr   x_valuesNr   r   r   r   r    r    !   s    r   r    Objective Value)targettarget_namec          	        t        j                          t        j                  dd|iddi      }t	        | ||      }|j
                  }t        |      dk(  rt        j                  g |      S g }|D ]7  \  }}|j                  t        j                  |j                  ||d             9 t        j                  ||      }	|	j                  dd	g
       |	S )a  Plot the objective value EDF (empirical distribution function) of a study.

    Note that only the complete trials are considered when plotting the EDF.

    .. note::

        EDF is useful to analyze and improve search spaces.
        For instance, you can see a practical use case of EDF in the paper
        `Designing Network Design Spaces
        <https://doi.ieeecomputersociety.org/10.1109/CVPR42600.2020.01044>`__.

    .. note::

        The plotted EDF assumes that the value of the objective function is in
        accordance with the uniform distribution over the objective space.

    Args:
        study:
            A target :class:`~optuna.study.Study` object.
            You can pass multiple studies if you want to compare those EDFs.
        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:`plotly.graph_objects.Figure` object.
    z$Empirical Distribution Function PlottitlezCumulative Probability)r'   xaxisyaxisr   )datalayoutr!   )xynamemode   )range)r   checkr   Layout_get_edf_infor!   lenFigureappendScatterr"   update_yaxes)
studyr$   r%   r+   info	edf_linestracesr   r   figures
             r   plot_edfr?   &   s    N NNYY4$01F 4D

I
9~yyb00F ) ^
Hbjj4==H:T[\]^ YYF62F
q!f%Mr   c           	     n   t        | t              r| g}nt        |       }t        |||       t	        |      dk(  r5t
        j                  d       t        g t        j                  g             S |dd}|}g }g }|D ]  } t        | j                  dt        j                  f      |      }t        j                  |D cg c]
  } ||       c}      }	|j                  |	       |j                  | j                          t!        d |D              r5t
        j                  d	       t        g t        j                  g             S t        j"                  t        j$                  |            }
t        j&                  t        j$                  |            }t        j(                  |
|t*              }g }t-        ||      D ]]  \  }}	t        j.                  |	d d t        j0                  f   |k  d
      |	j2                  z  }|j                  t5        ||             _ t        ||      S c c}w )Nr   zThere are no studies.)r!   r"   c                6    t        t        | j                        S )N)r   floatvalue)ts    r   _targetz_get_edf_info.<locals>._targetw   s    qww''r   F)deepcopystates)r$   c              3  8   K   | ]  }t        |      d k(    yw)r   N)r5   ).0valuess     r   	<genexpr>z _get_edf_info.<locals>.<genexpr>   s     
53v;!
5s   zThere are no complete trials.)axis)r   r   )rD   r
   returnrB   )
isinstancer	   listr   r5   _loggerwarningr    nparrayr   
get_trialsr   COMPLETEr7   r   allminconcatenatemaxlinspaceNUM_SAMPLES_X_AXISzipsumnewaxissizer   )r:   r$   r%   studiesrE   study_names
all_valuestrialstrialrJ   min_x_valuemax_x_valuer"   edf_line_info_listr   r   s                   r   r4   r4   e   s   
 %'u+Wfk2
7|q/0b288B<88~	( K#%J -"eZ5H5H4JKTZ
 f=U6%==>&!5++,- 
5*
5578b288B<88&&
34K&&
34K{{;5GHH!+z: Z
F66&BJJ/8;!Dv{{R!!,*x"XYZ ,x@@# >s   H2
)r:   Study | Sequence[Study]r$   %Callable[[FrozenTrial], float] | Noner%   r   rM   z'go.Figure')Nr#   )r:   rh   r$   ri   r%   r   rM   r    )
__future__r   collections.abcr   r   typingr   r   numpyrR   optuna.loggingr   optuna.studyr	   optuna.trialr
   r   $optuna.visualization._plotly_importsr   optuna.visualization._utilsr   r   is_successfulr   r   rP   r[   r   r    r?   r4   r   r   r   <module>rt      s    " $ $    %  $ # 9 8 9 87
X
  : 
z  59(	<"< 2< 	<
 <B 59(/A"/A1/A /A 	/Ar   