
    -i                     &   S r SSKJrJr  SSKJr  SSKrSSKJ	r	J
r
  SSKJr  SSKJr  \ " S	 S
5      5       r\R                   4S jr " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\\\\\S.rg)zM
Module contains classes for invertible (and differentiable) link functions.
    )ABCabstractmethod)	dataclassN)expitlogit)gmean   )softmaxc                   J    \ rS rSr% \\S'   \\S'   \\S'   \\S'   S rS rSr	g	)
Interval   lowhighlow_inclusivehigh_inclusivec                     U R                   U R                  :  a&  [        SU R                    SU R                   S35      eg)zCheck that low <= highz#One must have low <= high; got low=z, high=.N)r   r   
ValueError)selfs    E/var/www/html/venv/lib/python3.13/site-packages/sklearn/_loss/link.py__post_init__Interval.__post_init__   s?    88dii5dhhZwtyykQRS       c                    U R                   (       a!  [        R                  " XR                  5      nO [        R                  " XR                  5      n[        R
                  " U5      (       d  gU R                  (       a!  [        R                  " XR                  5      nO [        R                  " XR                  5      n[        [        R
                  " U5      5      $ )zTest 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   npgreater_equalr   greaterallr   
less_equalr   lessbool)r   xr   r   s       r   includesInterval.includes    s     ""1hh/C**Q)Cvvc{{==II.D771ii(D BFF4L!!r    N)
__name__
__module____qualname____firstlineno__float__annotations__r!   r   r#   __static_attributes__r%   r   r   r   r      s"    	J
K"r   r   c                    S[         R                  " U5      R                  -  nU R                  [         R                  * :X  a  SnO;U R                  S:  a  U R                  SU-
  -  U-   nOU R                  SU-   -  U-   nU R
                  [         R                  :X  a  SnX44$ U R
                  S:  a  U R
                  SU-   -  U-
  nX44$ U R
                  SU-
  -  U-
  nX44$ )zGenerate values low and high to be within the interval range.

This is used in tests only.

Returns
-------
low, high : tuple
    The returned values low and high lie within the interval.

   g    _r      g    _B)r   finfoepsr   infr   )intervaldtyper1   r   r   s        r   _inclusive_low_highr5   =   s     rxx""
"C||w		lla#g&,lla#g&,}} 9 
	}}C(3. 9 }}C(3.9r   c                       \ rS rSrSrSr\" \R                  * \R                  SS5      r	\
SS j5       r\
SS j5       rSrg)	BaseLinkY   a  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.
FNc                     g)a  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.
out : array
    A location into which the result is stored. If provided, it must
    have a shape that the inputs broadcast to. If not provided or None,
    a freshly-allocated array is returned.

Returns
-------
out : array
    Output array, element-wise link function.
Nr%   r   y_predouts      r   linkBaseLink.linko       r   c                     g)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).
out : array
    A location into which the result is stored. If provided, it must
    have a shape that the inputs broadcast to. If not provided or None,
    a freshly-allocated array is returned.

Returns
-------
out : array
    Output array, element-wise inverse link function.
Nr%   r   raw_predictionr<   s      r   inverseBaseLink.inverse   r?   r   r%   N)r&   r'   r(   r)   __doc__is_multiclassr   r   r2   interval_y_predr   r=   rC   r,   r%   r   r   r7   r7   Y   sP     M
 wu=O *  r   r7   c                   &    \ rS rSrSrSS jr\rSrg)IdentityLink   z"The identity link function g(x)=x.Nc                 <    Ub  [         R                  " X!5        U$ U$ rE   )r   copytor:   s      r   r=   IdentityLink.link   s    ?IIc"JMr   r%   rE   )r&   r'   r(   r)   rF   r=   rC   r,   r%   r   r   rJ   rJ      s    , Gr   rJ   c                   V    \ rS rSrSr\" S\R                  SS5      rS	S jr	S	S jr
Srg)
LogLink   z"The log link function g(x)=log(x).r   FNc                 *    [         R                  " XS9$ Nr<   )r   logr:   s      r   r=   LogLink.link   s    vvf&&r   c                 *    [         R                  " XS9$ rS   )r   exprA   s      r   rC   LogLink.inverse   s    vvn..r   r%   rE   )r&   r'   r(   r)   rF   r   r   r2   rH   r=   rC   r,   r%   r   r   rP   rP      s#    ,q"&&%7O'/r   rP   c                   B    \ rS rSrSr\" SSSS5      rS
S jrS
S jrS	r	g)	LogitLink   z&The logit link function g(x)=logit(x).r   r/   FNc                     [        XS9$ rS   r   r:   s      r   r=   LogitLink.link   s    V%%r   c                     [        XS9$ rS   r   rA   s      r   rC   LogitLink.inverse   s    ^--r   r%   rE   
r&   r'   r(   r)   rF   r   rH   r=   rC   r,   r%   r   r   r[   r[      s    0q!UE2O&.r   r[   c                   B    \ rS rSrSr\" SSSS5      rS
S jrS
S jrS	r	g)HalfLogitLink   zRHalf the logit link function g(x)=1/2 * logit(x).

Used for the exponential loss.
r   r/   FNc                 "    [        XS9nUS-  nU$ )NrT   g      ?r^   r:   s      r   r=   HalfLogitLink.link   s    F$s

r   c                      [        SU-  U5      $ )Nr	   ra   rA   s      r   rC   HalfLogitLink.inverse   s    Q'--r   r%   rE   rc   r%   r   r   re   re      s#    
 q!UE2O
.r   re   c                   L    \ rS rSrSrSr\" SSSS5      rS rSS	 jr	SS
 jr
Srg)MultinomialLogit   a  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                 \    U[         R                  " USS9S S 2[         R                  4   -
  $ )Nr/   axis)r   meannewaxis)r   rB   s     r   symmetrize_raw_prediction*MultinomialLogit.symmetrize_raw_prediction  s%    Q ?2:: NNNr   Nc                 n    [        USS9n[        R                  " XS S 2[        R                  4   -  US9$ )Nr/   ro   rT   )r   r   rU   rr   )r   r;   r<   gms       r   r=   MultinomialLogit.link  s/    6"vvf!RZZ-00c::r   c                 `    Uc
  [        USS9$ [        R                  " X!5        [        USS9  U$ )NT)copyF)r
   r   rM   rA   s      r   rC   MultinomialLogit.inverse  s/    ;>55IIc*Ce$Jr   r%   rE   )r&   r'   r(   r)   rF   rG   r   rH   rs   r=   rC   r,   r%   r   r   rl   rl      s/    +Z Mq!UE2OO;
r   rl   )identityrU   r   
half_logitmultinomial_logit)rF   abcr   r   dataclassesr   numpyr   scipy.specialr   r   scipy.statsr   utils.extmathr
   r   float64r5   r7   rJ   rP   r[   re   rl   _LINKSr%   r   r   <module>r      s    $ !  &  # '" '" '"T )+

 8@s @F
8 
	/h 	/	. 	..H ."?x ?F )
r   