% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_B.R
\name{.qp_refine}
\alias{.qp_refine}
\title{Quadratic Programming Refinement for Inequality Constraints}
\usage{
.qp_refine(
  result,
  X,
  y,
  K,
  p_expansions,
  A,
  Lambda,
  Lambda_block,
  family,
  iterate,
  tol,
  qp_Amat,
  qp_bvec,
  qp_meq,
  qp_score_function,
  order_list,
  glm_weight_function,
  schur_correction_function,
  need_dispersion_for_estimation,
  dispersion_function,
  observation_weights,
  VhalfInv,
  ...
)
}
\arguments{
\item{result}{List of current coefficient column vectors by partition.}

\item{X}{List of partition-specific design matrices.}

\item{y}{List of response vectors by partition.}

\item{K}{Integer; number of interior knots.}

\item{p_expansions}{Integer; number of basis terms per partition.}

\item{A}{Equality constraint matrix \eqn{\mathbf{A}}.}

\item{Lambda}{Shared penalty matrix \eqn{\boldsymbol{\Lambda}}.}

\item{Lambda_block}{Full block-diagonal penalty matrix.}

\item{family}{GLM family object.}

\item{iterate}{Logical; if \code{TRUE}, iterate the SQP loop until
convergence rather than taking a single step.}

\item{tol}{Convergence tolerance.}

\item{qp_Amat}{Inequality constraint matrix \eqn{\mathbf{C}} for
\code{solve.QP}.}

\item{qp_bvec}{Inequality constraint vector \eqn{\mathbf{c}}.}

\item{qp_meq}{Number of equality constraints within \code{qp_Amat}.}

\item{qp_score_function}{Score function
\eqn{\nabla_{\boldsymbol{\beta}}\ell(\boldsymbol{\beta}^*)} for the
QP step.}

\item{order_list}{List of index vectors mapping partition rows to
original data ordering.}

\item{glm_weight_function}{Function computing GLM working weights.}

\item{schur_correction_function}{Function computing Schur corrections.}

\item{need_dispersion_for_estimation}{Logical.}

\item{dispersion_function}{Dispersion estimation function.}

\item{observation_weights}{List of observation weights by partition.}

\item{VhalfInv}{Inverse square root of the working correlation matrix in
the original observation ordering (or \code{NULL}); permuted internally
via \code{order_list}.}

\item{...}{Passed to weight, correction, dispersion, and score functions.}
}
\value{
A list with components:
\describe{
  \item{result}{List of refined coefficient column vectors by partition.}
  \item{qp_info}{List with QP solve metadata including Lagrangian
    multipliers and the active constraint matrix.}
}
}
\description{
After the Lagrangian projection handles smoothness equality constraints,
this function refines the estimate to satisfy additional inequality
constraints (monotonicity, derivative sign, range bounds, or user-supplied
constraints) via \code{quadprog::solve.QP}.
}
\details{
The subproblem at each iteration is a second-order Taylor approximation
of the penalized log-likelihood around the current iterate
\eqn{\boldsymbol{\beta}^*}. Collecting terms, this yields:
\deqn{\tilde{\boldsymbol{\beta}} = \arg\min_{\boldsymbol{\beta}}
  \left\{-\mathbf{d}^{\top}\boldsymbol{\beta} + \frac{1}{2}
  \boldsymbol{\beta}^{\top}\mathbf{G}^{-1}\boldsymbol{\beta}\right\}
  \quad \text{s.t.} \quad
  \mathbf{A}^{\top}\boldsymbol{\beta} = \mathbf{0}, \quad
  \mathbf{C}^{\top}\boldsymbol{\beta} \succeq \mathbf{c}}
where \eqn{\mathbf{d}} is the score adjusted by the current iterate
and \eqn{\mathbf{c}} is the constraint value vector. Step acceptance
uses damped updates with deviance monitoring; see Nocedal and Wright
(2006) for the general SQP framework.
}
\keyword{internal}
