Penalised NB Newton solvers and batched grams (for package developers)
Source:R/nbSolver.R
nbNewtonSolver.RdLow-level building blocks of polishNB, exported so that a
downstream package (e.g. spiDE) can form the penalised covariance of a
polished fit from the SAME factorisation the polish used. The information is
crossprod(W, w * W) + diag(pen). absorb marks an indicator block whose
part of the information is block-diagonal and is eliminated by a Schur
complement: NULL (dense), a logical over W's columns (each
marked column its own 1x1 block), or an integer block id per column
(NA = dense).
Usage
nbNewtonSolver(W, pen, absorb = NULL)
nbNewtonSolverBatch(W, pen, absorb = NULL)
nbGramBatch(
W,
wt_block,
penalty_diag = NULL,
backend = "cpu",
cell.tile = NULL
)
nbAbsorbGramBatch(W, pen, absorb, wt_block, cell.tile = NULL, parts = FALSE)Arguments
- W
a cells x p design (base matrix, or torch tensor for the batch forms).
nbNewtonSolver()also takes annbBlockDesign(), whose groups' blocks it absorbs (withabsorb = NULL); its state then carriesS(the Schur complement on the columns ofX),B(every group'scrossprod(X_g, w_g * Z_g)side by side,p_x x G q),H(per group, aq x r_gmatrix whosetcrossprod(H)is a generalised inverse ofcrossprod(Z_g, w_g * Z_g) + diag(pen_g)) andrank(r_g). The batch forms take a dense design only.- pen
a length-p ridge penalty (for an
nbBlockDesign, also one value, or one per column of[X | Z]).- absorb
see Description.
- wt_block
a genes x cells weight matrix (one row per gene).
- penalty_diag
NULL, or a length-p ridge penalty added to the diagonal of every gene's gram.- backend
the resolved backend; unused on base R matrices, kept for symmetry with the other batched helpers.
- cell.tile
cells per accumulation tile, or
NULLfor all at once. A gram is a sum over cells, so every tiling gives the same result; a tile bounds thebatch x cells x pweighted design on a device.- parts
if
TRUE, return the pieces a Newton step's back-substitution needs (S,B,cvec,xi,zi) rather than the Schur complementsSalone.