L i1ddlmZddlZddlmZddlZddlmZddl m Z ddl m Z ddl m Z ddlmZd ZGd d ej" Zed GddeZed ddZed GddeZy)) annotationsN)cast)experimental_class)StudyDirection) FrozenTrial)Trial) TrialStatezterminator:cv_scorescBeZdZdZej ddZy)BaseErrorEvaluatorz Base class for error evaluators.cyNselftrialsstudy_directions a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/optuna/terminator/erroreval.pyevaluatezBaseErrorEvaluator.evaluates Nrzlist[FrozenTrial]rrreturnfloat)__name__ __module__ __qualname____doc__abcabstractmethodrrrrr r s9* ! (     rr ) metaclassz3.2.0c$eZdZdZ ddZy)CrossValidationErrorEvaluatoraAn error evaluator for objective functions based on cross-validation. This evaluator evaluates the objective function's statistical error, which comes from the randomness of dataset. This evaluator assumes that the objective function is the average of the cross-validation and uses the scaled variance of the cross-validation scores in the best trial at the moment as the statistical error. c|Dcgc]"}|jtjk(s!|$}}t|dkDsJ|tj k(rt |d}nt|d}|j}t|vr |t}n tdt|}|dkDsJdd|z d|dz z z}|tj|z} tj| } t| Scc}w)aEvaluate the statistical error of the objective function based on cross-validation. Args: trials: A list of trials to consider. The best trial in ``trials`` is used to compute the statistical error. study_direction: The direction of the study. Returns: A float representing the statistical error of the objective function. rc6tt|jSr rrvaluets rz8CrossValidationErrorEvaluator.evaluate..@4qww3Gr)keyc6tt|jSr r$r&s rr(z8CrossValidationErrorEvaluator.evaluate..Br)rzCross-validation scores have not been reported. Please call `report_cross_validation_scores(trial, scores)` during a trial and pass the list of scores as `scores`.z9Should be guaranteed by `report_cross_validation_scores`.)stater COMPLETElenrMAXIMIZEmaxmin system_attrs_CROSS_VALIDATION_SCORES_KEY ValueErrornpvarsqrtr) rrrtrial best_trialbest_trial_attrs cv_scoreskscaler7stds rrz&CrossValidationErrorEvaluator.evaluate)s&&,REu{{j>Q>Q/Q%RR6{Q n55 5V)GHJV)GHJ%22 '+; ;()EFI.   N1uQQQuAQU #bffY''ggclSz3Ss "C4C4Nr)rrrrrrrrr!r!s(,!,(,  ,rr!ct|dkr td|jj|jt |y)aA function to report cross-validation scores of a trial. This function should be called within the objective function to report the cross-validation scores. The reported scores are used to evaluate the statistical error for termination judgement. Args: trial: A :class:`~optuna.trial.Trial` object to report the cross-validation scores. scores: The cross-validation scores of the trial. r,z:The length of `scores` is expected to be greater than one.N)r/r5storageset_trial_system_attr _trial_idr4)r9scoress rreport_cross_validation_scoresrEXs8 6{aUVV MM''9UW]^rc,eZdZdZddZ ddZy)StaticErrorEvaluatora7An error evaluator that always returns a constant value. This evaluator can be used to terminate the optimization when the evaluated improvement potential is below the fixed threshold. Args: constant: A user-specified constant value to always return as an error estimate. c||_yr  _constant)rconstants r__init__zStaticErrorEvaluator.__init__ys !rc|jSr rIrs rrzStaticErrorEvaluator.evaluate|s ~~rN)rKrrNoner)rrrrrLrrrrrGrGls- "!(  rrG)r9rrDz list[float]rrN) __future__rrtypingrnumpyr6optuna._experimentalr optuna.studyr optuna.trialrroptuna.trial._stater r4ABCMetar r!rErGrrrrWs" 3'$* 6  3;;  G6$666rG__&G-r