L idZddlmZddlZddlZddlmZ d dZ d dZ d dZ d dZ y) a The functions in this file are mostly based on BoTorch v0.13.0, but they are refactored significantly from the original version. For ``_get_upper_bound_set``, look at: * https://github.com/pytorch/botorch/blob/v0.13.0/botorch/utils/multi_objective/box_decompositions/utils.py#L101-L160 For ``_get_box_bounds``, look at: * https://github.com/pytorch/botorch/blob/v0.13.0/botorch/utils/multi_objective/box_decompositions/utils.py#L163-L193 For ``_get_non_dominated_box_bounds``, look at: * https://github.com/pytorch/botorch/blob/v0.13.0/botorch/utils/multi_objective/box_decompositions/non_dominated.py#L395-L430 The preprocessing for four or fewer objectives, we use the algorithm proposed by: Title: A Box Decomposition Algorithm to Compute the Hypervolume Indicator Authors: Renaud Lacour, Kathrin Klamroth, and Carlos M. Fonseca URL: https://arxiv.org/abs/1510.01963 We refer this paper as Lacour17 in this file. ) annotationsN)_is_pareto_frontcd |j\}tjtjt d dddf<d fd }tj |g}tj dftj }||df<|D]}||||\}}||fS)a! This function follows Algorithm 2 of Lacour17. Args: sorted_pareto_sols: Pareto solutions sorted with respect to the first objective. ref_point: The reference point. Returns: upper_bound_set: The upper bound set, which is ``U(N)`` in the paper. The shape is ``(n_bounds, n_objectives)``. def_points: The defining points of each vector in ``U(N)``. The shape is ``(n_bounds, n_objectives, n_objectives)``. NOTE: ``pareto_sols`` corresponds to ``N`` and ``upper_bound_set`` corresponds to ``U(N)`` in the paper. ``def_points`` (the shape is ``(n_bounds, n_objectives, n_objectives)``) is not well explained in the paper, but basically, ``def_points[i, j] = z[j]`` of ``upper_bound_set[i]``. )dtypeTNrctj||kd}t|s||fS||}|jd}|tjtj tj |dk\}tjtj|ddtjf |}tj |df|}|j|jk(sJtj|j} ||} || | |f<|||} ||| | |f<tj||| gtj||| gfS)Naxisr) npallanyshapemaxwhereinftilearangenewaxissizevstack)solubsdps is_dominated dominated_dpsn_boundsupdateubs_indices_to_updatedimensions_to_updateindices_for_sweepingnew_dpsnew_ubs n_objectivesobjective_indicesskip_ineq_judges k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/optuna/_hypervolume/box_decomposition.pyrz$_get_upper_bound_set..update<scvvcCib1 < 8OL)  &&q)rxx"&&-PWYZZ!# ((;ArzzM(JL YZ` a!ww'88Q-HP$))-A-F-FFFF!yy)=)B)BC 56>A$&::;l#$9:>ABV>W$&::;yy#|m,g67C DVX_C`9aaar )r np.ndarrayrr*rr*returntuple[np.ndarray, np.ndarray])rr reyeboolasarrayfullr) sorted_pareto_sols ref_point_rupper_bound_set def_pointssolutionr%r&r's @@@r(_get_upper_bound_setr7s.+00Q  ,/ff\6O OAqDb8jj)-O!\<8266'BJ:CJq#%667&T&,X &S#T J &&r)c|jd}|dkDsJdtjdg|j}|ddddf|ddddf<|d|ddddf<tj|dz \}}tjj |ddd||dzf|dddddf<|ddddf|dddddf<tj |d|dkd}|dd|fS)Nrr 8This function is used only for multi-objective problems.rr r )rr empty diag_indicesmaximum accumulater)r4r5r2r%boundsrowcol not_emptys r(_get_box_boundsrCas #((,L ! WWW  XXq1?001 2F Aq)F1a7OlF1a7O|a/0HCzz,,Zb,A!S#PQ'/RF1a8&q!"u-F1a8q VAY.R88I !Y, r)ct||d }tj|d}tj|tj}t|t |d|\}}t ||| \}}||fS)Nrr Tassume_unique_lexsorted)r1r2)r7r unique full_likerrrC) r1r2neg_upper_bound_setsorted_neg_upper_bound_setpoint_at_infinityneg_lower_bound_setneg_def_pointsbox_upper_boundsbox_lower_boundss r(_get_non_dominated_box_boundsrPqs00BINqQQ!#+>Q!G Y7+?5 7QU V $ +' +:^->+*&& - --r)c0tjtj|sJdtj|d}|t |d}|j d}|dkDsJd|d kDrt jd t||S) Nz3loss_vals must be clipped before box decomposition.rr TrErr r9zBox decomposition (typically used by `GPSampler`) might be significantly slow for n_objectives > 4. Please consider using another sampler instead.) r risfiniterGrrwarningswarnrP) loss_valsr2unique_lexsorted_loss_valsr1r%s r(get_non_dominated_box_boundsrXs 66"++i( )`+`` )!#91!=33TR??2&L ! WWW a  O ));Y GGr))r1r*r2r*r+r,)r4r*r5r*r2r*r+r*)rVr*r2r*r+r,) __doc__ __future__rrTnumpyr optuna.study._multi_objectiverr7rCrPrXr)r(r^s*#:?'"?'/9?'"?'D    -7  DN    ."./9.".4HH&0H"Hr)