Debido a que esta es una matriz de covarianza, e=h, f=l, g=m, y A,B,C,D son todas positivas. El cambio de notación para manejar una generalización de este problema, considere la matriz simétrica
A=(σ2100⋯x1σ1σn0σ220⋯x2σ2σn00σ23⋯x3σ3σn⋮⋮⋮⋱⋮x1σ1σnx2σ2σnx3σ3σn⋯σ2n).
By comparing this to the question it is apparent that n=4, σ1=√A, σ2=√B, σ3=√C, σ4=σn=√D, and x1=e/(σ1σn) etc. There are n−1 such xi.
It is evident that
A=UXU
where U is the diagonal matrix with entries (σ1,σ2,…,σn) and (therefore)
X=(100⋯x1010⋯x2001⋯x3⋮⋮⋮⋱⋮x1x2x3⋯1).
It is straightforward to demonstrate (inductively) that X is invertible if and only if x21+x22+⋯+x2n−1≠1. In this case set
Δ=det
and observe (using, for instance, the block-matrix formulae in Glen_b's answer) that
\mathbb{X}^{-1} = \frac{1}{\Delta}\pmatrix{
\Delta + x_1^2 & x_1, x_2 & x_1 x_3 & \cdots & -x_1 \\
x_1, x_2 & \Delta + x_2^2 & x_2 x_3 & \cdots & -x_2 \\
x_3 x_1 & x_3 x_2 & \Delta + x_3^2 & \cdots & -x_3 \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
-x_1 & -x_2 & -x_3 & \cdots & 1}.
The computation of \mathbb{U}^{-1} is simple--invert each of its diagonal entries--and the subsequent construction of
\mathbb{A}^{-1} = \mathbb{U}^{-1} \mathbb{X}^{-1} \mathbb{U}^{-1}
is equally easy.
To illustrate this algorithm, here is an R
implementation. It creates a random symmetric matrix with positive diagonal entries and arbitrary values in the last row and column, inverts it with the algorithm, multiplies that by the original, and compares the result to the identity matrix. The arguments to the inversion function are the vector of n diagonal elements a
and the vector of n-1 elements in the bottom row of \mathbb{X}. Thus \mathbb{X} nunca realmente se necesita para ser construido.
El tiempo es un poco más lento que usar el sparseMatrix
de la clase en la Matrix
paquete, porque sólo los nativos R
operaciones (por ejemplo, outer
y t
) son empleados y estos no están optimizados para la velocidad. Debido a la inversa de la matriz resultante es nada pero dispersas, parece ser que no hay inherente ventaja del uso de la matriz dispersa cálculos.
invert <- function(a, y) {
n <- length(a) # The diagonal elements
sigma <- sqrt(a)
x <- (y / (sigma[-n] * sigma[n]))
Delta <- 1 - sum(x*x)
X.inv <- outer(c(x, -1), c(x, -1)) + diag(c(rep(Delta, n-1), 0))
X.inv <- t(t(X.inv) / sigma) / sigma
return (X.inv / Delta)
}
#
# Create a matrix.
#
n <- 4000
a <- rexp(n)
y <- rnorm(n-1)
X <- diag(a)
n <- length(a)
X[-n, n] <- X[n, -n] <- y
#
# Invert it with the algorithm.
#
system.time(X.inv <- invert(a, y))
#
# Check that it is the inverse.
#
if (n <= 1000) {
One <- zapsmall(X %*% X.inv)
if(!all.equal(One, diag(rep(1,n))))
warning("Not an inverse!") else
message("Inverse is correct.")
}
El uso de la dispersa-matriz de problemas, acceso a la solve
función en el Matrix
biblioteca. Aquí es una ilustración que sigue el código anterior.
library(Matrix)
i <- c(1:n, 1:(n-1), rep(n, n-1))
j <- c(1:n, rep(n, n-1), 1:(n-1))
X.0 <- sparseMatrix(i, j, x=c(a, y, y))
system.time(X.0.inv <- solve(X.0))