Ë
    ÿÿæi­$  ã                  ón   — d dl mZ d dlZd dlmZ d	d„Zd	d„Zd
d„Z	 	 	 	 	 	 	 	 dd„Z		 d	 	 	 	 	 	 	 dd„Z
y)é    )ÚannotationsN)Ú_is_pareto_frontc                óØ   — | j                   d   |j                   d   cxk(  rdk(  sJ ‚ J ‚t        j                  |dd  | d d…df   g«      }|d   | d d …df   z
  }|| d d …df   z
  }||z  S )Né   r   é   éÿÿÿÿ)ÚshapeÚnpÚconcatenate)Úsorted_pareto_solsÚreference_pointÚrect_diag_yÚedge_length_xÚedge_length_ys        úl/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/optuna/_hypervolume/wfg.pyÚ_compute_2dr      s‘   € Ø×#Ñ# AÑ&¨/×*?Ñ*?ÀÑ*BÔGÀaÒGÐGÑGÐGÐGÜ—.‘. /°!°"Ð"5Ð7IÈ#È2È#ÈqÈ&Ñ7QÐ!RÓS€KØ# AÑ&Ð);ºA¸q¸DÑ)AÑA€MØÐ"4²Q¸°TÑ":Ñ:€MØ˜=Ñ(Ð(ó    c                ó¤  — | j                   d   |j                   d   cxk(  rdk(  sJ ‚ J ‚| j                   d   }t        j                  | dd…df   «      }t        j                  ||ft        ¬«      }|d   | |df   z
  ||t        j
                  |«      f<   t        j                  j                  t        j                  j                  |d¬«      d¬«      }| dd…df   }| |df   }t        j                  |dd |dd g«      |z
  }t        j                  |dd |dd g«      |z
  }t        j                  t        j                  ||«      |«      S )aw  
    Compute hypervolume in 3D. Time complexity is O(N^2) where N is sorted_pareto_sols.shape[0].
    If X, Y, Z coordinates are permutations of 0, 1, ..., N-1 and reference_point is (N, N, N), the
    hypervolume is calculated as the number of voxels (x, y, z) dominated by at least one point.
    If we fix x and y, this number is equal to the minimum of z' over all points (x', y', z')
    satisfying x' <= x and y' <= y. This can be efficiently computed using cumulative minimum
    (`np.minimum.accumulate`). Non-permutation coordinates can be transformed into permutation
    coordinates by using coordinate compression.
    r   r   é   N)Údtyper   ©Úaxis)
r	   r
   ÚargsortÚzerosÚfloatÚarangeÚmaximumÚ
accumulater   Údot)	r   r   ÚnÚy_orderÚz_deltaÚx_valsÚy_valsÚx_deltaÚy_deltas	            r   Ú_compute_3dr'      sK  € ð ×#Ñ# AÑ&¨/×*?Ñ*?ÀÑ*BÔGÀaÒGÐGÑGÐGÐGØ× Ñ  Ñ#€AÜ�j‰jÐ+ªA¨q¨DÑ1Ó2€GÜ�h‰h˜˜1�v¤UÔ+€GØ%4°QÑ%7Ð:LÈWÐVWÈZÑ:XÑ%X€GˆG”R—Y‘Y˜q“\Ð!Ñ"Ü�j‰j×#Ñ#¤B§J¡J×$9Ñ$9¸'ÈÐ$9Ó$JÐQRÐ#ÓS€Gà¢ 1 Ñ%€FØ ¨ 
Ñ+€FÜ�n‰n˜f Q R˜j¨/¸"¸1Ð*=Ð>Ó?À&ÑH€GÜ�n‰n˜f Q R˜j¨/¸!¸AÐ*>Ð?Ó@À6ÑI€Gä�6‰6”"—&‘&˜ 'Ó*¨GÓ4Ð4r   c                ó$  ‡‡
‡— | j                   d   dk(  r,d}t        ‰| d   «      D ]  \  }}|||z
  z  }Œ t        |«      S | j                   d   dk(  rLd\  }}}t        ‰| d   | d   «      D ](  \  }}}	|||z
  z  }|||	z
  z  }||t        ||	«      z
  z  }Œ* ||z   |z
  S ‰| z
  j	                  d¬«      Š
t        j                  | d d …t
        j                  f   | «      Š‰
