Ë
    ÷Q(hG…  ã                   óB   — d Z ddlZddlmZ ddlmZ d„ Z G d„ d«      Zy)	zA
Loss functions for linear models with raw_prediction = X @ coef
é    N)Úsparseé   )Úsquared_normc                 óò   — | j                   d   }t        j                  | «      r9| j                  t        j                  |df||f¬«      z  | z  j                  «       S |dd…df   | z  }| j                  |z  S )z/Compute the sandwich product X.T @ diag(W) @ X.r   ©ÚshapeN)r   r   ÚissparseÚTÚ
dia_matrixÚtoarray)ÚXÚWÚ	n_samplesÚWXs       ú_/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sklearn/linear_model/_linear_loss.pyÚsandwich_dotr      sp   € ð —‘˜‘
€IÜ‡��qÔà�C‰C”&×#Ñ# Q¨ F°9¸iÐ2HÔIÑIÈAÑMß
‰'‹)ð	ð Šq�$ˆw‰Z˜!‰^ˆØ�s‰s�R‰xˆó    c                   ó~   — e Zd ZdZd„ Zdd„Zd„ Zd„ Zd„ Z	 	 	 	 dd„Z		 	 	 	 dd	„Z
	 	 	 	 dd
„Z	 	 	 	 	 	 dd„Z	 dd„Zy)ÚLinearModelLossa
	  General class for loss functions with raw_prediction = X @ coef + intercept.

    Note that raw_prediction is also known as linear predictor.

    The loss is the average of per sample losses and includes a term for L2
    regularization::

        loss = 1 / s_sum * sum_i s_i loss(y_i, X_i @ coef + intercept)
               + 1/2 * l2_reg_strength * ||coef||_2^2

    with sample weights s_i=1 if sample_weight=None and s_sum=sum_i s_i.

    Gradient and hessian, for simplicity without intercept, are::

        gradient = 1 / s_sum * X.T @ loss.gradient + l2_reg_strength * coef
        hessian = 1 / s_sum * X.T @ diag(loss.hessian) @ X
                  + l2_reg_strength * identity

    Conventions:
        if fit_intercept:
            n_dof =  n_features + 1
        else:
            n_dof = n_features

        if base_loss.is_multiclass:
            coef.shape = (n_classes, n_dof) or ravelled (n_classes * n_dof,)
        else:
            coef.shape = (n_dof,)

        The intercept term is at the end of the coef array:
        if base_loss.is_multiclass:
            if coef.shape (n_classes, n_dof):
                intercept = coef[:, -1]
            if coef.shape (n_classes * n_dof,)
                intercept = coef[n_features::n_dof] = coef[(n_dof-1)::n_dof]
            intercept.shape = (n_classes,)
        else:
            intercept = coef[-1]

        Shape of gradient follows shape of coef.
        gradient.shape = coef.shape

        But hessian (to make our lives simpler) are always 2-d:
        if base_loss.is_multiclass:
            hessian.shape = (n_classes * n_dof, n_classes * n_dof)
        else:
            hessian.shape = (n_dof, n_dof)

    Note: If coef has shape (n_classes * n_dof,), the 2d-array can be reconstructed as

        coef.reshape((n_classes, -1), order="F")

    The option order="F" makes coef[:, i] contiguous. This, in turn, makes the
    coefficients without intercept, coef[:, :-1], contiguous and speeds up
    matrix-vector computations.

    Note: If the average loss per sample is wanted instead of the sum of the loss per
    sample, one can simply use a rescaled sample_weight such that
    sum(sample_weight) = 1.

    Parameters
    ----------
    base_loss : instance of class BaseLoss from sklearn._loss.
    fit_intercept : bool
    c                 ó    — || _         || _        y ©N)Ú	base_lossÚfit_intercept)Úselfr   r   s      r   Ú__init__zLinearModelLoss.__init__h   s   € Ø"ˆŒØ*ˆÕr   Nc                 ó  — |j                   d   }| j                  j                  }| j                  r|dz   }n|}| j                  j                  rt        j                  |||f|d¬«      }|S t        j                  |||¬«      }|S )aâ  Allocate coef of correct shape with zeros.

        Parameters:
        -----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data.
        dtype : data-type, default=None
            Overrides the data type of coef. With dtype=None, coef will have the same
            dtype as X.

        Returns
        -------
        coef : ndarray of shape (n_dof,) or (n_classes, n_dof)
            Coefficients of a linear model.
        é   ÚF)r   ÚdtypeÚorder)r   r   )r   r   Ú	n_classesr   Úis_multiclassÚnpÚ
