
    (^i                    b    d dl mZ d dlZd dlmZ d dlZd dlmZ d dlm	Z	 d	dZ
 G d de      Zy)
    )annotationsN)Any)
BasePruner)_is_first_in_interval_stepc                    	 t        |       } | S # t        t        f$ r1 dj                  t	        |       j
                        }t        |      d w xY w)Nz@The `value` argument is of type '{}' but supposed to be a float.)float	TypeError
ValueErrorformattype__name__)valuemessages     Z/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/optuna/pruners/_threshold.py_check_valuer      sY    +e L z" +T[[K  
  d*	+s
    A A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                h   ||t        d      |t        |      }|t        |      }||nt        d       }||n
t        d      }||kD  rt        d      |dk  rt        dj	                  |            |dk  rt        dj	                  |            || _        || _        || _        || _        y )Nz(Either lower or upper must be specified.infz#lower should be smaller than upper.r   z5Number of warmup steps cannot be negative but got {}.   z5Pruning interval steps must be at least 1 but got {}.)	r	   r   r   r
   r   _lower_upper_n_warmup_steps_interval_steps)selfloweruppern_warmup_stepsinterval_stepss        r   __init__zThresholdPruner.__init__Q   s     =U]FGG 'E 'E*u*e5=BCCAGNN~^  AGNN~^  --    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.pruner   s    <--. )%++002NDDXDX
 006::l#$++%$++%r!   )NNr   r   )
r   float | Noner   r-   r   intr   r.   returnNone)r(   z'optuna.study.Study'r)   z'optuna.trial.FrozenTrial'r/   bool)r   
__module____qualname____doc__r    r,    r!   r   r   r      sQ    6t #".. . 	.
 . 
.Br!   r   )r   r   r/   r   )
__future__r   r&   typingr   optunaoptuna.prunersr   optuna.pruners._percentiler   r   r   r5   r!   r   <module>r;      s*    "    % A
rj rr!   