d   t        ˆ
ˆˆfd„t        ‰
j                  dz
  «      D «       «      z   S )	Nr   r   ç      ð?r   )r)   r)   r)   r   r   c              3  óR   •K  — | ]  }t        ‰||d z   d…f   ‰|   ‰«      –— Œ  y­w)r   N)Ú_compute_exclusive_hv)Ú.0ÚiÚinclusive_hvsÚlimited_sols_arrayr   s     €€€r   Ú	<genexpr>z_compute_hv.<locals>.<genexpr>=   s8   øè ø€ ð #á.ˆAô 	Ð0°°A¸±E±G°Ñ<¸mÈAÑ>NÐP_×`Ù.ùs   ƒ$')r	   Úzipr   ÚmaxÚprodr
   r   ÚnewaxisÚsumÚrangeÚsize)Úsorted_loss_valsr   Úinclusive_hvÚrÚvÚhv1Úhv2ÚintersecÚv1Úv2r.   r/   s    `        @@r   Ú_compute_hvrA   )   sE  ú€ Ø×Ñ˜aÑ  AÒ%àˆÜ˜Ð)9¸!Ñ)<Ö=‰DˆAˆqØ˜A ™EÑ!‰Lð >ä�\Ó"Ð"Ø	×	Ñ	 Ñ	" aÒ	'ð +ÑˆˆS�(Ü˜_Ð.>¸qÑ.AÐCSÐTUÑCVÖW‰IˆAˆr�2Ø�1�r‘6‰MˆCØ�1�r‘6‰MˆCØ˜œC  B›K™Ñ'‰Hð Xð �S‰y˜8Ñ#Ð#à$Ð'7Ñ7×=Ñ=À2Ð=ÓF€MäŸ™Ð$4²Q¼¿
¹
°]Ñ$CÐEUÓVÐØ˜Ñœsõ #ä�}×)Ñ)¨AÑ-Ô.ó#ó  ñ ð r   c                óª   — | j                   d   dk\  sJ ‚| j                   d   dk  r|t        | |«      z
  S t        | d¬«      }|t        | |   |«      z
  S )Nr   r   r   T©Úassume_unique_lexsorted)r	   rA   r   )Úlimited_solsr9   r   Úon_fronts       r   r+   r+   C   sh   € ð ×Ñ˜aÑ  AÒ%Ð%Ð%Ø×Ñ˜!Ñ Ò!àœk¨,¸ÓHÑHÐHôB   ÀdÔK€HØœ+ l°8Ñ&<¸oÓNÑNÐNr   c                ó2  — t        j                  | |k  «      st        d«      ‚t        j                  t        j                  |«      «      st	        d«      S | j
                  dk(  ry|s*t        j                  | d¬«      }t        |d¬«      }||   }n| | dd…df   j                  «          }|j                  d   d	k(  rt        ||«      }n+|j                  d   d
k(  rt        ||«      }nt        ||«      }t        j                  |«      r|S t	        d«      S )aO  Hypervolume calculator for any dimension.

    This class exactly calculates the hypervolume for any dimension.
    For 3 dimensions or higher, the WFG algorithm will be used.
    Please refer to ``A Fast Way of Calculating Exact Hypervolumes`` for the WFG algorithm.

    .. note::
        This class is used for computing the hypervolumes of points in multi-objective space.
        Each coordinate of each point represents a ``values`` of the multi-objective function.

    .. note::
        We check that each objective is to be minimized. Transform objective values that are
        to be maximized before calling this class's ``compute`` method.

    Args:
        loss_vals:
            An array of loss value vectors to calculate the hypervolume.
        reference_point:
            The reference point used to calculate the hypervolume.
        assume_pareto:
            Whether to assume the Pareto optimality to ``loss_vals``.
            In other words, if ``True``, none of loss vectors are dominated by another.
            ``assume_pareto`` is used only for speedup and it does not change the result even if
            this argument is wrongly given. If there are many non-Pareto solutions in
            ``loss_vals``, ``assume_pareto=True`` will speed up the calculation.

    Returns:
        The hypervolume of the given arguments.

    z�All points must dominate or equal the reference point. That is, for all points in the loss_vals and the coordinate `i`, `loss_vals[i] <= reference_point[i]`.Úinfr   g        r   TrC   Nr   r   )r
   ÚallÚ
ValueErrorÚisfiniter   r7   Úuniquer   r   r	   r   r'   rA   )Ú	loss_valsr   Úassume_paretoÚunique_lexsorted_loss_valsrF   r   Úhvs          r   Úcompute_hypervolumerQ   n   s  € ôD �6‰6�)˜Ñ.Ô/Üð4ó
ð 	
ô
 �6‰6”"—+‘+˜oÓ.Ô/ä�U‹|ÐØ‡~�~˜ÒØáÜ%'§Y¡Y¨y¸qÔ%AÐ"Ü#Ð$>ÐX\Ô]ˆØ7¸ÑAÑð ' y²°A°¡×'>Ñ'>Ó'@ÑAÐà×Ñ˜QÑ 1Ò$ÜÐ+¨_Ó=‰Ø	×	Ñ	˜qÑ	! QÒ	&ô Ð+¨_Ó=‰äÐ+¨_Ó=ˆô —‘˜R”ˆ2Ð2¤e¨E£lÐ2r   )r   ú
np.ndarrayr   rR   Úreturnr   )r8   rR   r   rR   rS   r   )rE   rR   r9   r   r   rR   rS   r   )F)rM   rR   r   rR   rN   ÚboolrS   r   )Ú
__future__r   Únumpyr
   Úoptuna.study._multi_objectiver   r   r'   rA   r+   rQ   © r   r   Ú<module>rY      sy   ðÝ "ã å :ó)ó5ó2ð4(OØð(OØ,1ð(OØDNð(Oà
ó(OðX OTðG3ØðG3Ø,6ðG3ØGKðG3à
ôG3r   