§
    rŠtja‹  ã                   ón   — d Z ddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZmZ d„ Z G d„ d	¦  «        ZdS )
zA
Loss functions for linear models with raw_prediction = X @ coef
é    N)Úsparse)Úget_namespaceÚget_namespace_and_deviceÚmove_to)Ú_align_api_if_sparse)Úsafe_sparse_dotÚsquared_normc           
      óô   — | j         d         }t          j        | ¦  «        r?t          t	          | j        t          j        |df||f¬¦  «        | z  d¬¦  «        ¦  «        S |dd…df         | z  }| j        |z  S )z/Compute the sandwich product X.T @ diag(W) @ X.r   ©ÚshapeT)Údense_outputN)r   r   Úissparser   r   ÚTÚ	dia_array)ÚXÚWÚ	n_samplesÚWXs       ú_/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sklearn/linear_model/_linear_loss.pyÚsandwich_dotr      s�   € ð ”˜”
€IÝ„�qÑÔð Ý#ÝØ”ÝÔ  ! Q °	¸9Ð/EÐFÑFÔFÈÑJØ!ðñ ô ñ
ô 
ð 	
ð ˆqˆqˆq�$ˆwŒZ˜!‰^ˆØŒ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dS )Ú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_classes * n_features:] = coef[(n_dof-1):]
            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 classes are expected to be
    contiguous, i.e. 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                 ó"   — || _         || _        d S ©N)Ú	base_lossÚfit_intercept)Úselfr   r   s      r   Ú__init__zLinearModelLoss.__init__s   s   € Ø"ˆŒØ*ˆÔÐÐr   Nc                 óÎ   — |j         d         }| j        j        }| j        r|dz   }n|}| j        j        rt          j        ||f|d¬¦  «        }n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)r   r   r#   Ú
n_featuresr%   Ún_dofÚcoefs          r   Úinit_zero_coefzLinearModelLoss.init_zero_coefw   sw   € ð  ”W˜Q”Zˆ
Ø”NÔ,ˆ	ØÔð 	Ø ‘NˆEˆEàˆEØŒ>Ô'ð 	6Ý”8 9¨eÐ"4¸EÈÐMÑMÔMˆDˆDå”8 %¨uÐ5Ñ5Ô5ˆDØˆr   c                 ó
  — | j         j        s| j        r|d         }|dd…         }nZd}|}nU|j        dk    r$|                     | j         j        dfd¬¦  «        }n|}| j        r|dd…df         }|dd…dd…f         }n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 ˜sœ)��à�	Ø��ð Œy˜AŠ~ˆ~ØŸ,š,¨¬Ô(@À"Ð'EÈS˜,ÑQÔQ��à�ØÔ!ð  Ø# A A A r EœN�	Ø! ! ! ! S b S &œ/��à�	à˜	Ð!Ð!r   c                 ó  — |                       |¦  «        \  }}t          |¦  «        \  }}}|                     ||j        |¬¦  «        }|                     ||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)
        )r#   Údevice)r5   r   Úasarrayr#   r   r&   r   )r   r+   r   r4   r3   ÚxpÚ_Údevice_Ú
weights_xpÚintercept_xpÚraw_predictions              r   Úweight_intercept_rawz$LinearModelLoss.weight_intercept_rawº   s    € ð, "×2Ò2°4Ñ8Ô8Ñˆ�Ý1°!Ñ4Ô4‰ˆˆAˆwð —Z’Z ¨q¬w¸w�ZÑGÔGˆ
Ø—z’z )°1´7À7�zÑKÔKˆØŒ~Ô+ð 	=Ø ™^¨lÑ:ˆNˆNð  ¤Ñ-°Ñ<ˆNà˜	 >Ð1Ð1r   c                 ój   — |j         dk    r||z  nt          |¦  «        }t          d|z  |z  ¦  «        S )z5Compute L2 penalty term l2_reg_strength/2 *||w||_2^2.r!   g      à?)r1   r	   Úfloat)r   r4   Úl2_reg_strengthÚnorm2_ws       r   Ú
l2_penaltyzLinearModelLoss.l2_penaltyâ   s=   € à'.¤|°qÒ'8Ð'8�'˜GÑ#Ð#½lÈ7Ñ>SÔ>SˆÝ�S˜?Ñ*¨WÑ4Ñ5Ô5Ð5r   r/   r!   c                 ó¨  — |j         d         }|€|                      ||¦  «        \  }	}
}n|                      |¦  «        \  }	}
| j                             ||||¬¦  «        }t          |||¦  «        \  }}|€|n|                     |¦  «        }t          |                     |¦  «        |z  ¦  «        }|dk    r||                      |	|¦  «        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.
        r   N©Úy_truer>   Úsample_weightÚ	n_threads)	r   r?   r5   r   Úlossr   ÚsumrA   rD   )r   r+   r   ÚyrH   rB   rI   r>   r   r4   r3   rJ   r9   r:   Úsw_sums                  r   rJ   zLinearModelLoss.lossç   sê   € ðN ”G˜A”Jˆ	ØÐ!Ø15×1JÒ1JÈ4ÐQRÑ1SÔ1SÑ.ˆG�Y  à!%×!6Ò!6°tÑ!<Ô!<ÑˆG�YàŒ~×"Ò"ØØ)Ø'Øð	 #ñ 
