
    !#hK                    f    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dZ	y)    )annotationsN)_is_pareto_frontc                    | j                   d   dk(  r|j                   d   dk(  sJ t        j                  |d   | d ddf         }|d   | d d df   z
  }|| d d df   z
  }||z  S )N      r   )shapenpappend)sorted_pareto_solsreference_pointrect_diag_yedge_length_xedge_length_ys        T/var/www/html/sandstorm/venv/lib/python3.12/site-packages/optuna/_hypervolume/wfg.py_compute_2dr      s    ##A&!+0E0Ea0HA0MMM))OA.0B3B360JKK#A&);AqD)AAM"4QT"::M=((    c                   t        j                  | z
  d      }|j                  d   dk(  rt        |d         S |j                  d   dk(  rJt        j                  t        j                  | d   | d         z
        }t        j
                  |      |z
  S t        j                  | d d t         j                  f   |       t        fdt        |      D              S )Nr   axisr   r   r   c              3  R   K   | ]  \  }}t        ||d z   df   |         yw)r   N)_compute_exclusive_hv).0iinclusive_hvlimited_sols_arrayr   s      r   	<genexpr>z_compute_hv.<locals>.<genexpr>   s6      A| 	0AEG<lO\s   $')r
   prodr	   floatmaximumsumnewaxis	enumerate)sorted_loss_valsr   inclusive_hvsintersecr   s    `  @r   _compute_hvr'      s    GGO.>>RHM1"]1%&&			Q	1	$77?RZZ8H8KM]^_M`-aabvvm$x// $4Q

]$CEUV (7  r   c                h    | j                   d   dk(  r|S t        | d      }|t        | |   |      z
  S )Nr   Tassume_unique_lexsorted)r	   r   r'   )limited_solsr   r   on_fronts       r   r   r   !   sB     !!<  dKH+l8&<oNNNr   c                   t        j                  | |k        st        d      t        j                  t        j                  |            st	        d      S |s*t        j
                  | d      }t        |d      }||   }n| | dddf   j                            }|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.

    zAll 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   r   Tr)   Nr   )r
   all
ValueErrorisfiniter   uniquer   argsortr	   r   r'   )	loss_valsr   assume_paretounique_lexsorted_loss_valsr,   r   hvs          r   compute_hypervolumer8   G   s    D 66)./4
 	

 66"++o./U|%'YYyq%A"#$>X\]7A 'yA'>'>'@AQ1$+_=+_= R22eEl2r   )r   
np.ndarrayr   r9   returnr   )r$   r9   r   r9   r:   r   )r+   r9   r   r   r   r9   r:   r   )F)r4   r9   r   r9   r5   boolr:   r   )

__future__r   numpyr
   optuna.study._multi_objectiver   r   r'   r   r8    r   r   <module>r@      so    "  :)"#O#O,1#ODN#O
#ON OT>3>3,6>3GK>3
>3r   