Ë
    ÿÿæin  ã                  ó  — 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 erd dlmZ d d	lmZ d
Z G d„ dej$                  ¬«      Z e	d«       G d„ de«      «       Z e	d«      dd„«       Z e	d«       G d„ de«      «       Zy)é    )ÚannotationsN)Úcast)ÚTYPE_CHECKING)Úexperimental_class)ÚStudyDirection)Ú
TrialState)ÚFrozenTrial)ÚTrialzterminator:cv_scoresc                  ó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/Volumes/fast/ai/experiments/voice-extract-mac/.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                ó6   — t        t        | j                  «      S r   ©r   r   Úvalue©Úts    r   Ú<lambda>z8CrossValidationErrorEvaluator.evaluate.<locals>.<lambda>D   ó   € ´4¼¸q¿w¹wÔ3Gr   )Úkeyc                ó6   — t        t        | j                  «      S r   r%   r'   s    r   r)   z8CrossValidationErrorEvaluator.evaluate.<locals>.<lambda>F   r*   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Úscaler8   Ústds              r   r   z&CrossValidationErrorEvaluator.evaluate-   sö   € ñ& &,ÓR¡V˜E¨u¯{©{¼j×>QÑ>QÓ/Q’% VˆÐRÜ�6‹{˜QŠÐˆàœn×5Ñ5Ò5Ü˜VÑ)GÔH‰Jä˜VÑ)GÔHˆ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        |«      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.

    r-   z:The length of `scores` is expected to be greater than one.N)r0   r6   ÚstorageÚset_trial_system_attrÚ	_trial_idr5   )r:   Úscoress     r   Úreport_cross_validation_scoresrF   \   s8   € ô ˆ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   rJ   r   s      r   r   zStaticErrorEvaluator.evaluate€   s   € ð
 �~‰~Ðr   N)rL   r   r   ÚNoner   )r   r   r   r   rM   r   r   r   r   rH   rH   p   s-   „ ñ	ó"ðà!ðð (ðð 
ô	r   rH   )r:   r
   rE   zlist[float]r   rO   )Ú
__future__r   r   Útypingr   r   Únumpyr7   Úoptuna._experimentalr   Úoptuna.studyr   Úoptuna.trial._stater   Úoptuna.trialr	   r
   r5   ÚABCMetar   r"   rF   rH   r   r   r   Ú<module>rX      sž   ðÝ "ã 
Ý Ý  ã å 3Ý 'Ý *ñ Ý(Ý"ð  6Ð ô	 3§;¡;õ 	ñ �GÓô6Ð$6ó 6ó ð6ñr �GÓò_ó ð_ñ& �GÓôÐ-ó ó ñr   