Toeplitz | R Documentation |
The Toeplitz
class contains efficient methods for linear algebra with symmetric positive definite (i.e., variance) Toeplitz matrices.
is.Toeplitz(x) as.Toeplitz(x) ## S3 method for class 'Toeplitz' dim(x)
x |
An R object. |
An N x N
Toeplitz matrix Tz
is defined by its length-N
"autocorrelation" vector acf
, i.e., first row/column Tz
. Thus, for the function stats::toeplitz()
, we have Tz = toeplitz(acf)
.
It is assumed that acf
defines a valid (i.e., positive definite) variance matrix. The matrix multiplication methods still work when this is not the case but the other methods do not (return values typically contain NaN
s).
as.Toeplitz(x)
attempts to convert its argument to a Toeplitz
object by calling Toeplitz$new(acf = x)
. is.Toeplitz(x)
checks whether its argument is a Toeplitz
object.
new()
Class constructor.
Toeplitz$new(N, acf)
N
Size of Toeplitz matrix.
acf
Autocorrelation vector of length N
.
A Toeplitz
object.
print()
Print method.
Toeplitz$print()
size()
Get the size of the Toeplitz matrix.
Toeplitz$size()
Size of the Toeplitz matrix. ncol()
, nrow()
, and dim()
methods for Toeplitz
objects also work as expected.
set_acf()
Set the autocorrelation of the Toeplitz matrix.
Toeplitz$set_acf(acf)
acf
Autocorrelation vector of length N
.
get_acf()
Get the autocorrelation of the Toeplitz matrix.
Toeplitz$get_acf()
The autocorrelation vector of length N
.
has_acf()
Check whether the autocorrelation of the Toeplitz matrix has been set.
Toeplitz$has_acf()
Logical; TRUE
if Toeplitz$set_acf()
has been called.
prod()
Toeplitz matrix-matrix product.
Toeplitz$prod(x)
x
Vector or matrix with N
rows.
The matrix product Tz %*% x
. Tz %*% x
and x %*% Tz
also work as expected.
solve()
Solve a Toeplitz system of equations.
Toeplitz$solve(x, method = c("gschur", "pcg"), tol = 1e-10)
x
Optional vector or matrix with N
rows.
method
Solve method to use. Choices are: gschur
for a modified version of the Generalized Schur algorithm of Ammar & Gragg (1988), or pcg
for the preconditioned conjugate gradient method of Chen et al (2006). The former is faster and obtains the log-determinant as a direct biproduct. The latter is more numerically stable for long-memory autocorrelations.
tol
Tolerance level for the pcg
method.
The solution in z
to the system of equations Tz %*% z = x
. If x
is missing, returns the inverse of Tz
. solve(Tz, x)
and solve(Tz, x, method, tol)
also work as expected.
log_det()
Calculate the log-determinant of the Toeplitz matrix.
Toeplitz$log_det()
The log-determinant log(det(Tz))
. determinant(Tz)
also works as expected.
trace_grad()
Computes the trace-gradient with respect to Toeplitz matrices.
Toeplitz$trace_grad(acf2)
acf2
Length-N
autocorrelation vector of the second Toeplitz matrix. This matrix must be symmetric but not necessarily positive definite.
Computes the trace of
solve(Tz, toeplitz(acf2)).
This is used in the computation of the gradient of log(det(Tz(theta)))
with respect to theta
.
trace_hess()
Computes the trace-Hessian with respect to Toeplitz matrices.
Toeplitz$trace_hess(acf2, acf3)
acf2
Length-N
autocorrelation vector of the second Toeplitz matrix. This matrix must be symmetric but not necessarily positive definite.
acf3
Length-N
autocorrelation vector of the third Toeplitz matrix. This matrix must be symmetric but not necessarily positive definite.
Computes the trace of
solve(Tz, toeplitz(acf2)) %*% solve(Tz, toeplitz(acf3)).
This is used in the computation of the Hessian of log(det(Tz(theta)))
with respect to theta
.
clone()
The objects of this class are cloneable with this method.
Toeplitz$clone(deep = FALSE)
deep
Whether to make a deep clone.
# construct a Toeplitz matrix acf <- exp(-(1:5)) Tz <- Toeplitz$new(acf = acf) # alternatively, can allocate space first Tz <- Toeplitz$new(N = length(acf)) Tz$set_acf(acf = acf) # basic methods Tz$get_acf() # extract the acf dim(Tz) # == c(nrow(Tz), ncol(Tz)) Tz # print method # linear algebra methods X <- matrix(rnorm(10), 5, 2) Tz %*% X t(X) %*% Tz solve(Tz, X) determinant(Tz) # log-determinant
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.