
    &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 Z	 ed           G d d	ej
                              Z ed
          d&d            Z ed           G d dej
                              Z ed          d             Z ed           G d dej
                              Z ed          d             Z ed           G d dej
                              Z ed          d'd            Z ed           G d dej
                              Z ed           d'd!            Z ed"           G d# d$ej
                              Zd%S )(    )backend)ops)keras_export)squeeze_or_expand_to_same_rank)reduction_metricsc                 "   t          j        |          }t          j        | |j                  } t          | |          \  } }t          j        t          j        t          j        | |          t          j                              d          S Ndtypeaxis)	r   convert_to_tensorr   r   meancastequalr   floatx)y_truey_preds     _/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/metrics/accuracy_metrics.pyaccuracyr      s~    "6**F"6>>>F3FFCCNFF866**'.2B2BCCC       zkeras.metrics.Accuracyc                   *     e Zd ZdZd fd	Zd Z xZS )Accuracya/  Calculates how often predictions equal labels.

    This metric creates two local variables, `total` and `count` that are used
    to compute the frequency with which `y_pred` matches `y_true`. This
    frequency is ultimately returned as `binary accuracy`: an idempotent
    operation that simply divides `total` by `count`.

    If `sample_weight` is `None`, weights default to 1.
    Use `sample_weight` of 0 to mask values.

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

    Examples:

    >>> m = keras.metrics.Accuracy()
    >>> m.update_state([[1], [2], [3], [4]], [[0], [2], [3], [4]])
    >>> m.result()
    0.75

    >>> m.reset_state()
    >>> m.update_state([[1], [2], [3], [4]], [[0], [2], [3], [4]],
    ...                sample_weight=[1, 1, 0, 0])
    >>> m.result()
    0.5

    Usage with `compile()` API:

    ```python
    model.compile(optimizer='sgd',
                  loss='binary_crossentropy',
                  metrics=[keras.metrics.Accuracy()])
    ```
    r   Nc                 h    t                                          t          ||           d| _        d S N)fnnamer   up)super__init__r   
_directionselfr   r   	__class__s      r   r!   zAccuracy.__init__8   s-    H4u===r   c                      | j         | j        dS Nr   r   r(   r$   s    r   
get_configzAccuracy.get_config=       	DJ777r   )r   N__name__
__module____qualname____doc__r!   r*   __classcell__r%   s   @r   r   r      sW        " "H     
8 8 8 8 8 8 8r   r   zkeras.metrics.binary_accuracy      ?c                    t          j        |           } t          j        |          }t          | |          \  } }t          j        ||j                  }t          j        ||k    | j                  }t          j        t          j        t          j        | |          t          j                              d          S r	   )	r   r   r   r   r   r   r   r   r   )r   r   	thresholds      r   binary_accuracyr6   A   s    "6**F"6**F3FFCCNFFFL11IXfy(&,77F866**'.2B2BCCC   r   zkeras.metrics.BinaryAccuracyc                   *     e Zd ZdZd fd	Zd Z xZS )BinaryAccuracya  Calculates how often predictions match binary labels.

    This metric creates two local variables, `total` and `count` that are used
    to compute the frequency with which `y_pred` matches `y_true`. This
    frequency is ultimately returned as `binary accuracy`: an idempotent
    operation that simply divides `total` by `count`.

    If `sample_weight` is `None`, weights default to 1.
    Use `sample_weight` of 0 to mask values.

    Args:
        name: (Optional) string name of the metric instance.
        dtype: (Optional) data type of the metric result.
        threshold: (Optional) Float representing the threshold for deciding
        whether prediction values are 1 or 0.

    Example:

    >>> m = keras.metrics.BinaryAccuracy()
    >>> m.update_state([[1], [1], [0], [0]], [[0.98], [1], [0], [0.6]])
    >>> m.result()
    0.75

    >>> m.reset_state()
    >>> m.update_state([[1], [1], [0], [0]], [[0.98], [1], [0], [0.6]],
    ...                sample_weight=[1, 0, 0, 1])
    >>> m.result()
    0.5

    Usage with `compile()` API:

    ```python
    model.compile(optimizer='sgd',
                  loss='binary_crossentropy',
                  metrics=[keras.metrics.BinaryAccuracy()])
    ```
    r6   Nr3   c                     ||dk    s|dk    rt          d|           t                                          t          |||           || _        d| _        d S )Nr      zaInvalid value for argument `threshold`. Expected a value in interval (0, 1). Received: threshold=)r   r   r   r5   r   )