zeros_like)r   r   r   Ú
n_featuresr!   Ún_dofÚcoefs          r   Úinit_zero_coefzLinearModelLoss.init_zero_coefl   s~   € ð  —W‘W˜Q‘Zˆ
Ø—N‘N×,Ñ,ˆ	Ø×ÒØ ‘N‰EàˆEØ�>‰>×'Ò'Ü—=‘= ¨9°eÐ*<ÀEÐQTÔUˆDð ˆô —=‘= ¨%°uÔ=ˆDØˆr   c                 ó<  — | j                   j                  s"| j                  r|d   }|dd }||fS d}|}||fS |j                  dk(  r*|j	                  | j                   j
                  dfd¬«      }n|}| j                  r|dd…df   }|dd…dd…f   }||fS d}||fS )a˜  Helper function to get coefficients and intercept.

        Parameters
        ----------
        coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
            Coefficients of a linear model.
            If shape (n_classes * n_dof,), the classes of one feature are contiguous,
            i.e. one reconstructs the 2d-array via
            coef.reshape((n_classes, -1), order="F").

        Returns
        -------
        weights : ndarray of shape (n_features,) or (n_classes, n_features)
            Coefficients without intercept term.
        intercept : float or ndarray of shape (n_classes,)
            Intercept terms.
        éÿÿÿÿNç        r   r   ©r    )r   r"   r   ÚndimÚreshaper!   )r   r'   Ú	interceptÚweightss       r   Úweight_interceptz LinearModelLoss.weight_interceptˆ   sÍ   € ð$ �~‰~×+Ò+Ø×!Ò!Ø  ™H�	Ø˜s ˜)�ð  ˜	Ð!Ð!ð  �	Ø�ð ˜	Ð!Ð!ð �y‰y˜AŠ~ØŸ,™,¨¯©×(@Ñ(@À"Ð'EÈS˜,ÓQ‘à�Ø×!Ò!Ø#¢A r E™N�	Ø!¢! S b S &™/�ð ˜	Ð!Ð!ð  �	à˜	Ð!Ð!r   c                 ó–   — | j                  |«      \  }}| j                  j                  s	||z  |z   }n||j                  z  |z   }|||fS )ai  Helper function to get coefficients, intercept and raw_prediction.

        Parameters
        ----------
        coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
            Coefficients of a linear model.
            If shape (n_classes * n_dof,), the classes of one feature are contiguous,
            i.e. one reconstructs the 2d-array via
            coef.reshape((n_classes, -1), order="F").
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data.

        Returns
        -------
        weights : ndarray of shape (n_features,) or (n_classes, n_features)
            Coefficients without intercept term.
        intercept : float or ndarray of shape (n_classes,)
            Intercept terms.
        raw_prediction : ndarray of shape (n_samples,) or             (n_samples, n_classes)
        )r1   r   r"   r
   )r   r'   r   r0   r/   Úraw_predictions         r   Úweight_intercept_rawz$LinearModelLoss.weight_intercept_raw¯   sU   € ð, "×2Ñ2°4Ó8Ñˆ�à�~‰~×+Ò+Ø ™[¨9Ñ4‰Nð  §¡™]¨YÑ6ˆNà˜	 >Ð1Ð1r   c                 óP   — |j                   dk(  r||z  n
t        |«      }d|z  |z  S )z5Compute L2 penalty term l2_reg_strength/2 *||w||_2^2.r   g      à?)r-   r   )r   r0   Úl2_reg_strengthÚnorm2_ws       r   Ú
l2_penaltyzLinearModelLoss.l2_penaltyÏ   s.   € à'.§|¡|°qÒ'8�'˜GÒ#¼lÈ7Ó>SˆØ�_Ñ$ wÑ.Ð.r   c                 óò   — |€| j                  ||«      \  }}	}n| j                  |«      \  }}	| j                  j                  ||d|¬«      }
t	        j
                  |
