Ë
    ÿÿæi  ã                  ó    — d dl mZ d dlZd dlZd dlmZ 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 	 	 	 	 	 	 d	d„Z	 	 	 	 	 	 	 	 	 	 dd„Z		 	 	 	 	 	 	 	 	 	 dd„Z
y)
é    )ÚannotationsN)Úcompute_hypervolumec                ó  — | j                   d   dk(  r|| j                   d   k  sJ ‚| j                   d   }t        j                  | j                   d   «      }| j                  «       }t        j                  |t        j
                  d d …f   |d¬«      }t        j                  |t        ¬«      }t        |«      D ]Ï  }	t        j                  ||z
  d¬«      }
t        j                  |
«      }|||      ||	<   ||   j                  «       }t        j                  ||	z
  t        ¬«      }d||<   ||   }||   }||   }t        j                  |d   |d |…df   «      |d |…df<   t        j                  |d   ||d …df   «      ||d …df<   ŒÑ |S )Néÿÿÿÿé   r   ©Úaxis©ÚdtypeFé   )ÚshapeÚnpÚarangeÚcopyÚrepeatÚnewaxisÚzerosÚintÚrangeÚprodÚargmaxÚonesÚboolÚminimum)Úrank_i_loss_valsÚrank_i_indicesÚsubset_sizeÚreference_pointÚn_trialsÚsorted_indicesÚsorted_loss_valsÚ
rect_diagsÚselected_indicesÚiÚcontribsÚ	max_indexÚ	loss_valsÚkeeps                 úm/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/optuna/_hypervolume/hssp.pyÚ_solve_hssp_2dr*   
   s“  € ð ×!Ñ! "Ñ%¨Ò*¨{Ð>N×>TÑ>TÐUVÑ>WÒ/WÐWÐWØ×%Ñ% aÑ(€Hä—Y‘YÐ/×5Ñ5°aÑ8Ó9€NØ'×,Ñ,Ó.Ðä—‘˜?¬2¯:©:²q¨=Ñ9¸8È!ÔL€JÜ—x‘x ´3Ô7ÐÜ�;ÖˆÜ—7‘7˜:Ð(8Ñ8¸rÔBˆÜ—I‘I˜hÓ'ˆ	Ø,¨^¸IÑ-FÑGÐ˜ÑØ$ YÑ/×4Ñ4Ó6ˆ	ä�w‰w�x !‘|¬4Ô0ˆØˆˆY‰à'¨Ñ-ˆØ Ñ%ˆ
Ø+¨DÑ1Ðä$&§J¡J¨y¸©|¸ZÈ
ÈÈ
ÐTUÈÑ=VÓ$Wˆ
�:�I�:˜q�=Ñ!Ü$&§J¡J¨y¸©|¸ZÈ	É
ÐTUÈÑ=VÓ$Wˆ
�9‘:˜q�=Ò!ð  ð  Ðó    c           
     óô  — t        j                  |«      r$t        j                  | t        j                  «      S t        j
                  |dd…t        j                  f   |dd «      }t        j                  ||z
  d¬«      }t        j                  |«      }t        j                  | |t        j                  ||dd…df   z
  d¬«      z
  «      } d}|j                  d   dk  }	t        j                  |  «      D ]|  }
||
   rt        j                  x}| |
<   Œ| |
   |k  rŒ'|	r-||
   j                  «       |d<   t        ||d¬«      }||z
  | |
<   n||
   t        ||
   |«      z
  | |
<   t        | |
   |«      }Œ~ | S )	a÷  Lazy update the hypervolume contributions.

    (1) Lazy update of the hypervolume contributions
    S=selected_indices - {indices[max_index]}, T=selected_indices, and S' is a subset of S.
    As we would like to know argmax H(T v {i}) in the next iteration, we can skip HV
    calculations for j if H(T v {i}) - H(T) > H(S' v {j}) - H(S') >= H(T v {j}) - H(T).
    We used the submodularity for the inequality above. As the upper bound of contribs[i] is
    H(S' v {j}) - H(S'), we start to update from i with a higher upper bound so that we can
    skip more HV calculations.

    (2) A simple cheap-to-evaluate contribution upper bound
    The HV difference only using the latest selected point and a candidate is a simple, yet
    obvious, contribution upper bound. Denote t as the latest selected index and j as an unselected
    index. Then, H(T v {j}) - H(T) <= H({t} v {j}) - H({t}) holds where the inequality comes from
    submodularity. We use the inclusion-exclusion principle to calculate the RHS.
    Nr   r   r   g        é   T)Úassume_pareto)ÚmathÚisinfr   Ú	full_likeÚinfÚmaximumr   r   r   r   Úargsortr   r   Úmax)r%   Úpareto_loss_valuesÚselected_vecsr   Úhv_selectedÚintersecÚinclusive_hvsÚis_contrib_infÚmax_contribÚis_hv_calc_fastr$   Úhv_pluss               r)   Ú_lazy_contribs_updater?   -   sl  € ô. ‡z�z�+Ôä�|‰|˜H¤b§f¡fÓ-Ð-ä�z‰zÐ,ªQ´·
