§
    rŠtj/  ã                   ó´   — 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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    úZ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/neural_network/_base.pyÚinplace_identityr
      ó   € € € ó    c                 ó2   — t          j        | | ¬¦  «         dS )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ˆ1�!ÐÑÔÐÐÐr   c                 ó(   — t          | | ¬¦  «         dS )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        | | ¬¦  «         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)r   Útanhr   s    r	   Úinplace_tanhr   -   s   € õ „GˆA�1ÐÑÔÐÐÐ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   8   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   Únewaxisr   Úsum)r   Útmps     r	   Úinplace_softmaxr$   C   sg   € ð ˆa�eŠe˜ˆe‰mŒm˜A˜A˜A�rœz˜MÔ*Ñ
*€CÝ„Fˆ3�AÐÑÔÐØˆ�Š�Aˆ‰Œ�q�q�q�"œ*�}Ô	%Ñ%€A€A€Ar   )Úidentityr   r   Ú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-   Z   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/   i   s   € ð 
ˆQ�J€EØ	ˆQ�‰U�N€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_derivativer2   |   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_derivativer4   Ž   s   € ð €Eˆ!ˆqŠ&�M€M€Mr   )r%   r   r&   r'   c                 óf   — dt          j        | |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.

    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>   ¨   s7   € ð( 	�bŒj˜& 6™/¨aÑ/¸ÈQÐOÑOÔO×TÒTÑVÔVÑVðr   c                 ó‚   — t          j        t          | | |z  ¦  «        | z
  |z   |d¬¦  «                             ¦   «         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@   À   sF   € õ, Œ:Ýˆf�f˜v‘oÑ&Ô&¨Ñ/°&Ñ8À-ÐVWðñ ô ç	‚c�e„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¬¦  «         	                    ¦   «          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�V˜S ! c¡'Ñ*Ô*€FØ„|�A„˜!ÒÐÝ”˜1˜v™: v°AÐ6Ñ6Ô6ˆà„|�A„˜!ÒÐÝ”˜1˜v™: v°AÐ6Ñ6Ô6ˆåŒJ•u˜V VÑ,Ô,°mÈ!ÐLÑLÔL×PÒPÑRÔRÐRÐRr   c                 ó  — t          j        |j        ¦  «        j        }t          j        ||d|z
  ¦  «        }t          j        t          | |¦  «        t          d| z
  d|z
  ¦  «        z   |d¬¦  «                             ¦   «          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   ú   s‚   € õ. Œ(�6”<Ñ
 Ô
 Ô
$€CÝŒW�V˜S ! c¡'Ñ*Ô*€FÝŒJÝˆf�fÑÔ¥ a¨&¡j°!°f±*Ñ =Ô =Ñ=ØØðñ ô ÷ 
‚c�e„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Ð 3Ð 3Ð 3Ð 3Ð 3Ø Ð Ð Ð Ð Ð ðð ð ðð ð ðð ð ðð ð ðð ð ð
&ð 
&ð 
&ð !ØØØ ØØðð €ðð ð ðð ð ð&ð ð ð$ð ð ð& ,Ø#Ø+Ø#ð	ð €ðð ð ð ð0ð ð ð ð6Sð Sð Sð Sð>ð ð ð ðB "ØØØ&ð	ð €€€r   