§
    qŠtj?  ã                   óF  — d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZ ddlmZ e G d„ d	¦  «        ¦   «         Zd
„ Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZeeeeedœZdS )zM
Module contains classes for invertible (and differentiable) link functions.
é    )ÚABCÚabstractmethod)Ú	dataclass)Úulp)Úgmean)Ú_expitÚ_logitÚget_namespace©Úsoftmaxc                   óD   — e Zd ZU eed<   eed<   eed<   eed<   d„ Zd„ ZdS )ÚIntervalÚlowÚhighÚlow_inclusiveÚhigh_inclusivec                 óf   — | j         | j        k    r t          d| j         › d| j        › d�¦  «        ‚dS )zCheck that low <= highz#One must have low <= high; got low=z, high=ú.N)r   r   Ú
ValueError)Úselfs    úP/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/_loss/link.pyÚ__post_init__zInterval.__post_init__   sE   € àŒ8�d”iÒÐÝØS°d´hÐSÐSÀtÄyÐSÐSÐSñô ð ð  Ðó    c                 ó�  — t          |¦  «        \  }}| j        r|                     || j        ¦  «        }n|                     || j        ¦  «        }|                     |¦  «        sdS | j        r|                     || j        ¦  «        }n| 	                    || j        ¦  «        }t          |                     |¦  «        ¦  «        S )zóTest whether all values of x are in interval range.

        Parameters
        ----------
        x : ndarray
            Array whose elements are tested to be in interval range.

        Returns
        -------
        result : bool
        F)r
   r   Úgreater_equalr   ÚgreaterÚallr   Ú
less_equalr   ÚlessÚbool)r   ÚxÚxpÚ_r   r   s         r   ÚincludeszInterval.includes    s¶   € õ ˜aÑ Ô ‰ˆˆAØÔð 	*Ø×"Ò" 1 d¤hÑ/Ô/ˆCˆCà—*’*˜Q ¤Ñ)Ô)ˆCà�vŠv�c‰{Œ{ð 	Ø�5àÔð 	)Ø—=’=  D¤IÑ.Ô.ˆDˆDà—7’7˜1˜dœiÑ(Ô(ˆDõ �B—F’F˜4‘L”LÑ!Ô!Ð!r   N)Ú__name__Ú
__module__Ú__qualname__ÚfloatÚ__annotations__r    r   r$   © r   r   r   r      s^   € € € € € € à	€J€J�JØ
€K€K�KØÐÐÑØÐÐÑðð ð ð"ð "ð "ð "ð "r   r   c                 ó€  — dt          d¦  «        z  }| j        t          d¦  «         k    rd}n,| j        dk     r| j        d|z
  z  |z   }n| j        d|z   z  |z   }| j        t          d¦  «        k    rd}n,| j        dk     r| j        d|z   z  |z
  }n| j        d|z
  z  |z
  }t          |¦  «        t          |¦  «        fS )zÞGenerate values low and high to be within the interval range.

    This is used in tests only.

    Returns
    -------
    low, high : tuple of floats
        The returned values low and high lie within the interval.
    é
   é   Úinfg    _ Âr   g    _ B)r   r   r(   r   )ÚintervalÚepsr   r   s       r   Ú_inclusive_low_highr1   >   sÒ   € ð �s�1‰vŒv‰+€CØ„|�˜e™œ�}Ò$Ð$ØˆˆØ	Œ˜Ò	Ð	ØŒl˜a #™gÑ&¨Ñ,ˆˆàŒl˜a #™gÑ&¨Ñ,ˆà„}�˜e™œÒ$Ð$ØˆˆØ	Œ˜Ò	Ð	ØŒ}  C¡Ñ(¨3Ñ.ˆˆàŒ}  C¡Ñ(¨3Ñ.ˆå�‰:Œ:•u˜T‘{”{Ð"Ð"r   c                   ó„   — e Zd ZdZdZ e ed¦  «          ed¦  «        dd¦  «        Zed„ ¦   «         Z	ed„ ¦   «         Z