ValueErrorr    r!   r6   r5   r"   )r$   r   r   r5   r%   s       r   r!   zBinaryAccuracy.__init__v   s}     i1nn	Q3'03 3  
 	T) 	 	
 	
 	
 #r   c                 ,    | j         | j        | j        dS )Nr   r   r5   r=   r)   s    r   r*   zBinaryAccuracy.get_config   s     IZ
 
 	
r   )r6   Nr3   r,   r2   s   @r   r8   r8   N   sW        $ $L     
 
 
 
 
 
 
r   r8   z"keras.metrics.categorical_accuracyc                    t          j        | d          } d}t          j        |          }t          j        | | j                  } t          j        |           }t          |j                  }t          | j                  }|C|At          | j                  t          |j                  k    rt          j        | d          } d}t          j        |d          }|j        | j        k    rt          j        || j                  }t          j        t          j        | |          t          j
                              }|rt          j        ||          }|S )Nr   r   Fr
   T)r   argmaxr   r   shapelensqueezer   r   r   r   reshaper   r   reshape_matchesy_true_org_shapey_pred_ranky_true_rankmatchess          r   categorical_accuracyrJ      s2   ZR(((FO"6**F"6>>>Fy((fl##Kfl##K 
	 $#fl"3"333VR((ZR(((F |v|##&555hsy00'.2B2BCCG 9+g'788Nr   z!keras.metrics.CategoricalAccuracyc                   *     e Zd ZdZd fd	Zd Z xZS )CategoricalAccuracya  Calculates how often predictions match one-hot labels.

    You can provide logits of classes as `y_pred`, since argmax of
    logits and probabilities are same.

    This metric creates two local variables, `total` and `count` that are used
    to compute the frequency with which `y_pred` matches `y_true`. This
    frequency is ultimately returned as `categorical accuracy`: an idempotent
    operation that simply divides `total` by `count`.

    `y_pred` and `y_true` should be passed in as vectors of probabilities,
    rather than as labels. If necessary, use `ops.one_hot` to expand `y_true` as
    a vector.

    If `sample_weight` is `None`, weights default to 1.
    Use `sample_weight` of 0 to mask values.

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

    Example:

    >>> m = keras.metrics.CategoricalAccuracy()
    >>> m.update_state([[0, 0, 1], [0, 1, 0]], [[0.1, 0.9, 0.8],
    ...                 [0.05, 0.95, 0]])
    >>> m.result()
    0.5

    >>> m.reset_state()
    >>> m.update_state([[0, 0, 1], [0, 1, 0]], [[0.1, 0.9, 0.8],
    ...                 [0.05, 0.95, 0]],
    ...                sample_weight=[0.7, 0.3])
    >>> m.result()
    0.3

    Usage with `compile()` API:

    ```python
    model.compile(optimizer='sgd',
                  loss='categorical_crossentropy',
                  metrics=[keras.metrics.CategoricalAccuracy()])
    ```
    rJ   Nc                 h    t                                          t          ||           d| _        d S r   )r    r!   rJ   r"   r#   s      r   r!   zCategoricalAccuracy.__init__   s.    0t5IIIr   c                      | j         | j        dS r'   r(   r)   s    r   r*   zCategoricalAccuracy.get_config   r+   r   )rJ   Nr,   r2   s   @r   rL   rL      sW        + +Z     
8 8 8 8 8 8 8r   rL   z)keras.metrics.sparse_categorical_accuracyc                 B   d}t          j        |          }t          j        | | j                  } t          j        |           }t	          |j                  }t	          | j                  }|a|_t	          | j                  t	          |j                  k    r5t          j        |           d         dk    rt          j        | d          } d}t          j        |d          }|j        | j        k    rt          j        || j                  }t          j        t          j        | |          t          j
                              }|rt          j        ||          }t	          |j                  dk    r&|j        d         dk    rt          j        |d          }|S )NFr
   r   r:   Tr   )r   r   r   r@   rA   rB   r?   r   r   r   r   rC   rD   s          r   sparse_categorical_accuracyrP      sl   O"6**F"6>>>Fy((fl##Kfl##K 
	 $#fl"3"333Ifb!Q&&VR((ZR(((F |v|##&&,//hsy00'.2B2BCCG 9+g'788
7=A'-"3q"8"8+gr**Nr   z'keras.metrics.SparseCategoricalAccuracyc                   *     e Zd ZdZd fd	Zd Z xZS )SparseCategoricalAccuracyaC  Calculates how often predictions match integer labels.

    ```python
    acc = np.dot(sample_weight, np.equal(y_true, np.argmax(y_pred, axis=1))
    ```

    You can provide logits of classes as `y_pred`, since argmax of
    logits and probabilities are same.

    This metric creates two local variables, `total` and `count` that are used
    to compute the frequency with which `y_pred` matches `y_true`. This
    frequency is ultimately returned as `sparse categorical accuracy`: an
    idempotent operation that simply divides `total` by `count`.

    If `sample_weight` is `None`, weights default to 1.
    Use `sample_weight` of 0 to mask values.

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

    Example:

    >>> m = keras.metrics.SparseCategoricalAccuracy()
    >>> m.update_state([[2], [1]], [[0.1, 0.6, 0.3], [0.05, 0.95, 0]])
    >>> m.result()
    0.5

    >>> m.reset_state()
    >>> m.update_state([[2], [1]], [[0.1, 0.6, 0.3], [0.05, 0.95, 0]],
    ...                sample_weight=[0.7, 0.3])
    >>> m.result()
    0.3

    Usage with `compile()` API:

    ```python
    model.compile(optimizer='sgd',
                  loss='sparse_categorical_crossentropy',
                  metrics=[keras.metrics.SparseCategoricalAccuracy()])
    ```
    rP   Nc                 h    t                                          t          ||           d| _        d S r   )r    r!   rP   r"   r#   s      r   r!   z"SparseCategoricalAccuracy.__init__2  s.    7d%PPPr   c                      | j         | j        dS r'   r(   r)   s    r   r*   z$SparseCategoricalAccuracy.get_config7  r+   r   )rP   Nr,   r2   s   @r   rR   rR     sW        ) )V     
