The QB decomposition uses the same set of orthonormal vectors to approximate
every column of A. These vectors form Q, and each column of
B gives the coordinates of an input column projected onto their
span. Their product gives the approximation
$$A \approx Q B, \qquad B = Q^{H} A.$$
The superscript \(H\) denotes the conjugate transpose, which is the ordinary
transpose for real input. Thus Q %*% B retains the part of each
column of A that lies in the column space of Q. This is an
orthogonal projection. The input is used without centering or scaling.
When rand = TRUE, random matrix products identify a candidate
subspace. The algorithm refines it with q power iterations and
intermediate orthogonalization before projecting the input. The basis width is
\(\ell = \min(k+p,m,n)\) for integer k
and p, with m rows and n columns in the input. The
oversampled columns are retained, so the result generally has k + p
basis vectors. A singular value decomposition (SVD) of the projected matrix
B can then identify its leading directions and truncate the
approximation further. The function rsvd follows this approach
and returns k singular triplets with its default vector counts.
Oversampling gives the sampled subspace additional directions, and power
iterations can improve how well it captures the input. Both can improve
approximation quality, especially when singular values decay slowly, at
the cost of more computation. The parameters remain fixed throughout the
calculation; there is no adaptive error tolerance or automatic rank
selection. The useful rank depends on how much information the application
needs to retain. Even a matrix with full algebraic rank may be well
represented in a much smaller subspace.
When rand = FALSE, the basis width is
\(\ell = \min(k,m,n)\). The result uses the first
\(\ell\) columns of qr.Q(qr(as.matrix(A))), with base R's
default QR conventions. For real input whose leading block is numerically
independent, only that block needs dense factorization. Complex input,
dependent leading columns and other cases use the full dense QR fallback.
This preserves base QR's ordering, including its pivoting behavior. The
resulting subspace follows that ordering and need not minimize the
rank-k approximation error.
For randomized decompositions, real-valued sparse Matrix inputs are
multiplied by thin dense factors without converting the entire input to a
dense matrix. Logical and pattern matrices are treated as zero/one data.
Complex input is supported for ordinary R matrices. Samples, orthonormal
bases and projected matrices are dense. The deterministic fallback can
convert the entire input to dense storage, which limits its usefulness
for large sparse matrices. It does not provide a general sparse QR
implementation. Constructing Q %*% B also forms a dense matrix.
Setting k = NULL uses the full available basis width and gives up the
storage advantage of a small basis. The function does not reduce that width
based on an estimated numerical rank.