dS )ÚBaseLinka   Abstract base class for differentiable, invertible link functions.

    Convention:
        - link function g: raw_prediction = g(y_pred)
        - inverse link h: y_pred = h(raw_prediction)

    For (generalized) linear models, `raw_prediction = X @ coef` is the so
    called linear predictor, and `y_pred = h(raw_prediction)` is the predicted
    conditional (on X) expected value of the target `y_true`.

    The methods are not implemented as staticmethods in case a link function needs
    parameters.
    Fr.   c                 ó   — dS )an  Compute the link function g(y_pred).

        The link function maps (predicted) target values to raw predictions,
        i.e. `g(y_pred) = raw_prediction`.

        Parameters
        ----------
        y_pred : array
            Predicted target values.

        Returns
        -------
        array
            Output array, element-wise link function.
        Nr*   ©r   Úy_preds     r   ÚlinkzBaseLink.linkp   ó   € € € r   c                 ó   — dS )a¢  Compute the inverse link function h(raw_prediction).

        The inverse link function maps raw predictions to predicted target
        values, i.e. `h(raw_prediction) = y_pred`.

        Parameters
        ----------
        raw_prediction : array
            Raw prediction values (in link space).

        Returns
        -------
        array
            Output array, element-wise inverse link function.
        Nr*   ©r   Úraw_predictions     r   ÚinversezBaseLink.inverse‚   r8   r   N)r%   r&   r'   Ú__doc__Úis_multiclassr   r(   Úinterval_y_predr   r7   r<   r*   r   r   r3   r3   Z   s‚   € € € € € ðð ð €Mð
 �h   e¡¤˜}¨e¨e°E©l¬l¸EÀ5ÑIÔI€Oàðð ñ „^ðð" ðð ñ „^ðð ð r   r3   c                   ó   — e Zd ZdZd„ ZeZdS )ÚIdentityLinkz"The identity link function g(x)=x.c                 ó   — |S ©Nr*   r5   s     r   r7   zIdentityLink.link˜   s   € Øˆr   N)r%   r&   r'   r=   r7   r<   r*   r   r   rA   rA   •   s*   € € € € € Ø,Ð,ðð ð ð €G€G€Gr   rA   c                   óL   — e Zd ZdZ ed ed¦  «        dd¦  «        Zd„ Zd„ ZdS )ÚLogLinkz"The log link function g(x)=log(x).r   r.   Fc                 óP   — t          |¦  «        \  }}|                     |¦  «        S rC   )r
   Úlog)r   r6   r"   r#   s       r   r7   zLogLink.link£   s#   € Ý˜fÑ%Ô%‰ˆˆAØ�vŠv�f‰~Œ~Ðr   c                 óP   — t          |¦  «        \  }}|                     |¦  «        S rC   )r
   Úexp©r   r;   r"   r#   s       r   r<   zLogLink.inverse§   s%   € Ý˜nÑ-Ô-‰ˆˆAØ�vŠv�nÑ%Ô%Ð%r   N)	r%   r&   r'   r=   r   r(   r?   r7   r<   r*   r   r   rE   rE   ž   sU   € € € € € Ø,Ð,à�h˜q % %¨¡,¤,°°uÑ=Ô=€Oðð ð ð&ð &ð &ð &ð &r   rE   c                   ó:   — e Zd ZdZ edddd¦  «        Zd„ Zd„ ZdS )Ú	LogitLinkz&The logit link function g(x)=logit(x).r   r-   Fc                 ó    — t          |¦  «        S rC   ©r	   r5   s     r   r7   zLogitLink.link±   s   € Ý�f‰~Œ~Ðr   c                 ó    — t          |¦  «        S rC   ©r   r:   s     r   r<   zLogitLink.inverse´   s   € Ý�nÑ%Ô%Ð%r   N©r%   r&   r'   r=   r   r?   r7   r<   r*   r   r   rL   rL   ¬   sM   € € € € € Ø0Ð0à�h˜q ! U¨EÑ2Ô2€Oðð ð ð&ð &ð &ð &ð &r   rL   c                   ó:   — e Zd ZdZ edddd¦  «        Zd„ Zd„ ZdS )ÚHalfLogitLinkzZHalf the logit link function g(x)=1/2 * logit(x).

    Used for the exponential loss.
    r   r-   Fc                 ó&   — dt          |¦  «        z  S )Ng      à?rN   r5   s     r   r7   zHalfLogitLink.linkÀ   s   € Ø•V˜F‘^”^Ñ#Ð#r   c                 ó&   — t          d|z  ¦  «        S )Né   rP   r:   s     r   r<   zHalfLogitLink.inverseÃ   s   € Ý�a˜.Ñ(Ñ)Ô)Ð)r   NrQ   r*   r   r   rS   rS   ¸   sS   € € € € € ðð ð
 �h˜q ! U¨EÑ2Ô2€Oð$ð $ð $ð*ð *ð *ð *ð *r   rS   c                   óD   — e Zd ZdZdZ edddd¦  «        Zd„ Zd„ Zd„ Z	d	S )