8 8 8 8 8 8 8r   rR   z(keras.metrics.top_k_categorical_accuracy   c                 l   d}t          j        |          }t          j        | | j                  } t          j        | d          } t	          | j                  }t	          |j                  }t          j        |           }|H|F|dk    r"t          j        |d|j        d         g          }|dk    rd}t          j        | dg          } t          j        t          j        t          j        | d          ||	          t          j
                              }|rt          j        ||          }|S )
NFr
   r   r      r:   Tint32k)r   r   r   r?   rA   r@   rC   r   in_top_kr   r   r   r   rZ   rE   rH   rG   rF   rI   s           r   top_k_categorical_accuracyr]   ;  s&   O"6**F"6>>>FZR(((Ffl##Kfl##Ky(( 	k&=??["fl2.>)?@@F??"O["..FhSXfg..!<<<n  G  9+g'788Nr   z%keras.metrics.TopKCategoricalAccuracyc                   *     e Zd ZdZd fd	Zd Z xZS )TopKCategoricalAccuracya  Computes how often targets are in the top `K` predictions.

    Args:
        k: (Optional) Number of top elements to look at for computing accuracy.
            Defaults to `5`.
        name: (Optional) string name of the metric instance.
        dtype: (Optional) data type of the metric result.

    Example:

    >>> m = keras.metrics.TopKCategoricalAccuracy(k=1)
    >>> m.update_state([[0, 0, 1], [0, 1, 0]],
    ...                [[0.1, 0.9, 0.8], [0.05, 0.95, 0]])
    >>> m.result()
    0.5

    >>> m.reset_state()
    >>> m.update_state([[0, 0, 1], [0, 1, 0]],
    ...                [[0.1, 0.9, 0.8], [0.05, 0.95, 0]],
    ...                sample_weight=[0.7, 0.3])
    >>> m.result()
    0.3

    Usage with `compile()` API:

    ```python
    model.compile(optimizer='sgd',
                  loss='categorical_crossentropy',
                  metrics=[keras.metrics.TopKCategoricalAccuracy()])
    ```
    rU   r]   Nc                 x    t                                          t          |||           || _        d| _        d S N)r   r   r   rZ   r   )r    r!   r]   rZ   r"   r$   rZ   r   r   r%   s       r   r!   z TopKCategoricalAccuracy.__init__{  sD    )	 	 	
 	
 	
 r   c                 ,    | j         | j        | j        dS Nr   r   rZ   re   r)   s    r   r*   z"TopKCategoricalAccuracy.get_config      	DJTVDDDr   )rU   r]   Nr,   r2   s   @r   r_   r_   Y  s^         @	 	 	 	 	 	E E E E E E Er   r_   z/keras.metrics.sparse_top_k_categorical_accuracyc                 @   d}t          j        |          }t          j        | | j                  } t          | j                  }t          |j                  }t          j        |           }|H|F|dk    r"t          j        |d|j        d         g          }|dk    rd}t          j        | dg          } t          j        t          j        t          j        | d          ||          t          j	                              }|rt          j        ||          }|S )	NFr
   rW   r   r:   TrX   rY   )
