View source: R/gen-namespace.R
torch_cholesky | R Documentation |
Cholesky
torch_cholesky(self, upper = FALSE)
self |
(Tensor) the input tensor |
upper |
(bool, optional) flag that indicates whether to return a
upper or lower triangular matrix. Default: |
Computes the Cholesky decomposition of a symmetric positive-definite
matrix A
or for batches of symmetric positive-definite matrices.
If upper
is TRUE
, the returned matrix U
is upper-triangular, and
the decomposition has the form:
A = U^TU
If upper
is FALSE
, the returned matrix L
is lower-triangular, and
the decomposition has the form:
A = LL^T
If upper
is TRUE
, and A
is a batch of symmetric positive-definite
matrices, then the returned tensor will be composed of upper-triangular Cholesky factors
of each of the individual matrices. Similarly, when upper
is FALSE
, the returned
tensor will be composed of lower-triangular Cholesky factors of each of the individual
matrices.
if (torch_is_installed()) {
a = torch_randn(c(3, 3))
a = torch_mm(a, a$t()) # make symmetric positive-definite
l = torch_cholesky(a)
a
l
torch_mm(l, l$t())
a = torch_randn(c(3, 2, 2))
## Not run:
a = torch_matmul(a, a$transpose(-1, -2)) + 1e-03 # make symmetric positive-definite
l = torch_cholesky(a)
z = torch_matmul(l, l$transpose(-1, -2))
torch_max(torch_abs(z - a)) # Max non-zero
## End(Not run)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.