% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tune_Lambda.R
\name{.fit_coefficients}
\alias{.fit_coefficients}
\title{Fit Coefficients During Penalty Tuning: blockfit_solve or get_B}
\usage{
.fit_coefficients(G_list, Lambda, L_partition_list, env, return_G_getB, ...)
}
\arguments{
\item{G_list}{List; eigendecomposition results from \code{compute_G_eigen},
containing \code{Ghalf} and \code{GhalfInv}.}

\item{Lambda}{Matrix; current combined penalty matrix.}

\item{L_partition_list}{List; partition-specific penalty matrices.}

\item{env}{List; tuning environment from \code{.build_tuning_env}.}

\item{return_G_getB}{Logical; whether to return G inside the fit. Set to
TRUE within \code{.compute_gcvu} and \code{.compute_gcvu_gradient} so
that \code{B_list$G_list} carries the (possibly GLM-iterated) G matrices
required for the subsequent \code{AGAmult_wrapper} and trace computations.}

\item{...}{Additional arguments forwarded to the fitting routine.}
}
\value{
List; output of \code{blockfit_solve} or \code{get_B}, containing
  at minimum \code{$B} (coefficient list) and \code{$G_list}.
}
\description{
Dispatches to \code{blockfit_solve} when the blockfit conditions are met
(i.e. \code{env$use_blockfit} is TRUE), otherwise calls \code{get_B}.
On \code{blockfit_solve} failure, falls back to \code{get_B} automatically.
}
\details{
The blockfit condition mirrors \code{lgspline.fit}:
\code{blockfit && length(flat_cols) > 0 && K > 0}, pre-computed in
\code{tune_Lambda} and stored in \code{env$use_blockfit}.

\code{return_G_getB} is set to TRUE by the callers so that
\code{B_list$G_list} contains the updated G matrices (after any GLM
weight iteration inside \code{get_B} or \code{blockfit_solve}).
These are needed immediately after this call for \code{AGAmult_wrapper},
\code{GXX}, and the trace computation.

When correlation structure inputs are supplied, this wrapper does not
introduce a separate tuning-specific notation or solver path. Instead, the
same correlated coefficient estimator used in the final model fit is called
here inside each tuning-objective evaluation. In particular, any
structured-correlation Woodbury factorization
\eqn{\mathbf{G}^{-1} =
\mathbf{G}_{\mathrm{on}}^{-1} + \mathbf{G}_{\mathrm{off}}^{-1}}
is handled inside \code{get_B} and documented in \code{lgspline-details}.
}
\keyword{internal}
