Ë
    þÍ:j�  ã                  óJ  — d dl mZ d dlZd dlmZ d dlmZ d dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ erd d
lmZ d dlmZ dZ e	j,                  ddd¬«      Z G d„ dej0                  ¬«      Z ed«       G d„ de«      «       Zdd„Z ed«       G d„ de«      «       Zy)é    )ÚannotationsN)Úcast)ÚTYPE_CHECKING)Ú_DEPRECATION_WARNING_TEMPLATE)Úexperimental_class)Úoptuna_warn)ÚStudyDirection)Ú
TrialState)ÚFrozenTrial)ÚTrialzterminator:cv_scoresz`optuna.terminator` modulez4.9.0z6.0.0)ÚnameÚd_verÚr_verc                  óB   — e Zd ZdZej
                  	 	 	 	 	 	 dd„«       Zy)ÚBaseErrorEvaluatorz Base class for error evaluators.c                 ó   — y ©N© ©ÚselfÚtrialsÚstudy_directions      úp/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/optuna/terminator/erroreval.pyÚevaluatezBaseErrorEvaluator.evaluate    s   € ð 	ó    N©r   zlist[FrozenTrial]r   r	   ÚreturnÚfloat)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚabcÚabstractmethodr   r   r   r   r   r      s9   „ Ù*à×Ñðà!ðð (ðð 
ò	ó ñr   r   )Ú	metaclassz3.2.0c                  ó$   — e Zd ZdZ	 	 	 	 	 	 dd„Zy)ÚCrossValidationErrorEvaluatora�  An 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                óò  — |D �cg c]"  }|j                   t        j                  k(  sŒ!|‘Œ$ }}t        |«      dkD  sJ ‚|t        j
                  k(  rt        |d„ ¬«      }nt        |d„ ¬«      }|j                  }t        |v r
|t           }nt        d«      ‚t        |«      }|dkD  sJ d«       ‚d|z  d|dz
  z  z   }|t        j                  |«      z  }	t        j                  |	«      }
t        |
«      S c c}w )a³  Evaluate 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.

        r   c                ó.   — t        d| j                  «      S ©Nr   ©r   Úvalue©Úts    r   ú<lambda>z8CrossValidationErrorEvaluator.evaluate.<locals>.<lambda>K   ó   € ´4¸ÀÇÁÓ3I€ r   )Úkeyc                ó.   — t        d| j                  «      S r*   r+   r-   s    r   r/   z8CrossValidationErrorEvaluator.evaluate.<locals>.<lambda>M   r0   r   z£Cross-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
   ÚCOMPLETEÚlenr	   ÚMAXIMIZEÚmaxÚminÚsystem_attrsÚ_CROSS_VALIDATION_SCORES_KEYÚ
ValueErrorÚnpÚvarÚsqrtr   )r   r   r   ÚtrialÚ
best_trialÚbest_trial_attrsÚ	cv_scoresÚkÚscaler>   Ústds              r   r   z&CrossValidationErrorEvaluator.evaluate4   sõ   € ð& &,ÖR˜E¨u¯{©{¼j×>QÑ>QÓ/Q’%ÐRˆÐRÜ�6‹{˜QŠÐˆàœn×5Ñ5Ò5Ü˜VÑ)IÔJ‰Jä˜VÑ)IÔJˆJà%×2Ñ2ÐÜ'Ð+;Ñ;Ø(Ô)EÑF‰Iäð.óð ô �	‹NˆØ�1ŠuÐQÐQÓQˆuØ�A‘˜˜Q ™U™Ñ#ˆà”b—f‘f˜YÓ'Ñ'ˆÜ�g‰g�c‹lˆä�S‹zÐùò3 Ss
   …"C4¨C4Nr   )r   r    r!   r"   r   r   r   r   r'   r'   )   s(   „ ñð,à!ð,ð (ð,ð 
ô	,r   r'   c                ó´   — t        t        t        «       t        |«      dk  rt	        d«      ‚| j
                  j                  | j                  t        |«       y)aÂ  A 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.

    r3   z:The length of `scores` is expected to be greater than one.N)	r   Ú_DEPRECATION_WARNING_MESSAGEÚFutureWarningr6   r<   ÚstorageÚset_trial_system_attrÚ	_trial_idr;   )r@   Úscoress     r   Úreport_cross_validation_scoresrN   c   sC   € ô Ô,¬mÔ<ä
ˆ6ƒ{�aÒÜÐUÓVÐVØ	‡M�M×'Ñ'¨¯©Ô9UÐW]Õ^r   c                  ó,   — e Zd ZdZdd„Z	 	 	 	 	 	 dd„Zy)ÚStaticErrorEvaluatora7  An 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                ó   — || _         y r   ©Ú	_constant)r   Úconstants     r   Ú__init__zStaticErrorEvaluator.__init__…   s	   € Ø!ˆ�r   c                ó   — | j                   S r   rR   r   s      r   r   zStaticErrorEvaluator.evaluateˆ   s   € ð
 �~‰~Ðr   N)rT   r   r   ÚNoner   )r   r    r!   r"   rU   r   r   r   r   rP   rP   x   s-   „ ñ	ó"ðà!ðð (ðð 
ô	r   rP   )r@   r   rM   zlist[float]r   rW   )Ú
__future__r   r#   Útypingr   r   Únumpyr=   Úoptuna._deprecatedr   Úoptuna._experimentalr   Úoptuna._warningsr   Úoptuna.studyr	   Úoptuna.trial._stater
   Úoptuna.trialr   r   r;   ÚformatrH   ÚABCMetar   r'   rN   rP   r   r   r   ú<module>rc      s¬   ðÝ "ã 
Ý Ý  ã å <Ý 3Ý (Ý 'Ý *ñ Ý(Ý"ð  6Ð ØCÐ<×CÑCØ	%Ø
Ø
ô Ð ô	 3§;¡;õ 	ñ �GÓô6Ð$6ó 6ó ð6ór_ñ* �GÓôÐ-ó ó ñr   