§
    	¼¸jG…  ã                   óJ   — d Z ddlZddlmZ ddlmZ d„ Z G d„ d¦  «        ZdS )	zA
Loss functions for linear models with raw_prediction = X @ coef
é    N)Úsparseé   )Úsquared_normc                 óä   — | j         d         }t          j        | ¦  «        r7| j        t          j        |df||f¬¦  «        z  | z                       ¦   «         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       úq/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/sklearn/linear_model/_linear_loss.pyÚsandwich_dotr      sy   € ð ”˜”
€IÝ„�qÑÔð àŒC•&Ô# Q¨ F°9¸iÐ2HÐIÑIÔIÑIÈAÑMß
Š'‰)Œ)ð	ð ˆ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_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                 ó"   — || _         || _        d S ©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¬¦  «        }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_like)r   r   r   Ú
n_featuresr!   Ún_dofÚcoefs          r   Úinit_zero_coefzLinearModelLoss.init_zero_coefl   s|   € ð  ”W˜Q”Zˆ
Ø”NÔ,ˆ	ØÔð 	Ø ‘NˆEˆEàˆEØŒ>Ô'ð 	>Ý”= ¨9°eÐ*<ÀEÐQTÐUÑUÔUˆDˆDå”= ¨%°uÐ=Ñ=Ô=ˆ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                 ó€   — |                       |¦  «        \  }}| 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¯   sX   € ð, "×2Ò2°4Ñ8Ô8Ñˆ�àŒ~Ô+ð 	7Ø ™[¨9Ñ4ˆNˆ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Ï   s5   € à'.¤|°qÒ'8Ð'8�'˜GÑ#Ð#½lÈ7Ñ>SÔ>SˆØ�_Ñ$ wÑ.Ð.r   r+   r   c                 ó  — |€|                       ||¦  «        \  }}	}n|                      |¦  «        \  }}	| j                             ||d|¬¦  «        }
t	          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Ô1SÑ.ˆG�Y  à!%×!6Ò!6°tÑ!<Ô!<ÑˆG�YàŒ~×"Ò"ØØ)ØØð	 #ñ 
ô 
ˆõ Œz˜$¨Ð6Ñ6Ô6ˆà�d—o’o g¨Ñ?Ô?Ñ?Ð?r   c                 óZ  — |j         | j        j        c\  }}	}
|	t          | j        ¦  «        z   }|€|                      ||¦  «        \  }}}n|                      |¦  «        \  }}| j                             ||||¬¦  «        \  }}|€|nt          j	        |¦  «        }| 	                    ¦   «         |z  }||  
                    ||¦  «        z  }||z  }| j        j        sOt          j        ||j        ¬¦  «        }|j        |z  ||z  z   |d|	…<   | j        r| 	                    ¦   «         |d<   n|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¬
¦  «        }||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°d´nÔ6NÐ*Ñˆ�J Ø�S Ô!3Ñ4Ô4Ñ4ˆàÐ!Ø15×1JÒ1JÈ4ÐQRÑ1SÔ1SÑ.ˆG�Y  à!%×!6Ò!6°tÑ!<Ô!<ÑˆG�Yà#œ~×;Ò;ØØ)Ø'Øð	  <ñ  
ô  
Ñˆˆnð ,Ð3��½¼ÀÑ9NÔ9NˆØ�xŠx‰zŒz˜FÑ"ˆØ�—’ ¨Ñ9Ô9Ñ9ˆà˜&Ñ ˆàŒ~Ô+ð 	-Ý”= ¨W¬]Ð;Ñ;Ô;ˆDØ !¤ nÑ 4°ÈÑ7PÑ PˆD��*�ÑØÔ!ð 0Ø)×-Ò-Ñ/Ô/��R‘øå”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Ñ,Ô,�à�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.
        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°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   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°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�Ñ-Ô-Ø8�z EÑ)¨e°a©iÐ8ðð ô à$ñ%ð ð ñ ð Ô!ð 
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.
        Nr:   rC   r*   r   r   rE   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#   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 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   rD   c                 óB  •— |                       ‰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   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  s\  ø€ Ø—I’I˜y¨"˜o°S�IÑ9Ô9�ØÔ%ð $Ø"# A A A r E¤(�KØ˜!˜!˜!˜S˜b˜S˜&œ	�A�Aà"#�KØ˜!œ#‘g Ñ+�Ø˜˜ ™×)Ò)¨qÐ)Ñ1Ô1°!°!°!µR´Z°-Ô@Ñ@�Ø�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   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°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åÔ% ~°qÐ&9À)ÈYÐAWÐXÑXÔXØñð �ð
 $ 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(   r1   r4   r8   r?   rH   rQ   rZ   r|   © r   r   r   r   %   s6  € € € € € ð@ð @ðD+ð +ð +ðð ð ð ð8%"ð %"ð %"ðN2ð 2ð 2ð@/ð /ð /ð ØØØð4@ð 4@ð 4@ð 4@ðv ØØØðLð Lð Lð Lðf ØØØðGð Gð Gð Gð\ ØØØØØð+ð +ð +ð +ðD NOðWð Wð Wð Wð Wð Wr   r   )	r€   Únumpyr#   Úscipyr   Úutils.extmathr   r   r   r�   r   r   ú<module>r…      sŒ   ððð ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à (Ð (Ð (Ð (Ð (Ð (ðð ð ð.Tð Tð Tð Tð Tñ Tô Tð Tð Tð Tr   