WoodburyMatrix {WoodburyMatrix}R Documentation

Create a Woodbury matrix identity matrix

Description

Creates an implicitly defined matrix representing the equation

A1+UB1V,A^{-1} + U B^{-1} V,

where A,U,BA, U, B and VV are n x n, n x p, p x p and p x n matrices, respectively. A symmetric special case is also possible with

A1+XB1X,A^{-1} + X B^{-1} X',

where XX is n x p and AA and BB are additionally symmetric. The available methods are described in WoodburyMatrix-class and in solve. Multiple B / U / V / X matrices are also supported; see below

Usage

WoodburyMatrix(A, B, U, V, X, O, symmetric)

Arguments

A

Matrix AA in the definition above.

B

Matrix BB in the definition above, or list of matrices.

U

Matrix UU in the definition above, or list of matrices. Defaults to a diagonal matrix/matrices.

V

Matrix VV in the definition above, or list of matrices. Defaults to a diagonal matrix/matrices.

X

Matrix XX in the definition above, or list of matrices. Defaults to a diagonal matrix/matrices.

O

Optional, precomputed value of OO, as defined above. THIS IS NOT CHECKED FOR CORRECTNESS, and this argument is only provided for advanced users who have precomputed the matrix for other purposes.

symmetric

Logical value, whether to create a symmetric or general matrix. See Details section for more information.

Details

The benefit of using an implicit representation is that the inverse of this matrix can be efficiently calculated via

AAUO1VAA - A U O^{-1} V A

where O=B+VAUO = B + VAU, and its determinant by

det(O)det(A)1det(B)1.det(O) det(A)^{-1} det(B)^{-1}.

These relationships are often called the Woodbury matrix identity and the matrix determinant lemma, respectively. If AA and BB are sparse or otherwise easy to deal with, and/or when p<np < n, manipulating the matrices via these relationships rather than forming WW directly can have huge advantageous because it avoids having to create the (typically dense) matrix

A1+UB1VA^{-1} + U B^{-1} V

directly.

Value

A GWoodburyMatrix object for a non-symmetric matrix, SWoodburyMatrix for a symmetric matrix.

Symmetric form

Where applicable, it's worth using the symmetric form of the matrix. This takes advantage of the symmetry where possible to speed up operations, takes less memory, and sometimes has numerical benefits. This function will create the symmetric form in the following circumstances:

Multiple B matrices

A more general form allows for multiple B matrices:

A1+i=1nUiBi1Vi,A^{-1} + \sum_{i = 1}^n U_i B_i^{-1} V_i,

and analogously for the symmetric form. You can use this form by providing a list of matrices as the B (or U, V or X) arguments. Internally, this is implemented by converting to the standard form by letting B = bdiag(...the B matrices...), U = cbind(..the U matrices...), and so on.

The B, U, V and X values are recycled to the length of the longest list, so you can, for instance, provide multiple B matrices but only one U matrix (and vice-versa).

References

More information on the underlying linear algebra can be found in Harville, D. A. (1997) <doi:10.1007/b98818>.

See Also

WoodburyMatrix, solve, instantiate

Examples

library(Matrix)
# Example solving a linear system with general matrices
A <- Diagonal(100)
B <- rsparsematrix(100, 100, 0.5)
W <- WoodburyMatrix(A, B)
str(solve(W, rnorm(100)))

# Calculating the determinant of a symmetric system
A <- Diagonal(100)
B <- rsparsematrix(100, 100, 0.5, symmetric = TRUE)
W <- WoodburyMatrix(A, B, symmetric = TRUE)
print(determinant(W))

# Having a lower rank B matrix and an X matrix
A <- Diagonal(100)
B <- rsparsematrix(10, 10, 1, symmetric = TRUE)
X <- rsparsematrix(100, 10, 1)
W <- WoodburyMatrix(A, B, X = X)
str(solve(W, rnorm(100)))

# Multiple B matrices
A <- Diagonal(100)
B1 <- rsparsematrix(100, 100, 1, symmetric = TRUE)
B2 <- rsparsematrix(100, 100, 1, symmetric = TRUE)
W <- WoodburyMatrix(A, B = list(B1, B2))
str(solve(W, rnorm(100)))

[Package WoodburyMatrix version 0.0.3 Index]