L iV+ddlmZddlmZddlmZddlZddlZddl m Z ddl m Z ddl mZddl mZ d dd Z d dd Zddd  dd Zdd ZddZddZddZdd ddZ ddZddZy)) annotations)Sequence)castN)_get_feasible_trials)StudyDirection) FrozenTrial) TrialStatec|Dcgc]"}|jtjk(s!|$}}|r t|}t |dk(rgSt fd|Dr t dtj|Dcgc]5}t|jDcgc]\}}t||c}}7c}}}}t|d}t||Dcgc] \}}|s | c}}Scc}wcc}}wcc}}}wcc}}w)Nrc3`K|]%}t|jtk7'ywN)lenvalues).0t directionss c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/optuna/study/_multi_objective.py z5_get_pareto_front_trials_by_trials..s" <3qxx=C O + `__, but the handling of the case when penalty values are None is different. The algorithm assigns the rank according to the following rules: 1. Feasible trials: First, the algorithm assigns the rank to feasible trials, whose penalty values are less than or equal to 0, according to unconstrained version of fast non- dominated sort. 2. Infeasible trials: Next, the algorithm assigns the rank from the minimum penalty value of to the maximum penalty value. 3. Trials with no penalty information (constraints value is None): Finally, The algorithm assigns the rank to trials with no penalty information according to unconstrained version of fast non-dominated sort. Note that only this step is different from the original constrained NSGA-II algorithm. Plus, the algorithm terminates whenever the number of sorted trials reaches n_below. Args: loss_values: Objective values, which is better when it is lower, of each trials. penalty: Constraints values of each trials. Defaults to None. n_below: The minimum number of top trials required to be sorted. The algorithm will terminate when the number of sorted trials reaches n_below. Defaults to None. Returns: An ndarray in the shape of (n_trials,), where each element is the non-domination rank of each trial. The rank is 0-indexed. This function guarantees the correctness of the ranks only up to the top-``n_below`` solutions. If a solution's rank is worse than the top-``n_below`` solution, its rank will be guaranteed to be greater than the rank of the top-``n_below`` solution. rdtypez#n_below must be a positive integer.Nr,zIThe length of penalty and loss_values must be same, but got len(penalty)=z and len(loss_values)=.)initialzAll the rank must be updated.) r rarrayint_calculate_nondomination_rankrfullisnan logical_and count_nonzeromaxnewaxisall) r#r+r,ranksis_penalty_nan is_feasible is_infeasibletop_rank_infeasibletop_rank_penalty_nans r_fast_non_domination_rankrE-sL ;1xx#&&)[)G Q;===;,['JJ 7|s;'' 7|o43{#3"5Q 8  GGC $b 4EXXg&N...'Q,?KNNN?GaK@M7{;7OY`aE+ s2##K011G&&{!3R@1D.1N q"**}-w2E- s2##M233G66%"8"EI03PN#W4E. 66%2+ ? ??  Lr*c|ddddf}|jd}tj|t}tj|}t |rd||dx}<tj ||||kd}ttjtttjtjf||}t |r|S)Nr4rr.T)axis) shaperzerosboolaranger rrndarraytupler6r/ signedinteger)unique_lexsorted_loss_valuesr#n_trialsr$remaining_indicesnew_nondominated_indexnondominated_and_not_tops r_is_pareto_front_ndrT{s/q!"u5K  #Hxx-HLNIIV^L_  FJ,=a,@@(B#%66 ) *[9O-P PWX$  ! JJuSz288B,<,<#== > 6 7    Or*c|jd}tjj|dddf}tj|t }|dd|ddk|dd|S)Nrr4r.r2)rHrminimum accumulateonesrJ)rOrP cummin_value1r$s r_is_pareto_front_2drZsc+11!4HJJ))*Fq!t*LMMwwxt,H $}Sb'99HQRL Or*c|j\}}|dk(r+tjt|t}d|d<|S|dk(r t |St |S)Nr4r.Tr)rHrrIr rJrZrT)rOrP n_objectivesr$s r"_is_pareto_front_for_unique_sortedr^s^;AAX|q88C <=TJ   "#?@@"#?@@r*c|r t|Stj|dd\}}t|}||jdS)NrT)rGreturn_inverser2)r^runiquereshape)r#rrO order_invr$s rrrsN 1+>>.0ii !\`.a+ )12NOH I%%b) **r*r0ct|dk(s|)|dkr$tjt|tS|j\}}|dk(r#tj |dddfd\}}|Stj |dd\}}|jd}t |xs t|t|}tj|t}d} tj|} || jz |kr9t|d} | || | <| | } || }| dz } || jz |kr9| || <||jdS) Nrr.r4T)r`)r`rGrr2) r rrIr6rHraminrKsizerrb) r#r,rPr]_r?rOrcn_uniquerankindicesr$s rr7r7s^ ;1!4AxxK(44*00X|q99[A.tD5 /1ii TX_`.a+ )+11!4H'>S!=>D`@abG HHXS )E Dii!G W\\ !G +#$@Z^_#'gh 8)$'CXI'N$   W\\ !G +E'N ""2& ''r*c>|j}|j}|jtjk7ry|jtjk7ry|J|Jt |t |k7r t dt |t |k7r t dt ||Dcgc]\}}t||}}}t ||Dcgc]\}}t||}}}||k(rytdt ||DScc}}wcc}}w)NFTz?Trials with different numbers of objectives cannot be compared.zIThe number of the values and the number of the objectives are mismatched.c3,K|] \}}||kywr )rv0v1s rrz_dominates..sRFBrRxRs) rrr rr rrrr>) trial0trial1rvalues0values1r!r"normalized_values0normalized_values1s r _dominatesrvsmmGmmG ||z*** ||z***       7|s7|#Z[[ 7|s:& W  >A*=UVTQ*1a0VV=@*=UVTQ*1a0VV// Rc*<>P&QR RR WVs 0DDcJ| tdS|tjur| }|S)Ninf)floatrMAXIMIZE)value directions rrrs+ }U|N+++ Lr*)F)rzSequence[FrozenTrial]rSequence[StudyDirection]r rJreturnlist[FrozenTrial])r(z'optuna.study.Study'r rJr~r)r# np.ndarrayr+znp.ndarray | Noner, int | Noner~r)rOrr~r)r#rrrJr~r)r#rr,rr~r)rprrqrrr}r~rJ)r{z float | Noner|rr~ry) __future__rcollections.abcrtypingrnumpyroptuna&optuna.study._constrained_optimizationroptuna.study._study_directionr optuna.trialrr r&r)rErTrZr^rr7rvrrmr*rrs"$ G8$# !&F !F(FF F2>Cc c6:cc>BY]KK):KLVKK\. A +"7; ( ()3 ( (FS S!,S:RS S@r*