|¬«      }
|
| j                  ||«      z   S )a  Compute the loss as weighted average over point-wise losses.

        Parameters
        ----------
        coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
            Coefficients of a linear model.
            If shape (n_classes * n_dof,), the classes of one feature are contiguous,
            i.e. one reconstructs the 2d-array via
            coef.reshape((n_classes, -1), order="F").
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data.
        y : contiguous array of shape (n_samples,)
            Observed, true target values.
        sample_weight : None or contiguous array of shape (n_samples,), default=None
            Sample weights.
        l2_reg_strength : float, default=0.0
            L2 regularization strength
        n_threads : int, default=1
            Number of OpenMP threads to use.
        raw_prediction : C-contiguous array of shape (n_samples,) or array of             shape (n_samples, n_classes)
            Raw prediction values (in link space). If provided, these are used. If
            None, then raw_prediction = X @ coef + intercept is calculated.

        Returns
        -------
        loss : float
            Weighted average of losses per sample, plus penalty.
        N©Úy_truer3   Úsample_weightÚ	n_threads©r0   )r4   r1   r   Úlossr#   Úaverager8   )r   r'   r   Úyr<   r6   r=   r3   r0   r/   r?   s              r   r?   zLinearModelLoss.lossÔ   s‡   € ðN Ð!Ø15×1JÑ1JÈ4ÐQRÓ1SÑ.ˆG�Y¡à!%×!6Ñ!6°tÓ!<ÑˆG�Yà�~‰~×"Ñ"ØØ)ØØð	 #ó 
ˆô �z‰z˜$¨Ô6ˆà�d—o‘o g¨Ó?Ñ?Ð?r   c                 ó¤  — |j                   | j                  j                  c\  }}	}
|	t        | j                  «      z   }|€| j                  ||«      \  }}}n| j                  |«      \  }}| j                  j                  ||||¬«      \  }}|€|nt        j                  |«      }|j                  «       |z  }|| j                  ||«      z  }||z  }| j                  j                  s\t        j                  ||j                  ¬«      }|j                  |z  ||z  z   |d|	 | j                  r|j                  «       |d<   ||fS t        j                  |
|f|j                  d¬«      }|j                  |z  ||z  z   |dd…d|	…f<   | j                  r|j                  d¬«      |dd…df<   |j                   d	k(  r|j#                  d¬
«      }||fS )a\  Computes the sum of loss and gradient w.r.t. coef.

        Parameters
        ----------
        coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
            Coefficients of a linear model.
            If shape (n_classes * n_dof,), the classes of one feature are contiguous,
            i.e. one reconstructs the 2d-array via
            coef.reshape((n_classes, -1), order="F").
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data.
        y : contiguous array of shape (n_samples,)
            Observed, true target values.
        sample_weight : None or contiguous array of shape (n_samples,), default=None
            Sample weights.
        l2_reg_strength : float, default=0.0
            L2 regularization strength
        n_threads : int, default=1
            Number of OpenMP threads to use.
        raw_prediction : C-contiguous array of shape (n_samples,) or array of             shape (n_samples, n_classes)
            Raw prediction values (in link space). If provided, these are used. If
            None, then raw_prediction = X @ coef + intercept is calculated.

        Returns
        -------
        loss : float
            Weighted average of losses per sample, plus penalty.

        gradient : ndarray of shape coef.shape
             The gradient of the loss.
        Nr:   ©r   r*   r   ©r   r    r   ©Úaxisr   r,   )r   r   r!   Úintr   r4   r1   Úloss_gradientr#   Úsumr8   r"   Ú
empty_liker   r
   Úemptyr-   Úravel)r   r'   r   rA   r<   r6   r=   r3   r   r%   r!   r&   r0   r/   r?   Úgrad_pointwiseÚsw_sumÚgrads                     r   rH   zLinearModelLoss.loss_gradient
  sÒ  € ðT ./¯W©W°d·n±n×6NÑ6NÐ*Ñˆ�J ØœS ×!3Ñ!3Ó4Ñ4ˆàÐ!Ø15×1JÑ1JÈ4ÐQRÓ1SÑ.ˆG�Y¡à!%×!6Ñ!6°tÓ!<ÑˆG�Yà#Ÿ~™~×;Ñ;ØØ)Ø'Øð	  <ó  
