§
    ˜_ndº  ã                   óœ   — 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ee	ee
ed
œZd„ Zd„ Zd„ Zd„ ZeeeedœZd„ Zd„ Zd„ ZeeedœZdS )z)Utilities for the neural network modules
é    N)Úexpit)Úxlogyc                 ó   — dS )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    ú<lib/python3.11/site-packages/sklearn/neural_network/_base.pyÚinplace_identityr
      ó   € € € ó    c                 ó(   — t          | | ¬¦  «         dS )z¥Compute the logistic function inplace.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.
    ©ÚoutN)Úlogistic_sigmoidr   s    r	   Úinplace_logisticr      s   € õ Q˜AÐÑÔÐÐÐr   c                 ó2   — t          j        | | ¬¦  «         dS )z«Compute the hyperbolic tan function inplace.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.
    r   N)ÚnpÚtanhr   s    r	   Úinplace_tanhr   $   s   € õ „GˆA1ÐÑÔÐÐÐr   c                 ó4   — t          j        | d| ¬¦  «         dS )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   /   s!   € õ „Jˆq!˜ÐÑÔÐÐÐr   c                 óæ   — | |                       d¬¦  «        dd…t          j        f         z
  }t          j        || ¬¦  «         | |                      d¬¦  «        dd…t          j        f         z  } dS )zªCompute the K-way softmax function inplace.

    Parameters
    ----------
    X : {array-like, sparse matrix}, shape (n_samples, n_features)
        The input data.
    é   ©ÚaxisNr   )Úmaxr   ÚnewaxisÚexpÚsum)r   Útmps     r	   Úinplace_softmaxr"   :   sg   € ð ˆaeŠe˜ˆe‰mŒm˜A˜A˜Arœz˜MÔ*Ñ
*€CÝ„Fˆ3AÐÑÔÐØˆŠAˆ‰Œqqq"œ*}Ô	%Ñ%€A€A€Ar   )Úidentityr   ÚlogisticÚreluÚsoftmaxc                 ó   — dS )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+   P   r   r   c                 ó    — || z  }|d| z
  z  }dS )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-   _   s   € ð 
ˆQJ€EØ	ˆQ‰UN€E€E€Er   c                 ó   — |d| dz  z
  z  }dS )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_derivativer0   r   s   € ð 
ˆQA‘‰XÑ€E€E€Er   c                 ó   — d|| dk    <   dS )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_derivativer2   „   s   € ð €Eˆ!ˆqŠ&M€M€Mr   )r#   r   r$   r%   c                 ó<   — | |z
  dz                        ¦   «         d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.

    Returns
    -------
    loss : float
        The degree to which the samples are correctly predicted.
    r/   )Úmean)Úy_trueÚy_preds     r	   Úsquared_lossr7   ž   s$   € ð  f‰_ Ñ"×(Ò(Ñ*Ô*¨QÑ.Ð.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        d         z  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.

    Returns
    -------
    loss : float
        The degree to which the samples are correctly predicted.
    r   r   r   )	r   ÚfinfoÚdtypeÚepsÚclipÚshapeÚappendr   r    ©r5   Úy_probr;   s      r	   Úlog_lossrA   ±   s¯   € õ" Œ(6”<Ñ
 Ô
 Ô
$€CÝŒWV˜S ! c¡'Ñ*Ô*€FØ„|A„˜!ÒÐÝ”˜1˜v™: v°AÐ6Ñ6Ô6ˆà„|A„˜!ÒÐÝ”˜1˜v™: v°AÐ6Ñ6Ô6ˆå&˜&Ñ!Ô!×%Ò%Ñ'Ô'Ð'¨&¬,°q¬/Ñ9Ð9r   c                 ó$  — t          j        |j        ¦  «        j        }t          j        ||d|z
  ¦  «        }t          | |¦  «                             ¦   «         t          d| z
  d|z
  ¦  «                             ¦   «         z    |j        d         z  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.

    Returns
    -------
    loss : float
        The degree to which the samples are correctly predicted.
    r   r   )r   r9   r:   r;   r<   r   r    r=   r?   s      r	   Úbinary_log_lossrC   Í   s   € õ( Œ(6”<Ñ
 Ô
 Ô
$€CÝŒWV˜S ! c¡'Ñ*Ô*€Få
˜Ñ
Ô
×
#Ò
#Ñ
%Ô
%­¨a°&©j¸!¸f¹*Ñ(EÔ(E×(IÒ(IÑ(KÔ(KÑ
KÐLØ
Œ,qŒ/ñ	ðr   )Úsquared_errorrA   rC   )Ú__doc__Únumpyr   Úscipy.specialr   r   r   r
   r   r   r   r"   ÚACTIVATIONSr+   r-   r0   r2   ÚDERIVATIVESr7   rA   rC   ÚLOSS_FUNCTIONSr   r   r	   ú<module>rK      sG  ððð ð Ð Ð Ð à 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø Ð Ð Ð Ð Ð ðð ð ðð ð ðð ð ðð ð ð
&ð 
&ð 
&ð !ØØ ØØðð €ðð ð ðð ð ð&ð ð ð$ð ð ð& ,Ø#Ø+Ø#ð	ð €ð/ð /ð /ð&:ð :ð :ð8ð ð ð: "ØØ&ðð €€€r   