
    0h$                        d 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  ed       G d	 d
e	j                               Z ed       G d de	j                               Z ed       G d de	j                               Zy)zHinge metrics.    )utils)categorical_hinge)hinge)squared_hinge)base_metric)keras_exportzkeras.metrics.Hingec                   B     e Zd ZdZej
                  d fd	       Z xZS )Hingea  Computes the hinge metric between `y_true` and `y_pred`.

    `y_true` values are expected to be -1 or 1. If binary (0 or 1) labels are
    provided we will convert them to -1 or 1.

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

    Standalone usage:

    >>> m = tf.keras.metrics.Hinge()
    >>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]])
    >>> m.result().numpy()
    1.3

    >>> m.reset_state()
    >>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]],
    ...                sample_weight=[1, 0])
    >>> m.result().numpy()
    1.1

    Usage with `compile()` API:

    ```python
    model.compile(
        optimizer='sgd', loss='mse', metrics=[tf.keras.metrics.Hinge()])
    ```
    c                 2    t         |   t        ||       y N)dtype)super__init__r   selfnamer   	__class__s      \/var/www/html/engine/venv/lib/python3.12/site-packages/tf_keras/src/metrics/hinge_metrics.pyr   zHinge.__init__;   s    E2    )r   N__name__
__module____qualname____doc__dtensor_utilsinject_meshr   __classcell__r   s   @r   r
   r
      s"    < 3 3r   r
   zkeras.metrics.SquaredHingec                   B     e Zd ZdZej
                  d fd	       Z xZS )SquaredHingeaC  Computes the squared hinge metric between `y_true` and `y_pred`.

    `y_true` values are expected to be -1 or 1. If binary (0 or 1) labels are
    provided we will convert them to -1 or 1.

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

    Standalone usage:

    >>> m = tf.keras.metrics.SquaredHinge()
    >>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]])
    >>> m.result().numpy()
    1.86

    >>> m.reset_state()
    >>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]],
    ...                sample_weight=[1, 0])
    >>> m.result().numpy()
    1.46

    Usage with `compile()` API:

    ```python
    model.compile(
        optimizer='sgd',
        loss='mse',
        metrics=[tf.keras.metrics.SquaredHinge()])
    ```
    c                 2    t         |   t        ||       y r   )r   r   r   r   s      r   r   zSquaredHinge.__init__b   s    E:r   )r   Nr   r   s   @r   r    r    @   s#    @ ; ;r   r    zkeras.metrics.CategoricalHingec                   B     e Zd ZdZej
                  d fd	       Z xZS )CategoricalHingea  Computes the categorical hinge metric between `y_true` and `y_pred`.

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

    Standalone usage:

    >>> m = tf.keras.metrics.CategoricalHinge()
    >>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]])
    >>> m.result().numpy()
    1.4000001

    >>> m.reset_state()
    >>> m.update_state([[0, 1], [0, 0]], [[0.6, 0.4], [0.4, 0.6]],
    ...                sample_weight=[1, 0])
    >>> m.result().numpy()
    1.2

    Usage with `compile()` API:

    ```python
    model.compile(
        optimizer='sgd',
        loss='mse',
        metrics=[tf.keras.metrics.CategoricalHinge()])
    ```
    c                 2    t         |   t        ||       y r   )r   r   r   r   s      r   r   zCategoricalHinge.__init__   s    *D>r   )r   Nr   r   s   @r   r#   r#   g   s"    : ? ?r   r#   N)r   tf_keras.src.dtensorr   r   tf_keras.src.lossesr   r   r   tf_keras.src.metricsr    tensorflow.python.util.tf_exportr   MeanMetricWrapperr
   r    r#    r   r   <module>r+      s     7 1 % - , : #$!3K)) !3 %!3H *+#;;00 #; ,#;L ./ ?{44  ? 0 ?r   