Ë
    8Ò^j/  ã                   ó²   — d Z ddlZddlmZ ddlmZ d„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zeee
e	eedœZd„ Zd„ Zd„ Zd„ ZeeeedœZdd„Zdd„Zdd„Zdd„ZeeeedœZy)z(Utilities for the neural network modulesé    N)Úexpit)Úxlogyc                  ó   — y)zûSimply leave the input array unchanged.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        Data, where `n_samples` is the number of samples
        and `n_features` is the number of features.
    N© ©ÚXs    úg/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/sklearn/neural_network/_base.pyÚinplace_identityr
      ó   � ó    c                 ó2   — t        j                  | | ¬«       y)zŸCompute the exponential inplace.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.
    ©ÚoutN)ÚnpÚexpr   s    r	   Úinplace_expr      s   € ô ‡F�Fˆ1�!Ör   c                 ó   — t        | | ¬«       y)z¥Compute the logistic function inplace.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.
    r   N)Úlogistic_sigmoidr   s    r	   Úinplace_logisticr   "   s   € ô �Q˜AÖr   c                 ó2   — t        j                  | | ¬«       y)z«Compute the hyperbolic tan function inplace.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.
    r   N)r   Útanhr   s    r	   Úinplace_tanhr   -   s   € ô ‡G�GˆA�1Ör   c                 ó4   — t        j                  | d| ¬«       y)z²Compute the rectified linear unit function inplace.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.
    r   r   N)r   Úmaximumr   s    r	   Úinplace_relur   8   s   € ô ‡J�Jˆq�!˜Ör   c                 óÚ   — | | j                  d¬«      dd…t        j                  f   z
  }t        j                  || ¬«       | | j	                  d¬«      dd…t        j                  f   z  } y)zªCompute the K-way softmax function inplace.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.
    é   ©ÚaxisNr   )Úmaxr   Únewaxisr   Úsum)r   Útmps     r	   Úinplace_softmaxr$   C   sT   € ð ˆa�e‰e˜ˆe‹mšAœrŸz™z˜MÑ*Ñ
*€CÜ‡F�Fˆ3�AÕØˆ�‰�Aˆ‹’qœ"Ÿ*™*�}Ñ	%Ñ%�Ar   )Úidentityr   r   ÚlogisticÚreluÚsoftmaxc                  ó   — y)a„  Apply the derivative of the identity function: do nothing.

    Parameters
    ----------
    Z : {array-like, sparse matrix}, shape (n_samples, n_features)
        The data which was output from the identity activation function during
        the forward pass.

    delta : {array-like}, shape (n_samples, n_features)
         The backpropagated error signal to be modified inplace.
    Nr   ©ÚZÚdeltas     r	   Úinplace_identity_derivativer-   Z   r   r   c                 ó   — || z  }|d| z
  z  }y)aó  Apply the derivative of the logistic sigmoid function.

    It exploits the fact that the derivative is a simple function of the output
    value from logistic function.

    Parameters
    ----------
    Z : {array-like, sparse matrix}, shape (n_samples, n_features)
        The data which was output from the logistic activation function during
        the forward pass.

    delta : {array-like}, shape (n_samples, n_features)
         The backpropagated error signal to be modified inplace.
    r   Nr   r*   s     r	   Úinplace_logistic_derivativer/   i   s   € ð 
ˆQ�J€EØ	ˆQ�‰U�N�Er   c                 ó   — |d| dz  z
  z  }y)aý  Apply the derivative of the hyperbolic tanh function.

    It exploits the fact that the derivative is a simple function of the output
    value from hyperbolic tangent.

    Parameters
    ----------
    Z : {array-like, sparse matrix}, shape (n_samples, n_features)
        The data which was output from the hyperbolic tangent activation
        function during the forward pass.

    delta : {array-like}, shape (n_samples, n_features)
         The backpropagated error signal to be modified inplace.
    r   é   Nr   r*   s     r	   Úinplace_tanh_derivativer2   |   s   € ð 