Ñˆˆnð ,Ð3‘¼¿¹ÀÓ9NˆØ�x‰x‹z˜FÑ"ˆØ�—‘ ¨Ó9Ñ9ˆà˜&Ñ ˆà�~‰~×+Ò+Ü—=‘= ¨W¯]©]Ô;ˆDØ !§¡ nÑ 4°ÈÑ7PÑ PˆD��*ÐØ×!Ò!Ø)×-Ñ-Ó/��R‘ð �TˆzÐô —8‘8˜Y¨Ð.°g·m±mÈ3ÔOˆDà#1×#3Ñ#3°aÑ#7¸/ÈGÑ:SÑ#SˆD’�K�Z�K�Ñ Ø×!Ò!Ø,×0Ñ0°aÐ0Ó8�’Q˜�U‘Ø�y‰y˜AŠ~Ø—z‘z¨�zÓ,�à�TˆzÐr   c                 óF  — |j                   | j                  j                  c\  }}	}
|	t        | j                  «      z   }|€| j                  ||«      \  }}}n| j                  |«      \  }}| j                  j                  ||||¬«      }|€|nt        j                  |«      }||z  }| j                  j                  sZt        j                  ||j                  ¬«      }|j                  |z  ||z  z   |d|	 | j                  r|j                  «       |d<   |S t        j                  |
|f|j                  d¬«      }|j                  |z  ||z  z   |dd…d|	…f<   | j                  r|j                  d¬«      |dd…df<   |j                  d	k(  r|j!                  d¬
«      S |S )aõ  Computes the gradient w.r.t. coef.

        Parameters
        ----------
        coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
            Coefficients of a linear model.
            If shape (n_classes * n_dof,), the classes of one feature are contiguous,
            i.e. one reconstructs the 2d-array via
            coef.reshape((n_classes, -1), order="F").
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data.
        y : contiguous array of shape (n_samples,)
            Observed, true target values.
        sample_weight : None or contiguous array of shape (n_samples,), default=None
            Sample weights.
        l2_reg_strength : float, default=0.0
            L2 regularization strength
        n_threads : int, default=1
            Number of OpenMP threads to use.
        raw_prediction : C-contiguous array of shape (n_samples,) or array of             shape (n_samples, n_classes)
            Raw prediction values (in link space). If provided, these are used. If
            None, then raw_prediction = X @ coef + intercept is calculated.

        Returns
        -------
        gradient : ndarray of shape coef.shape
             The gradient of the loss.
        Nr:   rC   r*   r   rD   r   rE   r   r,   )r   r   r!   rG   r   r4   r1   Úgradientr#   rI   r"   rJ   r   r
   rK   r-   rL   )r   r'   r   rA   r<   r6   r=   r3   r   r%   r!   r&   r0   r/   rM   rN   rO   s                    r   rQ   zLinearModelLoss.gradientX  s›  € ðN ./¯W©W°d·n±n×6NÑ6NÐ*Ñˆ�J ØœS ×!3Ñ!3Ó4Ñ4ˆàÐ!Ø15×1JÑ1JÈ4ÐQRÓ1SÑ.ˆG�Y¡à!%×!6Ñ!6°tÓ!<ÑˆG�YàŸ™×0Ñ0ØØ)Ø'Øð	 1ó 