ô 
ˆõ ˜a  MÑ2Ô2‰ˆˆAØ+Ð3��¸¿ºÀÑ9NÔ9NˆÝ�R—V’V˜D‘\”\ FÑ*Ñ+Ô+ˆà˜QÒÐØ�D—O’O G¨_Ñ=Ô=Ñ=ˆDàˆr   c                 ó*  — |j         | j        j        c\  }}	}
|	t          | j        ¦  «        z   }|€|                      ||¦  «        \  }}}n|                      |¦  «        \  }}| j                             ||||¬¦  «        \  }}t          |||¦  «        \  }}|€|n| 	                    |¦  «        }t          | 	                    |¦  «        |z  ¦  «        }||                      ||¦  «        z  }||z  }| j        j        sgt          j        ||j        ¬¦  «        }|j        |z  }t#          |t          d¬¦  «        ||z  z   |d|	…<   | j        r| 	                    |¦  «        |d<   n©t          j        |
|f|j        d¬¦  «        }|j        |z  }t#          |t          d¬¦  «        ||z  z   |dd…d|	…f<   | j        r3t#          | 	                    |d	¬
¦  «        t          d¬¦  «        |dd…df<   |j        dk    r|                     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.
        NrF   ©r#   Úcpu)r9   r7   r.   r"   ©r#   r$   r   ©Úaxisr!   r0   )r   r   r%   Úintr   r?   r5   Úloss_gradientr   rK   rA   rD   r&   r'   Ú
empty_liker#   r   r   Úemptyr1   Úravel)r   r+   r   rL   rH   rB   rI   r>   r   r)   r%   r*   r4   r3   rJ   Úgrad_pointwiser9   r:   rM   ÚgradÚX_gradÚgrad_Xs                         r   rU   zLinearModelLoss.loss_gradient#  sS  € ðT ./¬W°d´nÔ6NÐ*Ñˆ�J Ø�S Ô!3Ñ4Ô4Ñ4ˆàÐ!Ø15×1JÒ1JÈ4ÐQRÑ1SÔ1SÑ.ˆG�Y  à!%×!6Ò!6°tÑ!<Ô!<ÑˆG�Yà#œ~×;Ò;ØØ)Ø'Øð	  <ñ  
ô  
Ñˆˆnõ ˜a  MÑ2Ô2‰ˆˆAØ+Ð3��¸¿ºÀÑ9NÔ9NˆÝ�R—V’V˜D‘\”\ FÑ*Ñ+Ô+ˆØ�—’ ¨Ñ9Ô9Ñ9ˆà˜&Ñ ˆàŒ~Ô+ð 	-Ý”= ¨W¬]Ð;Ñ;Ô;ˆDØ”S˜>Ñ)ˆFå˜¥2¨eÐ4Ñ4Ô4°ÈÑ7PÑPð ��*�Ñð Ô!ð 2ØŸ6š6 .Ñ1Ô1��R‘øõ
 ”8˜Y¨Ð.°g´mÈ3ÐOÑOÔOˆDà#Ô%¨Ñ)ˆFå˜¥2¨eÐ4Ñ4Ô4°ÈÑ7PÑPð ����K�Z�K�Ñ ð Ô!ð Ý%Ø—F’F˜>°�FÑ2Ô2µrÀ%ðñ ô ��Q�Q�Q˜�U‘ð Œy˜AŠ~ˆ~Ø—z’z¨�zÑ,Ô,�à�TˆzÐr   c                 óò  — |j         | j        j        c\  }}	}