ÚMultinomialLogitaš  The symmetric multinomial logit function.

    Convention:
        - y_pred.shape = raw_prediction.shape = (n_samples, n_classes)

    Notes:
        - The inverse link h is the softmax function.
        - The sum is over the second axis, i.e. axis=1 (n_classes).

    We have to choose additional constraints in order to make

        y_pred[k] = exp(raw_pred[k]) / sum(exp(raw_pred[k]), k=0..n_classes-1)

    for n_classes classes identifiable and invertible.
    We choose the symmetric side constraint where the geometric mean response
    is set as reference category, see [2]:

    The symmetric multinomial logit link function for a single data point is
    then defined as

        raw_prediction[k] = g(y_pred[k]) = log(y_pred[k]/gmean(y_pred))
        = log(y_pred[k]) - mean(log(y_pred)).

    Note that this is equivalent to the definition in [1] and implies mean
    centered raw predictions:

        sum(raw_prediction[k], k=0..n_classes-1) = 0.

    For linear models with raw_prediction = X @ coef, this corresponds to
    sum(coef[k], k=0..n_classes-1) = 0, i.e. the sum over classes for every
    feature is zero.

    Reference
    ---------
    .. [1] Friedman, Jerome; Hastie, Trevor; Tibshirani, Robert. "Additive
        logistic regression: a statistical view of boosting" Ann. Statist.
        28 (2000), no. 2, 337--407. doi:10.1214/aos/1016218223.
        https://projecteuclid.org/euclid.aos/1016218223

    .. [2] Zahid, Faisal Maqbool and Gerhard Tutz. "Ridge estimation for
        multinomial logit models with symmetric side constraints."
        Computational Statistics 28 (2013): 1017-1034.
        http://epub.ub.uni-muenchen.de/11001/1/tr067.pdf
    Tr   r-   Fc                 ón   — t          |¦  «        \  }}||                     |d¬¦  «        d d …d f         z
  S ©Nr-   )Úaxis)r
   ÚmeanrJ   s       r   Úsymmetrize_raw_predictionz*MultinomialLogit.symmetrize_raw_predictionø   s;   € Ý˜nÑ-Ô-‰ˆˆAØ §¢¨¸Q Ñ ?Ô ?ÀÀÀÀ4ÀÔ HÑHÐHr   c                 óŒ   — t          |¦  «        \  }}t          |d¬¦  «        }|                     ||d d …d f         z  ¦  «        S rZ   )r
   r   rG   )r   r6   r"   r#   Úgms        r   r7   zMultinomialLogit.linkü   sH   € Ý˜fÑ%Ô%‰ˆˆAå�6 Ð"Ñ"Ô"ˆØ�vŠv�f˜r ! ! ! T 'œ{Ñ*Ñ+Ô+Ð+r   c                 ó    — t          |¦  «        S rC   r   r:   s     r   r<   zMultinomialLogit.inverse  s   € Ý�~Ñ&Ô&Ð&r   N)
r%   r&   r'   r=   r>   r   r?   r]   r7   r<   r*   r   r   rX   rX   Ç   sk   € € € € € ð+ð +ðZ €MØ�h˜q ! U¨EÑ2Ô2€OðIð Ið Ið,ð ,ð ,ð'ð 'ð 'ð 'ð 'r   rX   )ÚidentityrG   ÚlogitÚ
half_logitÚmultinomial_logitN)r=   Úabcr   r   Údataclassesr   Úmathr   Úscipy.statsr   Úsklearn.utils._array_apir   r	   r
   Úsklearn.utils.extmathr   r   r1   r3   rA   rE   rL   rS   rX   Ú_LINKSr*   r   r   ú<module>rl      sò  ððð ð $Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð à BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BÐ BØ )Ð )Ð )Ð )Ð )Ð )ð ð("ð ("ð ("ð ("ð ("ñ ("ô ("ñ „ð("ðV#ð #ð #ð88ð 8ð 8ð 8ð 8ˆsñ 8ô 8ð 8ðvð ð ð ð �8ñ ô ð ð&ð &ð &ð &ð &ˆhñ &ô &ð &ð	&ð 	&ð 	&ð 	&ð 	&�ñ 	&ô 	&ð 	&ð*ð *ð *ð *ð *�Hñ *ô *ð *ð<'ð <'ð <'ð <'ð <'�xñ <'ô <'ð <'ð@ ØØØØ)ð
ð 
€€€r   