
    &Vf,                        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 d dlmZ d dl	m
Z
 d Z ed	           G d
 de                      Z ed           G d de                      Z ed           G d de                      ZdS )    )backend)initializers)losses)ops)keras_export)Metric)serialization_libc           	         |pt          j                    }t          | dd           }t          j        | |          } |t          j        ||          }|#t          j                            |||d          }t          j        	                    | |          \  } }t          |j                  }t          | j                  }||k    r( || t          t          ||                              } | |z  } |dk    r( ||t          t          d|                              }t          | j                  }|dk    r, || t          t          d|                              } | |fS | |fS )N_keras_maskdtypesumr   	reduction)axis   )r   floatxgetattrr   castconvert_to_tensorr   loss
apply_masksqueeze_or_expand_to_same_ranklenshapelistrange)valuessample_weight	reduce_fnr   maskweight_ndimvalues_ndims          `/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/metrics/reduction_metrics.pyreduce_to_samplewise_valuesr%   
   s   %W^%%E6=$//DXfE***F -m5III"K22t5E 3  M !' J JM!
 !
 --..&,''$$YT%["A"ABB  F -'??%IDq+)>)>$?$?  M fl##KQ6U1k-B-B(C(CDDD}$$=      zkeras.metrics.Sumc                   8     e Zd ZdZd fd	Zd	dZd Zd Z xZS )
Suma  Compute the (weighted) sum of the given values.

    For example, if `values` is `[1, 3, 5, 7]` then their sum is 16.
    If `sample_weight` was specified as `[1, 1, 0, 0]` then the sum would be 4.

    This metric creates one variable, `total`.
    This is ultimately returned as the sum value.

    Args:
        name: (Optional) string name of the metric instance.
        dtype: (Optional) data type of the metric result.

    Example:

    >>> m = metrics.Sum()
    >>> m.update_state([1, 3, 5, 7])
    >>> m.result()
    16.0

    >>> m = metrics.Sum()
    >>> m.update_state([1, 3, 5, 7], sample_weight=[1, 1, 0, 0])
    >>> m.result()
    4.0
    r   Nc                     t                                          ||           |                     dt          j                    | j        d          | _        d S )Nnamer    totalr   initializerr   r+   )super__init__add_variabler   Zerosr   r-   selfr+   r   	__class__s      r$   r1   zSum.__init__H   sW    d%000&&$*,,*	 ' 
 



r&   c                     t          ||t          j        | j                  \  }}| j                            | j        t          j        |          z              d S )Nr    r   )r%   r   r   r   r-   assign)r5   r   r   _s       r$   update_statezSum.update_stateQ   sT    /MSWDJ
 
 
	 	
$*swv677777r&   c                 :    | j                             d           d S )N        )r-   r9   r5   s    r$   reset_statezSum.reset_stateW   s    
#r&   c                 @    t          j        | j        | j                  S N)r   r   r-   r   r>   s    r$   resultz
Sum.resultZ   s    x
DJ///r&   )r   NrA   	__name__
__module____qualname____doc__r1   r;   r?   rB   __classcell__r6   s   @r$   r(   r(   -   sy         2
 
 
 
 
 
8 8 8 8  0 0 0 0 0 0 0r&   r(   zkeras.metrics.Meanc                   8     e Zd ZdZd fd	Zd	dZd Zd Z xZS )
Meana  Compute the (weighted) mean of the given values.

    For example, if values is `[1, 3, 5, 7]` then the mean is 4.
    If `sample_weight` was specified as `[1, 1, 0, 0]` then the mean would be 2.

    This metric creates two variables, `total` and `count`.
    The mean value returned is simply `total` divided by `count`.

    Args:
        name: (Optional) string name of the metric instance.
        dtype: (Optional) data type of the metric result.

    Example:

    >>> m = Mean()
    >>> m.update_state([1, 3, 5, 7])
    >>> m.result()
    4.0

    >>> m.reset_state()
    >>> m.update_state([1, 3, 5, 7], sample_weight=[1, 1, 0, 0])
    >>> m.result()
    2.0
    ```
    meanNc                    t                                          ||           |                     dt          j                    | j        d          | _        |                     dt          j                    | j        d          | _        d S )Nr*   r,   r-   r.   count)r0   r1   r2   r   r3   r   r-   rN   r4   s      r$   r1   zMean.__init__z   s    d%000&&$*,,*	 ' 
 

 &&$*,,*	 ' 
 



