L i"&ddlmZddlZddlmZddlmZddlZddlm Z ddl m Z er$ddl m Z ddl mZdd lmZdd lmZdd lmZdd l mZGd dej,ZddZddZ ddZ ddZddZ ddZddZy)) annotationsN)cast) TYPE_CHECKING)intersection_search_space) TrialState)Callable) Collection)_SearchSpaceTransform)BaseDistribution)Study) FrozenTrialcNeZdZdZej ddd ddZy)BaseImportanceEvaluatorz(Abstract parameter importance evaluator.N)targetct)aEvaluate parameter importances based on completed trials in the given study. .. note:: This method is not meant to be called by library users. .. seealso:: Please refer to :func:`~optuna.importance.get_param_importances` for how a concrete evaluator should implement this method. Args: study: An optimized study. params: A list of names of parameters to assess. If :obj:`None`, all parameters that are present in all of the completed trials are assessed. target: A function to specify the value to evaluate importances. If it is :obj:`None` and ``study`` is being used for single-objective optimization, the objective values are used. Can also be used for other trial attributes, such as the duration, like ``target=lambda t: t.duration.total_seconds()``. .. note:: Specify this argument if ``study`` is being used for multi-objective optimization. For example, to get the hyperparameter importance of the first objective, use ``target=lambda t: t.values[0]`` for the target parameter. Returns: A :obj:`dict` where the keys are parameter names and the values are assessed importances. )NotImplementedError)selfstudyparamsrs ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/optuna/importance/_base.pyevaluatez BaseImportanceEvaluator.evaluates V"!N)rr rlist[str] | Noner%Callable[[FrozenTrial], float] | Nonereturndict[str, float])__name__ __module__ __qualname____doc__abcabstractmethodrrrrrsR2$(*" 9= *"*"!*" 6 *"  *"*"rrc|jdtjf}t|||t |jdS|Jd}|D]}|j t fdDs$|'ttfdj}Mtfd|jDsptdj||Jtt|jd }|S) NFdeepcopystates)r'c3&K|]}|v ywrr$).0nametrial_distributionss r z%_get_distributions..WsK44..Ksc|dvSNrr$)name_and_distributionparams_not_nones rz$_get_distributions..]s2G2Jo2]rc34K|]\}}||k7ywrr$)r*r+ distributionr,s rr-z%_get_distributions..cs' "l  % 5 sz{Parameters importances cannot be assessed with dynamic search spaces if parameters are specified. Specified parameters: {}.c |dSr/r$)r0s rr2z$_get_distributions..ns H]^_H`rkey) get_trialsrCOMPLETE_check_evaluate_argsr distributionsalldictfilteritemsany ValueErrorformatsorted)rrcompleted_trialsr;trialr1r,s @@r_get_distributionsrFHs-'' @S@S?U'V)62 ~()9)95)9)IJJO  && &M!#11K?KK    ]'--/M   &3&9&9&;  FFLfVn %.  $$ $}""$*`aM rct|dk(r tdt|dk(r td|t|ttfst dj |td|Drt dj |t|dkDr>d}|D]tfd |Dsd }n|std j |yyy) Nrz?Cannot evaluate parameter importances without completed trials.z?Cannot evaluate parameter importances with only a single trial.z>Parameters must be specified as a list. Actual parameters: {}.c3>K|]}t|t ywr) isinstancestr)r*ps rr-z'_check_evaluate_args..~s6!:a%%6szPParameters must be specified by their names with strings. Actual parameters: {}.Fc3:K|]}|jvywr)r;)r*rLrEs rr-z'_check_evaluate_args..s@AqE///@sTz\Study must contain completed trials with all specified parameters. Specified parameters: {}.) lenrArJlisttuple TypeErrorrBr@r<)rDrat_least_one_trialrEs @rr:r:ss !Z[[ !Z[[ &4-0PWWX^_  6v6 6fVn  v;?!& ) @@@)-& & 006v& rc |jdtjf}|Dcgc]X}t|t|jkr5t j |||ntd|jr|Zc}Scc}w)NFr&float) r8rr9setrnpisfinitervalue)rrrtrialsrEs r_get_filtered_trialsrZs~  uj6I6I5K  LF   v;#ell+ + KK#/F5MT'5;;5O    sABc t|tj|t|fDcic]\}}|| c}}Scc}}wr)ziprV broadcast_torN)rparam_importancesr+rXs r_param_importances_to_dictr_sE vr7H3v;.'YZ  D% e   s ?ctj|Dcgc]}|j|jc}Scc}wr)rVarray transformr)rYtransrEs r_get_trans_paramsrds, 88GuU__U\\2G HHGs"=cztj|Dcgc]}|||n |jc}Scc}wr)rVrarX)rYrrEs r_get_target_valuesrfs4 88W]^ef&8VE]ekkI^ __^s8c^ttt|jdS)Nc |dS)NrHr$)name_and_importances rr2z*_sort_dict_by_importance..s K^_`Karr6)r=reversedrCr?)r^s r_sort_dict_by_importancerks.  !'')/a   r)rr rrrzdict[str, BaseDistribution])rDlist[FrozenTrial]rrrNone)rr rCollection[str]rrrrl)rrnr^znp.ndarray | floatrr)rYrlrcr r np.ndarray)rYrlrrrro)r^rrr) __future__rr"typingrrnumpyrVoptuna.search_spacer optuna.trialrcollections.abcrr optuna._transformr optuna.distributionsr optuna.studyr r ABCrrFr:rZr_rdrfrkr$rrrzs"  9#(*75"(."cgg."b(V<   ) 3X   0BI` `'L`` r