r   r   r   rA   r@   rC   r   r[   r   r   r\   s           r   !sparse_top_k_categorical_accuracyrh     s   O"6**F"6>>>Ffl##Kfl##Ky(( 	k&=??["fl2.>)?@@F??"O["..FhSXfg..!<<<n  G  9+g'788Nr   z+keras.metrics.SparseTopKCategoricalAccuracyc                   ,     e Zd ZdZ	 d fd	Zd Z xZS )SparseTopKCategoricalAccuracyah  Computes how often integer targets are in the top `K` predictions.

    Args:
        k: (Optional) Number of top elements to look at for computing accuracy.
            Defaults to `5`.
        name: (Optional) string name of the metric instance.
        dtype: (Optional) data type of the metric result.

    Example:

    >>> m = keras.metrics.SparseTopKCategoricalAccuracy(k=1)
    >>> m.update_state([2, 1], [[0.1, 0.9, 0.8], [0.05, 0.95, 0]])
    >>> m.result()
    0.5

    >>> m.reset_state()
    >>> m.update_state([2, 1], [[0.1, 0.9, 0.8], [0.05, 0.95, 0]],
    ...                sample_weight=[0.7, 0.3])
    >>> m.result()
    0.3

    Usage with `compile()` API:

    ```python
    model.compile(optimizer='sgd',
                  loss='sparse_categorical_crossentropy',
                  metrics=[keras.metrics.SparseTopKCategoricalAccuracy()])
    ```
    rU   rh   Nc                 x    t                                          t          |||           || _        d| _        d S ra   )r    r!   rh   rZ   r"   rb   s       r   r!   z&SparseTopKCategoricalAccuracy.__init__  sF     	0	 	 	
 	
 	
 r   c                 ,    | j         | j        | j        dS rd   re   r)   s    r   r*   z(SparseTopKCategoricalAccuracy.get_config  rf   r   )rU   rh   Nr,   r2   s   @r   rj   rj     sd         > DH     E E E E E E Er   rj   N)r3   )rU   )	keras.srcr   r   keras.src.api_exportr   keras.src.losses.lossr   keras.src.metricsr   r   MeanMetricWrapperr   r6   r8   rJ   rL   rP   rR   r]   r_   rh   rj    r   r   <module>rs      s               - - - - - - @ @ @ @ @ @ / / / / / /   &''+8 +8 +8 +8 +8 2 +8 +8 ('+8\ -..	 	 	 /.	 ,--:
 :
 :
 :
 :
&8 :
 :
 .-:
z 233  43> 12248 48 48 48 48+= 48 48 3248n 9::  ;:@ 78828 28 28 28 28 1 C 28 28 9828j 899   :9: 566-E -E -E -E -E/A -E -E 76-E` ?@@   A@8 ;<<-E -E -E -E -E$5$G -E -E =<-E -E -Er   