ˆð ,Ð3‘¼¿¹ÀÓ9NˆØ˜&Ñ ˆà�~‰~×+Ò+Ü—=‘= ¨W¯]©]Ô;ˆDØ !§¡ nÑ 4°ÈÑ7PÑ PˆD��*ÐØ×!Ò!Ø)×-Ñ-Ó/��R‘ØˆKä—8‘8˜Y¨Ð.°g·m±mÈ3ÔOˆDà#1×#3Ñ#3°aÑ#7¸/ÈGÑ:SÑ#SˆD’�K�Z�K�Ñ Ø×!Ò!Ø,×0Ñ0°aÐ0Ó8�’Q˜�U‘Ø�y‰y˜AŠ~Ø—z‘z¨�zÓ,Ð,à�r   c
                 ó$  — |j                   | j                  j                  c\  }
}}|t        | j                  «      z   }|	€| j                  ||«      \  }}}	n| j                  |«      \  }}|€|
nt        j                  |«      }|€#t        j                  ||j                  d¬«      }nx|j                   |j                   k7  r&t        d|j                   › d|j                   › d�«      ‚| j                  j                  r!|j                  j                  st        d«      ‚|}|j                  }|€$t        j                   ||f|j                  ¬«      }n~|j                   ||fk7  rt        d	||f› d
|j                   ›d�«      ‚| j                  j                  r7|j                  j"                  s!|j                  j                  st        d«      ‚|}| j                  j                  �s:| j                  j%                  ||	||¬«      \  }}||z  }||z  }t        j&                  |dk  |¬«      dkD  }t        j(                  |«      }|j*                  |z  ||z  z   |d| | j                  r|j                  «       |d<   |r|||fS t-        ||«      |d|…d|…f<   |dkD  rA|j                  j"                  rdnd}|j/                  d|¬«      d||z  |dz   …xx   |z  cc<   | j                  �r |j*                  |z  }||dd…df<   ||ddd…f<   |j                  «       |d<   �nj| j                  j1                  ||	||¬«      \  }}||z  }|j/                  ||fd¬«      }|j*                  |z  ||z  z   |dd…d|…f<   | j                  r|j                  d¬«      |dd…df<   |j2                  dk(  r|j5                  d¬«      }|�||z  }nd|z  }t7        |«      D �]]  }|dd…|f   d|dd…|f   z
  z  |z  }t-        ||«      ||||z  |…|||z  |…f<   | j                  rV|j*                  |z  }|||||z  |…||z  |z   f<   ||||z  |z   |||z  |…f<   |j                  «       |||z  |z   ||z  |z   f<   t7        |dz   |«      D ]°  }|dd…|f    |dd…|f   z  |z  }t-        ||«      ||||z  |…|||z  |…f<   | j                  rV|j*                  |z  }|||||z  |…||z  |z   f<   ||||z  |z   |||z  |…f<   |j                  «       |||z  |z   ||z  |z   f<   ||d|…|d|…f   ||d|…|d|…f<   Œ² �Œ` |dkD  rJ|j                  j"                  rdnd}|j/                  d|¬«      d|dz  |z  |z  ||z  dz   …xx   |z  cc<   d}|||fS )a~  Computes gradient and hessian w.r.t. coef.

        Parameters
        ----------
        coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
            Coefficients of a linear model.
            If shape (n_classes * n_dof,), the classes of one feature are contiguous,
            i.e. one reconstructs the 2d-array via
            coef.reshape((n_classes, -1), order="F").
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data.
        y : contiguous array of shape (n_samples,)
            Observed, true target values.
        sample_weight : None or contiguous array of shape (n_samples,), default=None
            Sample weights.
        l2_reg_strength : float, default=0.0
            L2 regularization strength
        n_threads : int, default=1
            Number of OpenMP threads to use.
        gradient_out : None or ndarray of shape coef.shape
            A location into which the gradient is stored. If None, a new array
            might be created.
        hessian_out : None or ndarray of shape (n_dof, n_dof) or             (n_classes * n_dof, n_classes * n_dof)
            A location into which the hessian is stored. If None, a new array
            might be created.
        raw_prediction : C-contiguous array of shape (n_samples,) or array of             shape (n_samples, n_classes)
            Raw prediction values (in link space). If provided, these are used. If
            None, then raw_prediction = X @ coef + intercept is calculated.

        Returns
        -------
        gradient : ndarray of shape coef.shape
             The gradient of the loss.

        hessian : ndarray of shape (n_dof, n_dof) or             (n_classes, n_dof, n_dof, n_classes)
            Hessian matrix.

        hessian_warning : bool
            True if pointwise hessian has more than 25% of its elements non-positive.
        Nr   rD   z4gradient_out is required to have shape coef.shape = z; got ú.z"gradient_out must be F-contiguous.rC   z'hessian_out is required to have shape (z); got hessian_out.shape=zhessian_out must be contiguous.r:   r   r>   g      Ð?r*   ÚCr,   r   )r*   r*   rE   g      ð?r   F)r   r   r!   rG   r   r4   r1   r#   rI   rJ   r   Ú
ValueErrorr"   ÚflagsÚf_contiguousÚsizerK   Úc_contiguousÚgradient_hessianr@   Úabsr
   r   r.   Úgradient_probar-   rL   Úrange)r   r'   r   rA   r<   r6   r=   Úgradient_outÚhessian_outr3   r   r%   r!   r&   r0   r/   rN   rO   ÚnÚhessrM   Úhess_pointwiseÚhessian_warningr    ÚXhÚprobaÚswÚkÚhÚls                                 r   rZ   z LinearModelLoss.gradient_hessian¡  s÷  € ðn ./¯W©W°d·n±n×6NÑ6NÐ*Ñˆ�J ØœS ×!3Ñ!3Ó4Ñ4ˆØÐ!Ø15×1JÑ1JÈ4ÐQRÓ1SÑ.ˆG�Y¡à!%×!6Ñ!6°tÓ!<ÑˆG�YØ+Ð3‘¼¿¹ÀÓ9Nˆð ÐÜ—=‘= ¨W¯]©]À#ÔF‰DØ×Ñ 4§:¡:Ò-ÜØFÀtÇzÁzÀlð SØ#×)Ñ)Ð*¨!ð-óð ð �^‰^×)Ò)°,×2DÑ2D×2QÒ2QÜÐAÓBÐBàˆDà�I‰IˆØÐÜ—8‘8˜Q ˜F¨'¯-©-Ô8‰DØ×Ñ 1 a &Ò(ÜØ9¸!¸Q¸$¸ð @&Ø×$Ñ$Ð& að)óð ð �^‰^×)Ò)Ø×!Ñ!×.Ò.°{×7HÑ7H×7UÒ7UäÐ>Ó?Ð?àˆDà�~‰~×+Ó+Ø-1¯^©^×-LÑ-LØØ-Ø+Ø#ð	 .Mó .Ñ*ˆN˜Nð ˜fÑ$ˆNØ˜fÑ$ˆNô —
‘
˜>¨QÑ.¸ÔFÈÑMð ô  ŸV™V NÓ3ˆNà !§¡ nÑ 4°ÈÑ7PÑ PˆD��*ÐØ×!Ò!Ø)×-Ñ-Ó/��R‘áà˜T ?Ð2Ð2ä-9¸!¸^Ó-LˆD��*�˜k˜z˜kÐ)Ñ*à Ò"ð  $Ÿz™z×6Ò6™¸C�Ø—‘˜R u�Ó-Ø8�z EÑ)¨e°a©iÐ8óà$ñ%ó ð ×!Ó!ð —S‘S˜>Ñ)�Ø "��S�b�S˜"�W‘Ø "��R˜˜"˜�W‘Ø-×1Ñ1Ó3��V“ð %)§N¡N×$AÑ$AØØ-Ø+Ø#ð	 %Bó %Ñ!ˆN˜Eð ˜fÑ$ˆNØ—<‘< ¨EÐ 2¸#�<Ó>ˆDØ#1×#3Ñ#3°aÑ#7¸/ÈGÑ:SÑ#SˆD’�K�Z�K�Ñ Ø×!Ò!Ø,×0Ñ0°aÐ0Ó8�’Q˜�U‘Ø�y‰y˜AŠ~Ø—z‘z¨�zÓ,�ðL Ð(Ø" VÑ+‘à˜6‘\�ä˜9Ó%ó ,X�ð š!˜Q˜$‘K 1 uªQ°¨T¡{¡?Ñ3°bÑ8�ô !  AÓ&ð Ø˜	 JÑ.°Ð:Ø˜	 JÑ.°Ð:ð<ñð ×%Ò%àŸ™˜q™�Bð ð Ø˜I¨
Ñ2°YÐ>Ø! JÑ.°Ñ2ð4ñð ð Ø! JÑ.°Ñ2Ø˜I¨
Ñ2°YÐ>ð@ñð
 Ÿ™›ð ˜ ZÑ/°!Ñ3°YÀÑ5KÈaÑ5OÐOÑPô ˜q 1™u iÓ0ò X�Aàšq !˜t™˜ uªQ°¨T¡{Ñ2°RÑ7�Aô % Q¨Ó*ð Ø˜I¨
Ñ2°YÐ>Ø˜I¨
Ñ2°YÐ>ð@ñð ×)Ò)ØŸS™S 1™W˜ð ð Ø 	¨JÑ 6¸ÐBØ%¨
Ñ2°QÑ6ð8ñð ð Ø%¨
Ñ2°QÑ6Ø 	¨JÑ 6¸ÐBðDñð
 ŸE™E›Gð ˜Y¨Ñ3°aÑ7¸ÀZÑ9OÐRSÑ9SÐSÑTð 8<¸A¸L¸y¸LÈ!È,ÈYÈ,Ð<VÑ7W�D˜˜˜I˜ q |¨) |Ð3Ò4ò+Xð/,Xð\  Ò"à#Ÿz™z×6Ò6™¸C�Ø—‘˜R u�Ó-ØS�y !‘| jÑ0°5Ñ8¸YÈÑ=NÐQRÑ=RÐSóà$ñ%ó ð
 $ˆOà�T˜?Ð*Ð*r   c                 óB  ‡ ‡‡‡‡‡‡‡‡‡‡‡‡‡— ‰j                   ‰ j                  j                  c\  }ŠŠ‰t        ‰ j                  «      z   Š‰ j                  ‰‰«      \  Š}}	‰€|nt        j                  ‰«      Š‰ j                  j                  �sJ‰ j                  j                  ||	‰|¬«      \  }
}|
‰z  }
|‰z  }t        j                  ‰‰j                  ¬«      }‰j                  |
z  ‰‰z  z   |d‰ ‰ j                  r|
j                  «       |d<   |j                  «       Št        j                  ‰«      rt        j                  |df||f¬«      ‰z  Šn|dd…t        j                   f   ‰z  Š‰ j                  rMt        j"                  t        j$                  ‰j                  d¬«      «      «      Št        j&                  ‰«      Šˆˆˆˆˆˆˆ fd„}||fS ‰ j                  j)                  ||	‰|¬«      \  }
Š|
‰z  }
t        j*                  ‰‰f‰j                  d	¬
«      }|
j                  ‰z  ‰‰z  z   |dd…d‰…f<   ‰ j                  r|
j                  d¬«      |dd…df<   ˆˆˆˆˆˆˆˆˆ ˆˆfd„}‰j,                  dk(  r|j/                  d	¬«      |fS ||fS )a¡  Computes gradient and hessp (hessian product function) w.r.t. coef.

        Parameters
        ----------
        coef : ndarray of shape (n_dof,), (n_classes, n_dof) or (n_classes * n_dof,)
            Coefficients of a linear model.
            If shape (n_classes * n_dof,), the classes of one feature are contiguous,
            i.e. one reconstructs the 2d-array via
            coef.reshape((n_classes, -1), order="F").
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training data.
        y : contiguous array of shape (n_samples,)
            Observed, true target values.
        sample_weight : None or contiguous array of shape (n_samples,), default=None
            Sample weights.
        l2_reg_strength : float, default=0.0
            L2 regularization strength
        n_threads : int, default=1
            Number of OpenMP threads to use.

        Returns
        -------
        gradient : ndarray of shape coef.shape
             The gradient of the loss.

        hessp : callable
            Function that takes in a vector input of shape of gradient and
            and returns matrix-vector product with hessian.
        Nr:   rC   r*   r   r   rE   c                 ó‚  •— t        j                  | «      }t        j                  ‰«      r‰j                  ‰| d ‰ z  z  |d ‰ n2t         j
                  j                  ‰j                  ‰| d ‰ g«      |d ‰ |d ‰xxx ‰| d ‰ z  z  ccc ‰j                  r(|d ‰xxx | d   ‰z  z  ccc ‰| d ‰ z  ‰| d   z  z   |d<   |S )Nr*   )r#   rJ   r   r	   r
   ÚlinalgÚ	multi_dotr   )	ÚsÚretr   ÚhXÚhX_sumÚhessian_sumr6   r%   r   s	     €€€€€€€r   Úhesspz7LinearModelLoss.gradient_hessian_product.<locals>.hesspë  sÐ   ø€ Ü—m‘m AÓ&�Ü—?‘? 1Ô%Ø'(§s¡s¨b°1°[°j°>Ñ.AÑ'B�C˜˜Ñ$ä')§y¡y×':Ñ':¸A¿C¹CÀÀQÀ{È
À^Ð;TÓ'U�C˜˜Ð$Ø�K�ZÓ  O°a¸¸°nÑ$DÑDÓ à×%Ò%Ø˜˜Ó$¨¨"©°©Ñ6Ó$Ø$ q¨¨* ~Ñ5¸ÀaÈÁeÑ8KÑK�C˜‘GØ�
r   r   rD   c                 óV  •— | j                  ‰dfd¬«      } ‰j                  r| d d …df   }| d d …d d…f   } nd}‰| j                  z  |z   }|‰
 |z  j                  d¬«      d d …t        j
                  f   z  }|‰
z  }‰�|‰d d …t        j
                  f   z  }t	        j                  ‰‰f‰j                  d¬«      }|j                  ‰z  ‰z  ‰| z  z   |d d …d ‰	…f<   ‰j                  r|j                  d¬«      ‰z  |d d …df<   ‰j                  dk(  r|j                  d¬«      S |S )Nr*   r   r,   r   r   rE   rD   )
r.   r   r
   rI   r#   ÚnewaxisrK   r   r-   rL   )rn   Ús_interceptÚtmpÚ	hess_prodr   r'   r6   r!   r&   r%   re   r<   r   rN   r0   s       €€€€€€€€€€€r   rs   z7LinearModelLoss.gradient_hessian_product.<locals>.hessp  s8  ø€ Ø—I‘I˜y¨"˜o°S�IÓ9�Ø×%Ò%Ø"#¢A r E¡(�KØš!˜S˜b˜S˜&™	‘Aà"#�KØ˜!Ÿ#™#‘g Ñ+�Ø˜˜ ™×)Ñ)¨qÐ)Ó1²!´R·Z±Z°-Ñ@Ñ@�Ø�u‘�Ø Ð,Ø˜=ª¬B¯J©J¨Ñ7Ñ7�Cô ŸH™H i°Ð%7¸w¿}¹}ÐTWÔX�	Ø-0¯U©U°Q©Y¸&Ñ,@À?ÐUVÑCVÑ,V�	š!˜[˜j˜[˜.Ñ)Ø×%Ò%Ø'*§w¡w°A w£¸Ñ'?�Iša ˜eÑ$Ø—9‘9 ’>Ø$Ÿ?™?°˜?Ó5Ð5à$Ð$r   r   r,   )r   r   r!   rG   r   r4   r#   rI   r"   rZ   rJ   r   r
   r   r	   r   ru   ÚsqueezeÚasarrayÚ
atleast_1dr\   rK   r-   rL   )r   r'   r   rA   r<   r6   r=   r   r/   r3   rM   rb   rO   rs   rp   rq   rr   r!   r&   r%   re   rN   r0   s   ``` ``        @@@@@@@@@r   Úgradient_hessian_productz(LinearModelLoss.gradient_hessian_product¢  s‰  ÿý€ ð@ ./¯W©W°d·n±n×6NÑ6NÐ*Ñˆ�J ØœS ×!3Ñ!3Ó4Ñ4ˆØ-1×-FÑ-FÀtÈQÓ-OÑ*ˆ�˜NØ+Ð3‘¼¿¹ÀÓ9Nˆà�~‰~×+Ó+Ø-1¯^©^×-LÑ-LØØ-Ø+Ø#ð	 .Mó .Ñ*ˆN˜Nð ˜fÑ$ˆNØ˜fÑ$ˆNÜ—=‘= ¨W¯]©]Ô;ˆDØ !§¡ nÑ 4°ÈÑ7PÑ PˆD��*ÐØ×!Ò!Ø)×-Ñ-Ó/��R‘ð )×,Ñ,Ó.ˆKÜ�‰˜qÔ!ä×%Ñ% ~°qÐ&9À)ÈYÐAWÔXØññ ð
 $¢A¤r§z¡z MÑ2°QÑ6�à×!Ò!ô Ÿ™¤B§J¡J¨r¯v©v¸1¨v«~Ó$>Ó?�äŸ™ vÓ.�÷ò ð\ �Uˆ{Ððw %)§N¡N×$AÑ$AØØ-Ø+Ø#ð	 %Bó %Ñ!ˆN˜Eð ˜fÑ$ˆNÜ—8‘8˜Y¨Ð.°g·m±mÈ3ÔOˆDØ#1×#3Ñ#3°aÑ#7¸/ÈGÑ:SÑ#SˆD’�K�Z�K�Ñ Ø×!Ò!Ø,×0Ñ0°aÐ0Ó8�’Q˜�U‘÷.%ö %ð. �y‰y˜AŠ~Ø—z‘z¨�zÓ,¨eÐ3Ð3à�Uˆ{Ðr   r   )Nr+   r   N)Nr+   r   NNN)Nr+   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   r1   r4   r8   r?   rH   rQ   rZ   r|   © r   r   r   r   %   s‹   „ ñ@òD+óò8%"òN2ò@/ð ØØØó4@ðv ØØØóLðf ØØØóGð\ ØØØØØó+ðD NOôWr   r   )	r€   Únumpyr#   Úscipyr   Úutils.extmathr   r   r   r�   r   r   ú<module>r…      s&   ðñó Ý å (ò÷.Tò Tr   