±
¨]Ñ;¸]È3ÈBÐ=OÓP€HÜ—G‘G˜OÐ.@Ñ@ÀqÔI€MÜ—X‘X˜mÓ,€NÜ�z‰zØ�-¤"§'¡'¨/¸HÂQÈÀU¹OÑ*KÐRSÔ"TÑTó€Hð €KØ(×.Ñ.¨qÑ1°QÑ6€OÜ�Z‰Z˜˜	Ö"ˆØ˜!ÒÜ(*¯©Ð.ˆK˜( 1™+ØØ�A‰;˜Ò$Øñ Ø 2°1Ñ 5× :Ñ :Ó <ˆM˜"ÑÜ)¨-¸ÐX\Ô]ˆGØ! KÑ/ˆH�QŠKà'¨Ñ*Ô-@ÀÈ!ÁÈoÓ-^Ñ^ˆH�Q‰KÜ˜( 1™+ {Ó3‰ð #ð" €Or+   c           	     ó(  — t        j                  |«      j                  «       s|d | S |j                  |k(  r|S | j                  d   dk(  rt        | |||«      S ||j                  k  sJ ‚|| z
  }| j                  \  }}t        j                  |d¬«      }t        j                  |t        ¬«      }t        j                  ||f«      }	t        j                  |«      }
d}t        |«      D ]¢  }t        t        j                  |«      «      }|||   z  }|
|   ||<   | |   j                  «       |	|<   t        j                  |j                  t        ¬«      }d||<   ||   }|
|   }
| |   } ||dz
  k(  r ||   S t!        || |	d |dz    ||«      }Œ¤ ||   S )Nr   r   r   r
   r   Fr   )r   ÚisfiniteÚallÚsizer   r*   r   r   r   Úemptyr   r   r   r   r   r   r?   )r   r   r   r   Údiff_of_loss_vals_and_ref_pointÚn_solutionsÚn_objectivesr%   r#   r7   ÚindicesÚhvÚkr&   r(   s                  r)   Ú_solve_hssp_on_unique_loss_valsrK   d   s¹  € ô �;‰;�Ó'×+Ñ+Ô-Ø˜l˜{Ð+Ð+Ø×Ñ˜kÒ)ØÐØ×Ñ˜bÑ! QÒ&ÜÐ.°ÀÈ_Ó]Ð]à˜×,Ñ,Ò,Ð,Ð,à&5Ð8HÑ&HÐ#Ø"2×"8Ñ"8Ñ€[�,Ü�w‰wÐ6¸RÔ@€HÜ—x‘x ´3Ô7ÐÜ—H‘H˜k¨<Ð8Ó9€MÜ�i‰i˜Ó$€GØ	
€BÜ�;ÖˆÜœŸ	™	 (Ó+Ó,ˆ	Ø
ˆh�yÑ!Ñ!ˆØ% iÑ0Ð˜ÑØ+¨IÑ6×;Ñ;Ó=ˆ�aÑÜ�w‰w�x—}‘}¬DÔ1ˆØˆˆY‰Ø˜D‘>ˆØ˜$‘-ˆØ+¨DÑ1ÐØ�˜a‘Òàð Ð*Ñ+Ð+ô	 )ØÐ&¨°g¸¸A¹Ð(>ÀÐQSó
‰ð  ð$ Ð*Ñ+Ð+r+   c                ó\  — ||j                   k(  r|S t        j                  | dd¬«      \  }}|j                   }||k  r]t        j                  |j                   t        ¬«      }d||<   t        j
                  |j                   «      |    }d||d||z
   <   ||   S t        ||||«      }	||	   S )ah  Solve a hypervolume subset selection problem (HSSP) via a greedy algorithm.

    This method is a 1-1/e approximation algorithm to solve HSSP.

    For further information about algorithms to solve HSSP, please refer to the following
    paper:

    - `Greedy Hypervolume Subset Selection in Low Dimensions
       <https://doi.org/10.1162/EVCO_a_00188>`__
    Tr   )Úreturn_indexr	   r
   N)rC   r   Úuniquer   r   r   rK   )
r   r   r   r   Úrank_i_unique_loss_valsÚindices_of_unique_loss_valsÚn_uniqueÚchosenÚduplicated_indicesÚ$selected_indices_of_unique_loss_valss
             r)   Ú_solve_hssprU   �   sÌ   € ð  �n×)Ñ)Ò)ØÐä;=¿9¹9Ø t°!ô<Ñ8ÐÐ8ð +×/Ñ/€HØ�+ÒÜ—‘˜.×-Ñ-´TÔ:ˆØ.2ˆÐ*Ñ+ÜŸY™Y ~×':Ñ':Ó;¸V¸GÑDÐØ?CˆÐ!Ð": K°(Ñ$:Ð;Ñ<Ø˜fÑ%Ð%ä+JØÐ!<¸kÈ?ó,Ð(ð Ð>Ñ?Ð?r+   )
r   ú
np.ndarrayr   rV   r   r   r   rV   ÚreturnrV   )r%   rV   r6   rV   r7   rV   r   rV   r8   ÚfloatrW   rV   )Ú
__future__r   r/   Únumpyr   Úoptuna._hypervolume.wfgr   r*   r?   rK   rU   © r+   r)   Ú<module>r]      sð   ðÝ "ã ã å 7ð Ø ð àð ð ð ð  ð	 ð
 ó ðF4Øð4à"ð4ð ð4ð  ð	4ð
 ð4ð ó4ðn(,Ø ð(,àð(,ð ð(,ð  ð	(,ð
 ó(,ðV!@Ø ð!@àð!@ð ð!@ð  ð	!@ð
 ô!@r+   