% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/blockfit_solve.R
\name{.bf_sqp_loop}
\alias{.bf_sqp_loop}
\title{Damped SQP Refinement on the Full (Optionally Whitened) System}
\usage{
.bf_sqp_loop(
  X_design,
  y_design,
  X_block_raw,
  beta_init,
  Lambda_block,
  qp_Amat_combined,
  qp_bvec_combined,
  qp_meq_combined,
  K,
  p_expansions,
  family,
  order_list,
  glm_weight_function,
  schur_correction_function,
  qp_score_function,
  need_dispersion_for_estimation,
  dispersion_function,
  observation_weights,
  iterate,
  tol,
  VhalfInv,
  VhalfInv_perm,
  is_gee,
  deviance_fun,
  X_partitions,
  y_partitions,
  verbose,
  ...
)
}
\arguments{
\item{X_design}{\eqn{N \times P} design matrix (whitened for GEE,
unwhitened otherwise).}

\item{y_design}{\eqn{N \times 1} response vector (whitened for
GEE, unwhitened otherwise).}

\item{X_block_raw}{Unwhitened block-diagonal design matrix (used
for computing the linear predictor on the original scale).
For the non-GEE path this equals \code{X_design}.}

\item{beta_init}{\eqn{P \times 1} initial coefficient vector.}

\item{Lambda_block}{\eqn{P \times P} block-diagonal penalty.}

\item{qp_Amat_combined}{Combined constraint matrix (equalities
then inequalities).}

\item{qp_bvec_combined}{Combined constraint RHS.}

\item{qp_meq_combined}{Number of leading equality constraints.}

\item{K, p_expansions}{Integers.}

\item{family}{GLM family object.}

\item{order_list}{Observation-index lists.}

\item{glm_weight_function, schur_correction_function, }{qp_score_function Functions.}

\item{need_dispersion_for_estimation}{Logical.}

\item{dispersion_function}{Function.}

\item{observation_weights}{List or vector of weights.}

\item{iterate}{Logical; if FALSE, takes at most two steps.}

\item{tol}{Convergence tolerance.}

\item{VhalfInv, VhalfInv_perm}{\eqn{\mathbf{V}^{-1/2}} matrices
(original and permuted ordering).  NULL for non-GEE path.}

\item{is_gee}{Logical; TRUE when called from the GEE refinement
path (affects deviance computation).}

\item{deviance_fun}{Function computing deviance; either
\code{.bf_deviance} or \code{.bf_gee_deviance}.}

\item{X_partitions}{List of per-partition design matrices
(unwhitened); needed for Schur correction in non-GEE path.}

\item{y_partitions}{List of per-partition response vectors
(unwhitened); needed for Schur correction in non-GEE path.}

\item{verbose}{Logical.}

\item{...}{Forwarded to weight, dispersion, and score functions.}
}
\value{
A named list with elements \code{beta_block} (final
  coefficient vector), \code{result} (per-partition coefficient
  list), \code{last_qp_sol} (last successful \code{solve.QP}
  output or NULL), \code{converged} (logical), and
  \code{final_deviance} (scalar).
}
\description{
Runs a damped sequential quadratic programming loop using
\code{quadprog::solve.QP} at each iteration, enforcing all
smoothness equalities, flat-equality constraints, and any
user-supplied inequality constraints.
}
\details{
This function serves two roles within \code{\link{blockfit_solve}}:
\enumerate{
  \item \strong{GEE Stage 2} (Case c): operates on the whitened
    system \eqn{\tilde{\mathbf{X}} = \mathbf{V}^{-1/2}
    \mathbf{X}_{\mathrm{block}}}, initialized from the damped Newton-Raphson
    backfitting warm start.
  \item \strong{Non-GEE SQP refinement}: operates on the
    unwhitened block-diagonal design, applying inequality
    constraints after backfitting convergence.
}
}
\keyword{internal}