|	t          | j        ¦  «        z   }|€|                      ||¦  «        \  }}}n|                      |¦  «        \  }}| j                             ||||¬¦  «        }|€|nt          j	        |¦  «        }||z  }| j        j
        sPt          j        ||j        ¬¦  «        }|j        |z  ||z  z   |d|	…<   | j        r| 	                    ¦   «         |d<   |S t          j        |
|f|j        d¬¦  «        }|j        |z  ||z  z   |dd…d|	…f<   | j        r| 	                    d¬¦  «        |dd…df<   |j        d	k    r|                     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.
        NrF   rO   r.   r"   rQ   r   rR   r!   r0   )r   r   r%   rT   r   r?   r5   Úgradientr'   rK   r&   rV   r#   r   rW   r1   rX   )r   r+   r   rL   rH   rB   rI   r>   r   r)   r%   r*   r4   r3   rY   rM   rZ   s                    r   r^   zLinearModelLoss.gradient}  s¸  € ðN ./¬W°d´nÔ6NÐ*Ñˆ�J Ø�S Ô!3Ñ4Ô4Ñ4ˆàÐ!Ø15×1JÒ1JÈ4ÐQRÑ1SÔ1SÑ.ˆG�Y  à!%×!6Ò!6°tÑ!<Ô!<ÑˆG�Yàœ×0Ò0ØØ)Ø'Øð	 1ñ 
