bdpseudoinv: Compute Matrix Pseudoinverse (In-Memory)

View source: R/RcppExports.R

bdpseudoinvR Documentation

Compute Matrix Pseudoinverse (In-Memory)

Description

Computes the Moore-Penrose pseudoinverse of a matrix using SVD decomposition. This implementation handles both square and rectangular matrices, and provides numerically stable results even for singular or near-singular matrices.

Usage

bdpseudoinv(X, threads = NULL)

Arguments

X

Numeric matrix or vector to be pseudoinverted.

threads

Optional integer. Number of threads for parallel computation. If NULL, uses maximum available threads.

Details

The Moore-Penrose pseudoinverse (denoted A+) of a matrix A is computed using Singular Value Decomposition (SVD).

For a matrix A = USigmaV^T (where ^T denotes transpose), the pseudoinverse is computed as:

A^+ = V \Sigma^+ U^T

where Sigma+ is obtained by taking the reciprocal of non-zero singular values.

Value

The pseudoinverse matrix of X.

Mathematical Details

  • SVD decomposition: A = U \Sigma V^T

  • Pseudoinverse: A^+ = V \Sigma^+ U^T

  • \Sigma^+_{ii} = 1/\Sigma_{ii} if \Sigma_{ii} > \text{tolerance}

  • \Sigma^+_{ii} = 0 otherwise

Key features:

  • Robust computation:

    • Handles singular and near-singular matrices

    • Automatic threshold for small singular values

    • Numerically stable implementation

  • Implementation details:

    • Uses efficient SVD algorithms

    • Parallel processing support

    • Memory-efficient computation

    • Handles both dense and sparse inputs

The pseudoinverse satisfies the Moore-Penrose conditions:

  • AA^+A = A

  • A^+AA^+ = A^+

  • (AA^+)^* = AA^+

  • (A^+A)^* = A^+A

References

  • Golub, G. H., & Van Loan, C. F. (2013). Matrix Computations, 4th Edition. Johns Hopkins University Press.

  • Ben-Israel, A., & Greville, T. N. E. (2003). Generalized Inverses: Theory and Applications, 2nd Edition. Springer.

Examples


# Create a singular matrix
X <- matrix(c(1,2,3,2,4,6), 2, 3)  # rank-deficient matrix

# Compute pseudoinverse
X_pinv <- bdpseudoinv(X)

# Verify Moore-Penrose conditions
# 1. X %*% X_pinv %*% X = X
all.equal(X %*% X_pinv %*% X, X)

# 2. X_pinv %*% X %*% X_pinv = X_pinv
all.equal(X_pinv %*% X %*% X_pinv, X_pinv)


BigDataStatMeth documentation built on May 15, 2026, 1:07 a.m.