§
    ¨éUg­h  ã                   óD   — d Z ddlZddlmZ ddlmZ  G d„ d¦  «        ZdS )zA
Loss functions for linear models with raw_prediction = X @ coef
é    N)Úsparseé   )Úsquared_normc                   ó€   — 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]

    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      ú`/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/sklearn/linear_model/_linear_loss.pyÚ__init__zLinearModelLoss.__init__E   s   € Ø"ˆŒØ*ˆÔÐÐó    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)ÚshapeÚdtypeÚorder©r   r   )r   r
   Ú	n_classesr   Úis_multiclassÚnpÚ
zeros_like)r   ÚXr   Ú
n_featuresr   Ún_dofÚcoefs          r   Úinit_zero_coefzLinearModelLoss.init_zero_coefI   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_intercepte   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)
        )r(   r
   r   ÚT)r   r   r   r'   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   r'   Ú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_truer+   Úsample_weightÚ	n_threads)r'   )r,   r(   r
   Úlossr   Úaverager0   )r   r   r   Úyr4   r.   r5   r+   r'   r&   r6   s              r   r6   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.
        Nr2   ©r   r!   r   ©r   r   r   ©Úaxisr   r#   )r   r
   r   Úintr   r,   r(   Úloss_gradientr   Úsumr0   r   Ú
empty_liker   r*   Úemptyr$   Úravel)r   r   r   r8   r4   r.   r5   r+   Ú	n_samplesr   r   r   r'   r&   r6   Úgrad_pointwiseÚsw_sumÚgrads                     r   r?   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.
        Nr2   r:   r!   r   r;   r   r<   r   r#   )r   r
   r   r>   r   r,   r(   Úgradientr   r@   r   rA   r   r*   rB   r$   rC   )r   r   r   r8   r4   r.   r5   r+   rD   r   r   r   r'   r&   rE   rF   rG   s                    r   rI   zLinearModelLoss.gradient5  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         \  }
}|t          | j        ¦  «        z   }|	€|                      ||¦  «        \  }}}	n|                      |¦  «        \  }}| j                             ||	||¬¦  «        \  }}|€|
nt          j        |¦  «        }||z  }||z  }t          j	        |dk    ¦  «        dk    }t          j
        |¦  «        }| j        j        �sp|€t          j        ||j        ¬¦  «        }n|}|j        |z  ||z  z   |d|…<   | j        r|                     ¦   «         |d<   |€t          j        ||f|j        ¬¦  «        }n|}|r|||fS t!          j        |¦  «        rA|j        t!          j        |df|
|
f¬¦  «        z  |z                       ¦   «         |d|…d|…f<   n2|dd…df         |z  }t          j        |j        |¦  «        |d|…d|…f<   |dk    r,|                     d¦  «        d||z  |d	z   …xx         |z  cc<   | j        r3|j        |z  }||dd…df<   ||ddd…f<   |                     ¦   «         |d
<   nt,          ‚|||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
            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
            Hessian matrix.

        hessian_warning : bool
            True if pointwise hessian has more than half of its elements non-positive.
        Nr2   r   g      Ð?r:   r!   r   ©r   r   )r!   r!   )r   r>   r   r,   r(   r
   Úgradient_hessianr   r@   ÚmeanÚabsr   rA   r   r*   rB   r   ÚissparseÚ
dia_matrixÚtoarrayÚdotr%   ÚNotImplementedError)r   r   r   r8   r4   r.   r5   Úgradient_outÚhessian_outr+   rD   r   r   r'   r&   rE   Úhess_pointwiserF   Úhessian_warningrG   ÚhessÚWXÚXhs                          r   rL   z LinearModelLoss.gradient_hessian~  s  € ðj !"¤Ñˆ	�:Ø�S Ô!3Ñ4Ô4Ñ4ˆàÐ!Ø15×1JÒ1JÈ4ÐQRÑ1SÔ1SÑ.ˆG�Y  à!%×!6Ò!6°tÑ!<Ô!<ÑˆG�Yà)-¬×)HÒ)HØØ)Ø'Øð	 *Iñ *
ô *
Ñ&ˆ˜ð ,Ð3��½¼ÀÑ9NÔ9NˆØ˜&Ñ ˆØ˜&Ñ ˆõ
 œ' .°AÒ"5Ñ6Ô6¸Ò=ˆÝœ Ñ/Ô/ˆàŒ~Ô+ñ :	&àÐ#Ý”} T°´Ð?Ñ?Ô?��à#�Ø !¤ nÑ 4°ÈÑ7PÑ PˆD��*�ÑØÔ!ð 0Ø)×-Ò-Ñ/Ô/��R‘ð Ð"Ý”x u¨e n¸G¼MÐJÑJÔJ��à"�àð 3à˜T ?Ð2Ð2õ
 Œ˜qÑ!Ô!ð Aà”CÝÔ'Ø'¨Ð+°I¸yÐ3Iðñ ô ñð ñ	÷
 ’'‘)”)ð �[�j�[ + : +Ð-Ñ.Ð.ð $ A A A t GÔ,¨qÑ0�Ý13´¸¼¸R±´��[�j�[ + : +Ð-Ñ.à Ò"Ð"ð —’˜RÑ Ô Ø8�z EÑ)¨e°a©iÐ8ðð ô à$ñ%ð ð ñ ð Ô!ð 
4ð ”S˜>Ñ)�Ø "��S�b�S˜"�W‘Ø "��R˜˜"˜�W‘Ø-×1Ò1Ñ3Ô3��V‘øõ &Ð%à�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.
        Nr2   r:   r!   r   rK   r<   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   rA   r   rO   r*   ÚlinalgÚ	multi_dotr   )	ÚsÚretr   ÚhXÚhX_sumÚhessian_sumr.   r   r   s	     €€€€€€€r   Úhesspz7LinearModelLoss.gradient_hessian_product.<locals>.hesspR  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   r;   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   r<   r;   )
r%   r   r*   r@   r   ÚnewaxisrB   r   r$   rC   )r_   Ús_interceptÚtmpÚ	hess_prodr   r   r.   r   r   r   Úprobar4   r   rF   r'   s       €€€€€€€€€€€r   rd   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   r>   r   r,   r   r@   r   rL   rA   r   r*   r   rO   rP   rf   ÚsqueezeÚasarrayÚ
atleast_1dÚgradient_probarB   r$   rC   )r   r   r   r8   r4   r.   r5   rD   r&   r+   rE   rV   rG   rd   ra   rb   rc   r   r   r   rj   rF   r'   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   r(   r,   r0   r6   r?   rI   rL   ro   © r   r   r   r      s4  € € € € € ð7ð 7ðr+ð +ð +ðð ð ð ð8%"ð %"ð %"ðN2ð 2ð 2ð@/ð /ð /ð ØØØð4@ð 4@ð 4@ð 4@ðv ØØØðLð Lð Lð Lðf ØØØðGð Gð Gð Gð\ ØØØØØðI+ð I+ð I+ð I+ðX NOðWð Wð Wð Wð Wð Wr   r   )rs   Únumpyr   Úscipyr   Úutils.extmathr   r   rt   r   r   ú<module>rx      s}   ððð ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à (Ð (Ð (Ð (Ð (Ð (ðU
ð U
ð U
ð U
ð U
ñ U
ô U
ð U
ð U
ð U
r   