Ë
    þÍ:j×  ã                  ó‚   — 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	 erd dl
mZ d dlmZ dd	„Z G d
„ de«      Zy)é    )ÚannotationsN)ÚAny)ÚTYPE_CHECKING)Ú
BasePruner)Ú_is_first_in_interval_step)ÚStudy)ÚFrozenTrialc                óŽ   — 	 t        | «      } | S # t        t        f$ r& dt        | «      j                  › d�}t        |«      d ‚w xY w)Nz!The `value` argument is of type 'z' but supposed to be a float.)ÚfloatÚ	TypeErrorÚ
ValueErrorÚtypeÚ__name__)ÚvalueÚmessages     ún/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/optuna/pruners/_threshold.pyÚ_check_valuer      sY   € ð+ä�e“ˆð €Løô ”zÐ"ò +à/´°U³×0DÑ0DÐ/EÐEbÐcð 	ô ˜Ó  dÐ*ð	+ús	   ‚ �5Ac                  ó<   — e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 	 	 dd„Zdd„Zy)ÚThresholdPruneraÎ  Pruner to detect outlying metrics of the trials.

    Prune if a metric exceeds upper threshold,
    falls behind lower threshold or reaches ``nan``.

    Example:
        .. testcode::

            from optuna import create_study
            from optuna.pruners import ThresholdPruner
            from optuna import TrialPruned


            def objective_for_upper(trial):
                for step, y in enumerate(ys_for_upper):
                    trial.report(y, step)

                    if trial.should_prune():
                        raise TrialPruned()
                return ys_for_upper[-1]


            def objective_for_lower(trial):
                for step, y in enumerate(ys_for_lower):
                    trial.report(y, step)

                    if trial.should_prune():
                        raise TrialPruned()
                return ys_for_lower[-1]


            ys_for_upper = [0.0, 0.1, 0.2, 0.5, 1.2]
            ys_for_lower = [100.0, 90.0, 0.1, 0.0, -1]

            study = create_study(pruner=ThresholdPruner(upper=1.0))
            study.optimize(objective_for_upper, n_trials=10)

            study = create_study(pruner=ThresholdPruner(lower=0.0))
            study.optimize(objective_for_lower, n_trials=10)

    Args:
        lower:
            A minimum value which determines whether pruner prunes or not.
            If an intermediate value is smaller than lower, it prunes.
        upper:
            A maximum value which determines whether pruner prunes or not.
            If an intermediate value is larger than upper, it prunes.
        n_warmup_steps:
            Pruning is disabled if the step is less than the given number of warmup steps.
        interval_steps:
            Interval in number of steps between the pruning checks, offset by the warmup steps.
            If no value has been reported at the time of a pruning check, that particular check
            will be postponed until a value is reported. Value must be at least 1.

    Nc                ó<  — |€|€t        d«      ‚|�t        |«      }|�t        |«      }|�|nt        d«       }|�|n
t        d«      }||kD  rt        d«      ‚|dk  rt        d|› d�«      ‚|dk  rt        d|› d�«      ‚|| _        || _        || _        || _        y )	Nz(Either lower or upper must be specified.Úinfz#lower should be smaller than upper.r   z2Number of warmup steps cannot be negative but got ú.é   z2Pruning interval steps must be at least 1 but got )r   r   r   r   Ú_lowerÚ_upperÚ_n_warmup_stepsÚ_interval_steps)ÚselfÚlowerÚupperÚn_warmup_stepsÚinterval_stepss        r   Ú__init__zThresholdPruner.__init__V   sÖ   € ð ˆ=˜U˜]ÜÐFÓGÐGØÐÜ  Ó'ˆEØÐÜ  Ó'ˆEàÐ*‘´°u³°ˆØÐ*‘´°e³ˆà�5Š=ÜÐBÓCÐCØ˜AÒÜØDÀ^ÐDTÐTUÐVóð ð ˜AÒÜØDÀ^ÐDTÐTUÐVóð ð ˆŒØˆŒØ-ˆÔØ-ˆÕó    c                ó2  — |j                   }|€y| j                  }||k  ryt        ||j                  j	                  «       || j
                  «      sy|j                  |   }t        j                  |«      ry|| j                  k  ry|| j                  kD  ryy)NFT)
Ú	last_stepr   r   Úintermediate_valuesÚkeysr   ÚmathÚisnanr   r   )r   ÚstudyÚtrialÚstepr!   Úlatest_values         r   ÚprunezThresholdPruner.prunew   s”   € Ø�‰ˆØˆ<Øà×-Ñ-ˆØ�.Ò Øä)Ø�%×+Ñ+×0Ñ0Ó2°NÀD×DXÑDXô
ð à×0Ñ0°Ñ6ˆÜ�:‰:�lÔ#Øà˜$Ÿ+™+Ò%Øà˜$Ÿ+™+Ò%Øàr$   )NNr   r   )
r   úfloat | Noner    r0   r!   Úintr"   r1   ÚreturnÚNone)r+   r   r,   r	   r2   Úbool)r   Ú
__module__Ú__qualname__Ú__doc__r#   r/   © r$   r   r   r      sQ   „ ñ6ðt #Ø"ØØð.àð.ð ð.ð ð	.ð
 ð.ð 
ó.ôBr$   r   )r   r   r2   r   )Ú
__future__r   r)   Útypingr   r   Úoptuna.prunersr   Úoptuna.pruners._percentiler   Úoptuna.studyr   Úoptuna.trialr	   r   r   r8   r$   r   ú<module>r?      s5   ðÝ "ã Ý Ý  å %Ý Añ Ý"Ý(ó
ôr�jõ rr$   