ô 
ˆð ,Ð3��½¼ÀÑ9NÔ9NˆØ˜&Ñ ˆàŒ~Ô+ð 	Ý”= ¨W¬]Ð;Ñ;Ô;ˆDØ !¤ nÑ 4°ÈÑ7PÑ PˆD��*�ÑØÔ!ð 0Ø)×-Ò-Ñ/Ô/��R‘ØˆKå”8˜Y¨Ð.°g´mÈ3ÐOÑOÔOˆDà#1Ô#3°aÑ#7¸/ÈGÑ:SÑ#SˆD����K�Z�K�Ñ ØÔ!ð 9Ø,×0Ò0°aÐ0Ñ8Ô8��Q�Q�Q˜�U‘ØŒy˜AŠ~ˆ~Ø—z’z¨�zÑ,Ô,Ð,à�r   c
                 ó`
  — |j         | j        j        c\  }
}}|t          | j        ¦  «        z   }|	€|                      ||¦  «        \  }}}	n|                      |¦  «        \  }}|€|
nt          j        |¦  «        }|€t          j	        ||j
        d¬¦  «        }nY|j         |j         k    r t          d|j         › d|j         › d�¦  «        ‚| j        j        r|j        j        st          d¦  «        ‚|}|j        }|€t          j        ||f|j
        ¬¦  «        }n_|j         ||fk    rt          d	||f› d
|j         ›d�¦  «        ‚| j        j        r'|j        j        s|j        j        st          d¦  «        ‚|}| j        j        �s0| j                             ||	||¬¦  «        \  }}||z  }||z  }t          j        |dk    |¬¦  «        dk    }t          j        |¦  «        }|j        |z  ||z  z   |d|…<   | j        r|                     ¦   «         |d<   |r|||fS t-          ||¦  «        |d|…d|…f<   |dk    r>|j        j        rdnd}|                     d|¬¦  «        d||z  |dz   …xx         |z  cc<   | j        r3|j        |z  }||dd…df<   ||ddd…f<   |                     ¦   «         |d<   �nt| j                             ||	||¬¦  «        \  }}||z  }|                     ||fd¬¦  «        }|j        |z  ||z  z   |dd…d|…f<   | j        r|                     d¬¦  «        |dd…df<   |j        dk    r|                     d¬¦  «        }|�||z  }nd|z  }t7          |¦  «        D �]j}|dd…|f         d|dd…|f         z
  z  |z  }t-          ||¦  «        ||||z  |…|||z  |…f<   | j        rU|j        |z  }|||||z  |…||z  |z   f<   ||||z  |z   |||z  |…f<   |                     ¦   «         |||z  |z   ||z  |z   f<   t7          |dz   |¦  «        D ]·}|dd…|f          |dd…|f         z  |z  }t-          ||¦  «        ||||z  |…|||z  |…f<   | j        rU|j        |z  }|||||z  |…||z  |z   f<   ||||z  |z   |||z  |…f<   |                     ¦   «         |||z  |z   ||z  |z   f<   ||d|…|d|…f         ||d|…|d|…f<   Œ¸�Œl|dk    rG|j        j        rdnd}|                     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"   rQ   z4gradient_out is required to have shape coef.shape = z; got ú.z"gradient_out must be F-contiguous.rO   z'hessian_out is required to have shape (z); got hessian_out.shape=zhessian_out must be contiguous.rF   r   )r4   g      Ð?r.   ÚCr0   r!   )r.   r.   rR   g      ð?é   F)r   r   r%   rT   r   r?   r5   r'   rK   rV   r#   Ú
ValueErrorr&   ÚflagsÚf_contiguousÚsizerW   Úc_contiguousÚgradient_hessianÚaverageÚabsr   r   r2   Úgradient_probar1   rX   Úrange)r   r+   r   rL   rH   rB   rI   Úgradient_outÚhessian_outr>   r   r)   r%   r*   r4   r3   rM   rZ   ÚnÚhessrY   Úhess_pointwiseÚhessian_warningr$   ÚXhÚprobaÚswÚkÚhÚls                                 r   rh   z LinearModelLoss.gradient_hessianÆ  s™  € ðn ./¬W°d´nÔ6NÐ*Ñˆ�J Ø�S Ô!3Ñ4Ô4Ñ4ˆØÐ!Ø15×1JÒ1JÈ4ÐQRÑ1SÔ1SÑ.ˆG�Y  à!%×!6Ò!6°tÑ!<Ô!<ÑˆG�YØ+Ð3��½¼ÀÑ9NÔ9Nˆð ÐÝ”= ¨W¬]À#ÐFÑFÔFˆDˆDØÔ 4¤:Ò-Ð-Ýð-ÀtÄzð -ð -Ø#Ô)ð-ð -ð -ñô ð ð Œ^Ô)ð 	 °,Ô2DÔ2Qð 	 ÝÐAÑBÔBÐBàˆDàŒIˆØÐÝ”8˜Q ˜F¨'¬-Ð8Ñ8Ô8ˆDˆDØÔ 1 a &Ò(Ð(Ýð)¸!¸Q¸ð )ð )ØÔ$ð)ð )ð )ñô ð ð Œ^Ô)ð 	ØÔ!Ô.ð	Ø7BÔ7HÔ7Uð	õ Ð>Ñ?Ô?Ð?àˆDàŒ~Ô+ñ b	$Ø-1¬^×-LÒ-LØØ-Ø+Ø#ð	 .Mñ .ô .Ñ*ˆN˜Nð ˜fÑ$ˆNØ˜fÑ$ˆNõ ”
˜>¨QÒ.¸ÐFÑFÔFÈÒMð õ  œV NÑ3Ô3ˆNà !¤ nÑ 4°ÈÑ7PÑ PˆD��*�ÑØÔ!ð 0Ø)×-Ò-Ñ/Ô/��R‘àð 3à˜T ?Ð2Ð2å-9¸!¸^Ñ-LÔ-LˆD��*�˜k˜z˜kÐ)Ñ*à Ò"Ð"ð  $œzÔ6Ð?˜˜¸C�Ø—’˜R u�Ñ-Ô-Ð.R°¸eÑ1CÈÐPQÉ	Ð.RÐSÐSÔSØ#ñÐSÐSÑSð Ô!ð 
4ð ”S˜>Ñ)�Ø "��S�b�S˜"�W‘Ø "��R˜˜"˜�W‘Ø-×1Ò1Ñ3Ô3��V‘ùð %)¤N×$AÒ$AØØ-Ø+Ø#ð	 %Bñ %ô %Ñ!ˆN˜Eð ˜fÑ$ˆNØ—<’< ¨EÐ 2¸#�<Ñ>Ô>ˆDØ#1Ô#3°aÑ#7¸/ÈGÑ:SÑ#SˆD����K�Z�K�Ñ ØÔ!ð 9Ø,×0Ò0°aÐ0Ñ8Ô8��Q�Q�Q˜�U‘ØŒy˜AŠ~ˆ~Ø—z’z¨�zÑ,Ô,�ðL Ð(Ø" VÑ+��à˜6‘\�å˜9Ñ%Ô%ð ,Xñ ,X�ð ˜!˜!˜!˜Q˜$”K 1 u¨Q¨Q¨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Ô0ð Xð X�Aà˜q˜q˜q !˜tœ˜ u¨Q¨Q¨Q°¨T¤{Ñ2°RÑ7�Aõ % Q¨Ñ*Ô*ð Ø˜I¨
Ñ2°YÐ>Ø˜I¨
Ñ2°YÐ>ð@ñð Ô)ð ØœS 1™W˜ð ð Ø 	¨JÑ 6¸ÐBØ%¨
Ñ2°QÑ6ð8ñð ð Ø%¨
Ñ2°QÑ6Ø 	¨JÑ 6¸ÐBðDñð
 ŸEšE™GœGð ˜Y¨Ñ3°aÑ7¸ÀZÑ9OÐRSÑ9SÐSÑTð 8<¸A¸L¸y¸LÈ!È,ÈYÈ,Ð<VÔ7W�D˜˜˜I˜ q |¨) |Ð3Ñ4Ð4ñ+Xð.  Ò"Ð"à#œzÔ6Ð?˜˜¸C�Ø—’˜R u�Ñ-Ô-ØS�y !‘| jÑ0°5Ñ8¸YÈÑ=NÐQRÑ=RÐSðð ô à$ñ%ð ð ñ ð
 $ˆOà�T˜?Ð*Ð*r   c                 óØ  ‡ ‡‡‡‡‡‡‡‡‡‡‡‡‡— ‰j         ‰ j        j        c\  }ŠŠ‰t          ‰ j        ¦  «        z   Š‰                      ‰‰¦  «        \  Š}}	‰€|nt          j        ‰¦  «        Š‰ j        j        �s9‰ j         	                    ||	‰|¬¦  «        \  }
}|
‰z  }
|‰z  }t          j
        ‰‰j        ¬¦  «        }‰j        |
z  ‰‰z  z   |d‰…<   ‰ j        r|
                     ¦   «         |d<   |                     ¦   «         Št          j        ‰¦  «        rt          j        |df||f¬¦  «        ‰z  Šn|dd…t          j        f         ‰z  Š‰ j        rNt          j        t          j        ‰                     d¬¦  «        ¦  «        ¦  «        Št          j        ‰¦  «        Šˆˆˆˆˆˆˆ fd„}n³‰ j                             ||	‰|¬¦  «        \  }
Š|
‰z  }
t          j        ‰‰f‰j        d	¬
¦  «        }|
j        ‰z  ‰‰z  z   |dd…d‰…f<   ‰ j        r|
                     d¬¦  «        |dd…df<   ˆˆˆˆˆˆˆˆˆ ˆˆfd„}‰j        dk    r|                     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.
        NrF   rO   r.   r   r   rR   c                 ó¬  •— t          j        | ¦  «        }t          j        ‰¦  «        r‰j        ‰| d ‰…         z  z  |d ‰…<   n4t           j                             ‰j        ‰| d ‰…         g¦  «        |d ‰…<   |d ‰…xx         ‰| d ‰…         z  z  cc<   ‰j        r7|d ‰…xx         | d         ‰z  z  cc<   ‰| d ‰…         z  ‰| d         z  z   |d<   |S )Nr.   )r'   rV   r   r   r   ÚlinalgÚ	multi_dotr   )	ÚsÚretr   ÚhXÚhX_sumÚhessian_sumrB   r)   r   s	     €€€€€€€r   Úhesspz7LinearModelLoss.gradient_hessian_product.<locals>.hessp  s  ø€ Ý”m AÑ&Ô&�Ý”? 1Ñ%Ô%ð VØ'(¤s¨b°1°[°j°[´>Ñ.AÑ'B�C˜˜˜Ñ$Ð$å')¤y×':Ò':¸A¼CÀÀQÀ{È
À{Ä^Ð;TÑ'UÔ'U�C˜˜˜Ñ$Ø�K�Z�KÐ Ð Ô  O°a¸¸¸´nÑ$DÑDÐ Ð Ñ àÔ%ð LØ˜˜˜Ð$Ð$Ô$¨¨"¬°©Ñ6Ð$Ð$Ñ$Ø$ q¨¨*¨¤~Ñ5¸ÀaÈÄeÑ8KÑK�C˜‘GØ�
r   r"   rQ   c                 ó@  •— |                       ‰dfd¬¦  «        } ‰j        r| d d …df         }| d d …d d…f         } nd}‰| j        z  |z   }|‰
|z                       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 |                     d¬¦  «        ‰z  |d d …df<   ‰j        dk    r| 	                    d¬¦  «        S |S )Nr.   r"   r0   r   r!   rR   rQ   )
r2   r   r   rK   r'   ÚnewaxisrW   r#   r1   rX   )r}   Ús_interceptÚtmpÚ	hess_prodr   r+   rB   r%   r*   r)   rt   rH   r   rM   r4   s       €€€€€€€€€€€r   r‚   z7LinearModelLoss.gradient_hessian_product.<locals>.hesspD  sZ  ø€ Ø—I’I˜y¨"˜o°S�IÑ9Ô9�ØÔ%ð $Ø"# A A A r E¤(�KØ˜!˜!˜!˜S˜b˜S˜&œ	�A�Aà"#�KØ˜!œ#‘g Ñ+�Ø˜ ™×(Ò(¨aÐ(Ñ0Ô0°°°µB´J°Ô?Ñ?�Ø�u‘�Ø Ð,Ø˜=¨¨¨­B¬J¨Ô7Ñ7�Cõ œH i°Ð%7¸w¼}ÐTWÐXÑXÔX�	Ø-0¬U°Q©Y¸&Ñ,@À?ÐUVÑCVÑ,V�	˜!˜!˜!˜[˜j˜[˜.Ñ)ØÔ%ð @Ø'*§w¢w°A w¡¤¸Ñ'?�I˜a˜a˜a ˜eÑ$Ø”9 ’>�>Ø$Ÿ?š?°˜?Ñ5Ô5Ð5à$Ð$r   r!   r0   )r   r   r%   rT   r   r?   r'   rK   r&   rh   rV   r#   r   r   r   r   r„   Úsqueezer8   Ú
atleast_1drk   rW   r1   rX   )r   r+   r   rL   rH   rB   rI   r   r3   r>   rY   rq   rZ   r‚   r   r€   r�   r%   r*   r)   rt   rM   r4   s   ``` ``        @@@@@@@@@r   Úgradient_hessian_productz(LinearModelLoss.gradient_hessian_productÇ  s-  øøøøøøøøøøøøøø€ ð@ ./¬W°d´nÔ6NÐ*Ñˆ�J Ø�S Ô!3Ñ4Ô4Ñ4ˆØ-1×-FÒ-FÀtÈQÑ-OÔ-OÑ*ˆ�˜NØ+Ð3��½¼ÀÑ9NÔ9NˆàŒ~Ô+ñ p	4Ø-1¬^×-LÒ-LØØ-Ø+Ø#ð	 .Mñ .ô .Ñ*ˆN˜Nð ˜fÑ$ˆNØ˜fÑ$ˆNÝ”= ¨W¬]Ð;Ñ;Ô;ˆDØ !¤ nÑ 4°ÈÑ7PÑ PˆD��*�ÑØÔ!ð 0Ø)×-Ò-Ñ/Ô/��R‘ð )×,Ò,Ñ.Ô.ˆKÝŒ˜qÑ!Ô!ð 7åÔ$ n°aÐ%8ÀÈIÐ@VÐWÑWÔWØñð �ð
 $ A A A¥r¤z MÔ2°QÑ6�àÔ!ð /õ œ¥B¤J¨r¯vªv¸1¨v©~¬~Ñ$>Ô$>Ñ?Ô?�åœ vÑ.Ô.�ðð ð ð ð ð ð ð ð ð ð ð ð& %)¤N×$AÒ$AØØ-Ø+Ø#ð	 %Bñ %ô %Ñ!ˆN˜Eð ˜fÑ$ˆNÝ”8˜Y¨Ð.°g´mÈ3ÐOÑOÔOˆDØ#1Ô#3°aÑ#7¸/ÈGÑ:SÑ#SˆD����K�Z�K�Ñ ØÔ!ð 9Ø,×0Ò0°aÐ0Ñ8Ô8��Q�Q�Q˜�U‘ð.%ð %ð %ð %ð %ð %ð %ð %ð %ð %ð %ð %ð %ð %ð %ð. Œ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,   r5   r?   rD   rJ   rU   r^   rh   rŠ   © r   r   r   r   /   s2  € € € € € ðAð AðF+ð +ð +ðð ð ð ð8%"ð %"ð %"ðN&2ð &2ð &2ðP6ð 6ð 6ð ØØØð:ð :ð :ð :ðB ØØØðXð Xð Xð Xð~ ØØØðGð Gð Gð Gð\ ØØØØØð+ð +ð +ð +ðD NOðWð Wð Wð Wð Wð Wr   r   )rŽ   Únumpyr'   Úscipyr   Úsklearn.utils._array_apir   r   r   Úsklearn.utils._sparser   Úsklearn.utils.extmathr   r	   r   r   r�   r   r   ú<module>r•      sØ   ððð ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð ð ð
 7Ð 6Ð 6Ð 6Ð 6Ð 6Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?ðð ð ð6oð oð oð oð oñ oô oð oð oð or   