ó
    ,Êžj  ã                  ó¨   • S SK Jr  S SKrS SKrS SKJr            SS jr            S	S jr          SS jr	          SS jr
g)
é    )ÚannotationsN)Úcompute_hypervolumec                ó  • U R                   S   S:X  a  X R                   S   ::  d   eU R                   S   n[        R                  " U R                   S   5      nU R                  5       n[        R                  " U[        R
                  S S 24   USS9n[        R                  " U[        S9n[        U5       HÄ  n	[        R                  " Xv-
  SS9n
[        R                  " U
5      nXU      X‰'   Xk   R                  5       n[        R                  " XI-
  [        S9nSXÛ'   X]   nX}   nXm   n[        R                  " US   US U2S4   5      US U2S4'   [        R                  " US   X{S 2S4   5      X{S 2S4'   MÆ     U$ )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                 Ú¦C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\optuna/_hypervolume/hssp.pyÚ_solve_hssp_2dr*   
   sy  € ð ×!Ñ! "Ñ%¨Ó*¨{×>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¸rÑBˆÜ—I’I˜hÓ'ˆ	Ø,¸IÑ-FÑGÐÑØ$Ñ/×4Ñ4Ó6ˆ	ä�wŠw�x‘|¬4Ñ0ˆØˆ‰à'Ñ-ˆØÑ%ˆ
Ø+Ñ1Ðä$&§J¢J¨y¸©|¸ZÈ
ÈÈ
ÐTUÈÑ=VÓ$Wˆ
�:�I�:˜q�=Ñ!Ü$&§J¢J¨y¸©|¸ZÉ
ÐTUÈÑ=VÓ$Wˆ
‘:˜q�=Ó!ñ  ð  Ðó    c           
     óþ  • [         R                  " U5      (       a%  [        R                  " U [        R                  5      $ [        R
                  " USS2[        R                  4   USS 5      n[        R                  " X1-
  SS9n[        R                  " U5      n[        R                  " X[        R                  " X5SS2S4   -
  SS9-
  5      n SnUR                  S   S:*  n	[        R                  " U * 5       H|  n
Xz   (       a  [        R                  =o€U
'   M"  X
   U:  a  M,  U	(       a&  X   R                  5       US'   [        X#SS9nX´-
  X
'   OXj   [        XZ   U5      -
  X
'   [        X
   U5      nM~     U $ )	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?   -   sR  € ô. ‡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Ø¤"§'¢'¨/ÂQÈÀU¹OÑ*KÐRSÑ"TÑTó€Hð €KØ(×.Ñ.¨qÑ1°QÑ6€OÜ�ZŠZ˜˜	Ö"ˆØ×Ü(*¯©Ð.ˆK 1™+ÙØ‰;˜Ó$Ùö Ø 2Ñ 5× :Ñ :Ó <ˆM˜"ÑÜ)¨-ÐX\Ñ]ˆGØ!Ñ/ˆHŠKà'Ñ*Ô-@ÀÁÈoÓ-^Ñ^ˆH‰KÜ˜(™+ {Ó3Šñ #ð" €Or+   c           	     ó  • [         R                  " U5      R                  5       (       d  US U $ UR                  U:X  a  U$ U R                  S   S:X  a  [        XX#5      $ X!R                  :  d   eX0-
  nU R                  u  pV[         R                  " USS9n[         R                  " U[        S9n[         R                  " X&45      n	[         R                  " U5      n
Sn[        U5       H–  n[        [         R                  " U5      5      nX·U   -  nX­   XŒ'   X   R                  5       Xœ'   [         R                  " UR                  [        S9nSXí'   X~   nX®   n
X   n XÂS-
  :X  a    X   $ [!        XpU	S US-    X;5      nM˜     X   $ )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Ñ&HÐ#Ø"2×"8Ñ"8Ñ€[Ü�wŠwÐ6¸RÑ@€HÜ—x’x ´3Ñ7ÐÜ—H’H˜kÐ8Ó9€MÜ�iŠi˜Ó$€GØ	
€BÜ�;ÖˆÜœŸ	š	 (Ó+Ó,ˆ	Ø
�yÑ!Ñ!ˆØ%Ñ0ÐÑØ+Ñ6×;Ñ;Ó=ˆÑÜ�wŠw�x—}‘}¬DÑ1ˆØˆ‰Ø‘>ˆØ‘-ˆØ+Ñ1ÐØ˜a‘Óàð Ñ+Ð+ô	 )Ø¨°g¸¸A¹Ð(>Àó
Šñ  ð$ Ñ+Ð+r+   c                óF  • X!R                   :X  a  U$ [        R                  " U SSS9u  pEUR                   nXb:  aX  [        R                  " UR                   [        S9nSXu'   [        R
                  " UR                   5      U)    nSXxSX&-
   '   X   $ [        XEX#5      n	X   $ )aP  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³   € ð  ×)Ñ)Ó)ØÐä;=¿9º9Ø t°!ñ<Ñ8Ðð +×/Ñ/€HØÓÜ—’˜.×-Ñ-´TÑ:ˆØ.2ˆÑ+ÜŸYšY ~×':Ñ':Ó;¸V¸GÑDÐØ?CˆÐ": KÑ$:Ð;Ñ<ØÑ%Ð%ä+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+   