ˆQ��A‘‰XÑ�Er   c                 ó   — d|| dk(  <   y)a  Apply the derivative of the relu function.

    It exploits the fact that the derivative is a simple function of the output
    value from rectified linear units activation function.

    Parameters
    ----------
    Z : {array-like, sparse matrix}, shape (n_samples, n_features)
        The data which was output from the rectified linear units activation
        function during the forward pass.

    delta : {array-like}, shape (n_samples, n_features)
         The backpropagated error signal to be modified inplace.
    r   Nr   r*   s     r	   Úinplace_relu_derivativer4   Ž   s   € ð €Eˆ!ˆq‰&‚Mr   )r%   r   r&   r'   c                 ó`   — dt        j                  | |z
  dz  |d¬«      j                  «       z  S )aà  Compute the squared loss for regression.

    Parameters
    ----------
    y_true : array-like or label indicator matrix
        Ground truth (correct) values.

    y_pred : array-like or label indicator matrix
        Predicted values, as returned by a regression estimator.

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights.

    Returns
    -------
    loss : float
        The degree to which the samples are correctly predicted.
    g      à?r1   r   ©Úweightsr   )r   ÚaverageÚmean©Úy_trueÚy_predÚsample_weights      r	   Úsquared_lossr>   ¨   s0   € ð( 	Œb�j‰j˜& 6™/¨aÑ/¸ÈQÔO×TÑTÓVÑVðr   c                 ót   — t        j                  t        | | |z  «      | z
  |z   |d¬«      j                  «       S )aó  Compute (half of the) Poisson deviance loss for regression.

    Parameters
    ----------
    y_true : array-like or label indicator matrix
        Ground truth (correct) labels.

    y_pred : array-like or label indicator matrix
        Predicted values, as returned by a regression estimator.

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights.

    Returns
    -------
    loss : float
        The degree to which the samples are correctly predicted.
    r   r6   )r   r8   r   r"   r:   s      r	   Úpoisson_lossr@   À   s9   € ô, �:‰:Üˆf�f˜v‘oÓ&¨Ñ/°&Ñ8À-ÐVWôç	�cƒeðr   c                 óž  — t        j                  |j                  «      j                  }t        j                  ||d|z
  «      }|j
                  d   dk(  rt        j                  d|z
  |d¬«      }| j
                  d   dk(  rt        j                  d| z
  | d¬«      } t        j                  t        | |«      |d¬«      j                  «        S )a  Compute Logistic loss for classification.

    Parameters
    ----------
    y_true : array-like or label indicator matrix
        Ground truth (correct) labels.

    y_prob : array-like of float, shape = (n_samples, n_classes)
        Predicted probabilities, as returned by a classifier's
        predict_proba method.

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights.

    Returns
    -------
    loss : float
        The degree to which the samples are correctly predicted.
    r   r   r   r6   )
r   ÚfinfoÚdtypeÚepsÚclipÚshapeÚappendr8   r   r"   ©r;   Úy_probr=   rD   s       r	   Úlog_lossrJ   Û   s¤   € ô( �(‰(�6—<‘<Ó
 ×
$Ñ
$€CÜ�W‰W�V˜S ! c¡'Ó*€FØ‡|�|�A�˜!ÒÜ—‘˜1˜v™: v°AÔ6ˆà‡|�|�A�˜!ÒÜ—‘˜1˜v™: v°AÔ6ˆä�J‰J”u˜V VÓ,°mÈ!ÔL×PÑPÓRÐRÐRr   c                 ó  — t        j                  |j                  «      j                  }t        j                  ||d|z
  «      }t        j
                  t        | |«      t        d| z
  d|z
  «      z   |d¬«      j                  «        S )a}  Compute binary logistic loss for classification.

    This is identical to log_loss in binary classification case,
    but is kept for its use in multilabel case.

    Parameters
    ----------
    y_true : array-like or label indicator matrix
        Ground truth (correct) labels.

    y_prob : array-like of float, shape = (n_samples, 1)
        Predicted probabilities, as returned by a classifier's
        predict_proba method.

    sample_weight : array-like of shape (n_samples,), default=None
        Sample weights.

    Returns
    -------
    loss : float
        The degree to which the samples are correctly predicted.
    r   r   r6   )r   rB   rC   rD   rE   r8   r   r"   rH   s       r	   Úbinary_log_lossrL   ú   su   € ô. �(‰(�6—<‘<Ó
 ×
$Ñ
$€CÜ�W‰W�V˜S ! c¡'Ó*€FÜ�J‰JÜˆf�fÓ¤ a¨&¡j°!°f±*Ó =Ñ=ØØô÷ 
�cƒeð	ð r   )Úsquared_errorÚpoissonrJ   rL   )N)Ú__doc__Únumpyr   Úscipy.specialr   r   r   r
   r   r   r   r   r$   ÚACTIVATIONSr-   r/   r2   r4   ÚDERIVATIVESr>   r@   rJ   rL   ÚLOSS_FUNCTIONSr   r   r	   ú<module>rU      s    ðÙ .ó
 Ý 3Ý òòòòòò
&ð !ØØØ ØØñ€òòò&ò$ð& ,Ø#Ø+Ø#ñ	€óó0ó6Só>ðB "ØØØ&ñ	�r   