
    ijX                     F    d dl Z d dlmZ d dlmZ d dlmZ  G d de      Zy)    N)ops)Callback)compile_utilsc                   8     e Zd ZdZ	 	 	 	 d fd	Zd Zd Z xZS )MonitorCallbacka  Base class for callbacks that monitor a quantity and evaluates
    improvements.

    This class provides common functionality for callbacks that monitor a
    metric during training to determine whether a condition has been met,
    such as improvement over time. It encapsulates logic for selecting
    the comparison operation based on a `monitor` value and `mode`, and
    computing whether a new value is an improvement.

    It is intended to be subclassed by other callbacks like `ModelCheckpoint`,
    `EarlyStopping`, or `ReduceLROnPlateau`, and is not meant to be used
    directly.

    Arguments:
        monitor: Quantity to be monitored. Defaults to `"val_loss"`.
        mode: One of `{"auto", "min", "max"}`. In `min` mode, training will aim
            to minimize the monitored quantity; in `'max'` mode it will aim to
            maximize it.; in `"auto"` mode, the direction is automatically
            inferred from the name of the monitored quantity. Defaults to
            `"auto"`.
        baseline: Floating point initial "best" value of the metric to be
            monitored. If `None` (default), the first monitored value will be
            used.
        min_delta: Minimum change in the monitored quantity to qualify as an
            improvement, i.e. an absolute change of less than min_delta, will
            count as no improvement. Defaults to `0`.

    Raises:
        ValueError: If `mode='auto'` is selected and the direction of the metric
        cannot be inferred.
    c                     t         |           |dvr3t        j                  | j                  j
                   d| dd       d}|| _        || _        || _        t        |      | _
        d | _        y )N)autominmaxz mode 'z$' is unknown, fallback to auto mode.   )
stacklevelr	   )super__init__warningswarn	__class____name__monitormodebestabs	min_delta
monitor_op)selfr   r   baseliner   r   s        y/var/www/html/emotional.easysim.app/public_html/venv/lib/python3.12/site-packages/keras/src/callbacks/monitor_callback.pyr   zMonitorCallback.__init__)   sv     	--MM>>**+74& 9   
 D		Y    c                    | j                   dk(  rt        j                  | _        nm| j                   dk(  rt        j                  | _        nG| j
                  j                  d      }|dk(  rt        j                  | _        t        | j                  d      rg }| j                  j                  D ]H  }t        |t        j                  t        j                  f      s.|j                  |j                         J |D ]Y  }|j                  |k(  st        |d      s |j                   dk(  rt        j                  | _        Et        j                  | _        [ | j                  /t#        | j$                  j&                   d| j
                   d	      | j                  t        j                  k(  r| xj(                  d
z  c_        y y )Nr
   r   val_lossmetrics
_directionupz callback received monitor=z, but Keras isn't able to automatically determine whether that metric should be maximized or minimized. Pass `mode='max'` in order to monitor based on the highest metric value, or pass `mode='min'` in order to use the lowest value.)r   r   lessr   greaterr   removeprefixhasattrmodelr!   
isinstancer   CompileMetricsMetricsListextendnamer"   
ValueErrorr   r   r   )r   metric_nameall_metricsms       r   _set_monitor_opzMonitorCallback._set_monitor_op>   sj   99!hhDOYY%!kkDO,,33F;Kf$"%((tzz9- ++ 6A!)88)55 $**19956 % ;Avv,"1l3 ||t325++25((; & ~~../ 0#||n -EE  ??chh&NNb N 'r   c                 F    |y| j                  || j                  z
  |      S )NT)r   r   )r   monitor_valuereference_values      r   _is_improvementzMonitorCallback._is_improvemente   s%    "}t~~=OOr   )val_lossr	   Nr   )r   
__module____qualname____doc__r   r3   r7   __classcell__)r   s   @r   r   r      s(    D *%!NPr   r   )r   	keras.srcr   keras.src.callbacks.callbackr   keras.src.trainersr   r    r   r   <module>rA      s!      1 ,`Ph `Pr   