r&   c                    t          ||t          j        | j                  \  }}| j                            | j        t          j        |          z              t          |j                  dk    rt          j        |          d         }nd}|t          j        |          }| j	                            | j	        t          j
        || j                  z              d S )Nr8   r   r   r   )r%   r   rL   r   r-   r9   r   r   r   rN   r   )r5   r   r   num_sampless       r$   r;   zMean.update_state   s     ;MSXTZ!
 !
 !
 	
$*swv6777v|!!)F++A.KKK$'-00K
$*sx4:'N'N'NNOOOOOr&   c                 n    | j                             d           | j                            d           d S )Nr=   r   )r-   r9   rN   r>   s    r$   r?   zMean.reset_state   s4    
#
!r&   c                 r    t          j        | j        t          j        | j        | j                            S )Nr   )r   divide_no_nanr-   r   rN   r   r>   s    r$   rB   zMean.result   s1     J4:>>>
 
 	
r&   )rL   NrA   rC   rI   s   @r$   rK   rK   ^   s}         4
 
 
 
 
 
P P P P  
 
 
 
 
 
 
r&   rK   zkeras.metrics.MeanMetricWrapperc                   P     e Zd ZdZd fd	Zd fd	Z fdZed             Z xZ	S )	MeanMetricWrappera  Wrap a stateless metric function with the `Mean` metric.

    You could use this class to quickly build a mean metric from a function. The
    function needs to have the signature `fn(y_true, y_pred)` and return a
    per-sample loss array. `MeanMetricWrapper.result()` will return
    the average metric value across all samples seen so far.

    For example:

    ```python
    def mse(y_true, y_pred):
        return (y_true - y_pred) ** 2

    mse_metric = MeanMetricWrapper(fn=mse)
    ```

    Args:
        fn: The metric function to wrap, with signature
            `fn(y_true, y_pred, **kwargs)`.
        name: (Optional) string name of the metric instance.
        dtype: (Optional) data type of the metric result.
        **kwargs: Keyword arguments to pass on to `fn`.
    Nc                     t                                          ||           || _        || _        | j        t          j        v s-t          | j        d          r!| j        j        t          j        v rd| _        d S d S d S )Nr*   r6   down)	r0   r1   _fn
_fn_kwargsr   ALL_OBJECTShasattrr6   
_direction)r5   fnr+   r   kwargsr6   s        r$   r1   zMeanMetricWrapper.__init__   s    d%000 
 H***tx-- +"f&888$DOOO	 +*88r&   c                     t          |dd           } | j        ||fi | j        }|*|(t          j                            ||| j        d          }t                                          ||          S )Nr   r   r   )r   )	r   rX   rY   r   r   r   r   r0   r;   )r5   y_truey_predr   r!   r   r6   s         r$   r;   zMeanMetricWrapper.update_state   s    v}d33&&<<DO<<$)9"K22t4: 3  M ww##F-#HHHr&   c                     t                                                      }dt          j        | j                  i}|                    t          j        | j                             i ||S )Nr]   )r0   
get_configr	   serialize_keras_objectrX   updaterY   )r5   base_configconfigr6   s      r$   rc   zMeanMetricWrapper.get_config   s`    gg((**)@JJK'>tOOPPP(+(((r&   c                 B    d|v rt          j        |          } | di |S )Nr]   r,   )r	   deserialize_keras_object)clsrg   s     r$   from_configzMeanMetricWrapper.from_config   s-    6>>&?GGFs}}V}}r&   )NNrA   )
rD   rE   rF   rG   r1   r;   rc   classmethodrk   rH   rI   s   @r$   rU   rU      s         0% % % % % %I I I I I I) ) ) ) )   [    r&   rU   N)	keras.srcr   r   r   r   keras.src.api_exportr   keras.src.metrics.metricr   keras.src.savingr	   r%   r(   rK   rU   r,   r&   r$   <module>rq      se         " " " " " "             - - - - - - + + + + + + . . . . . . !  !  !F !""-0 -0 -0 -0 -0& -0 -0 #"-0` "##>
 >
 >
 >
 >
6 >
 >
 $#>
B /00: : : : : : : 10: : :r&   