Computes the Cholesky decomposition of a symmetric positive-definite matrix stored in an HDF5 file. The Cholesky decomposition factors a matrix A into the product A = LL’ where L is a lower triangular matrix.
Character string. Path to the HDF5 file containing the input matrix.
group
Character string. Path to the group containing the input dataset.
dataset
Character string. Name of the input dataset to decompose.
outdataset
Character string. Name for the output dataset.
outgroup
Character string. Optional output group path. If not provided, results are stored in the input group.
fullMatrix
Logical. If TRUE, stores the complete matrix. If FALSE (default), stores only the lower triangular part to save space.
overwrite
Logical. If TRUE, allows overwriting existing results.
threads
Integer. Number of threads for parallel computation.
elementsBlock
Integer. Maximum number of elements to process in each block (default = 100,000). For matrices larger than 5000x5000, automatically adjusted to number of rows or columns * 2.
4 Value
A list containing the location of the Cholesky decomposition result:
fn: Character string. Path to the HDF5 file containing the result
ds: Character string. Full dataset path to the Cholesky decomposition result within the HDF5 file
5 Details
The Cholesky decomposition is a specialized factorization for symmetric positive-definite matrices that provides several advantages: - More efficient than LU decomposition for symmetric positive-definite matrices - Numerically stable - Useful for solving linear systems and computing matrix inverses - Important in statistical computing (e.g., for sampling from multivariate normal distributions)
This implementation features: - Block-based computation for large matrices - Optional storage formats (full or triangular) - Parallel processing support - Memory-efficient block algorithm
Mathematical Details: For a symmetric positive-definite matrix A, the decomposition A = LL’ has the following properties: - L is lower triangular - L has positive diagonal elements - L is unique
The elements of L are computed using:
6 Examples
Code
library(rhdf5)# Create a symmetric positive-definite matrixset.seed(1234)X <-matrix(rnorm(100), 10, 10)A <-crossprod(X) # A = X'X is symmetric positive-definite# Save to HDF5h5createFile("matrix.h5")h5write(A, "matrix.h5", "data/matrix")# Compute Cholesky decompositionbdCholesky_hdf5("matrix.h5", "data", "matrix",outdataset ="chol",outgroup ="decompositions",fullMatrix =FALSE)# Verify the decompositionL <-h5read("matrix.h5", "decompositions/chol")max(abs(A - L %*%t(L))) # Should be very small
---title: "bdCholesky_hdf5"subtitle: "bdCholesky_hdf5"---<span class="category-badge hdf5_algebra">HDF5_ALGEBRA</span>## DescriptionComputes the Cholesky decomposition of a symmetric positive-definite matrix storedin an HDF5 file. The Cholesky decomposition factors a matrix A into the productA = LL' where L is a lower triangular matrix.## Usage```rbdCholesky_hdf5(filename, group, dataset, outdataset, outgroup =NULL, fullMatrix =NULL, overwrite =NULL, threads =NULL, elementsBlock =1000000L)```## Arguments::: {.param-table}| Parameter | Description ||-----------|-------------||`filename`| Character string. Path to the HDF5 file containing the input matrix. ||`group`| Character string. Path to the group containing the input dataset. ||`dataset`| Character string. Name of the input dataset to decompose. ||`outdataset`| Character string. Name for the output dataset. ||`outgroup`| Character string. Optional output group path. If not provided, results are stored in the input group. ||`fullMatrix`| Logical. If TRUE, stores the complete matrix. If FALSE (default), stores only the lower triangular part to save space. ||`overwrite`| Logical. If TRUE, allows overwriting existing results. ||`threads`| Integer. Number of threads for parallel computation. ||`elementsBlock`| Integer. Maximum number of elements to process in each block (default = 100,000). For matrices larger than 5000x5000, automatically adjusted to number of rows or columns * 2. |:::## Value::: {.return-value}A list containing the location of the Cholesky decomposition result:- **`fn`**: Character string. Path to the HDF5 file containing the result- **`ds`**: Character string. Full dataset path to the Cholesky decomposition result within the HDF5 file\describe{ \item{L}{The lower triangular Cholesky factor}}:::## DetailsThe Cholesky decomposition is a specialized factorization for symmetric positive-definite matrices that provides several advantages:- More efficient than LU decomposition for symmetric positive-definite matrices- Numerically stable- Useful for solving linear systems and computing matrix inverses- Important in statistical computing (e.g., for sampling from multivariate normal distributions)This implementation features:- Block-based computation for large matrices- Optional storage formats (full or triangular)- Parallel processing support- Memory-efficient block algorithmMathematical Details:For a symmetric positive-definite matrix A, the decomposition A = LL' has the following properties:- L is lower triangular- L has positive diagonal elements- L is uniqueThe elements of L are computed using:\deqn{l_{ii} = \sqrt{a_{ii} - \sum_{k=1}^{i-1} l_{ik}^2}}\deqn{l_{ji} = \frac{1}{l_{ii}}(a_{ji} - \sum_{k=1}^{i-1} l_{ik}l_{jk})}## Examples```{r}#| eval: false#| code-fold: showlibrary(rhdf5)# Create a symmetric positive-definite matrixset.seed(1234)X <-matrix(rnorm(100), 10, 10)A <-crossprod(X) # A = X'X is symmetric positive-definite# Save to HDF5h5createFile("matrix.h5")h5write(A, "matrix.h5", "data/matrix")# Compute Cholesky decompositionbdCholesky_hdf5("matrix.h5", "data", "matrix",outdataset ="chol",outgroup ="decompositions",fullMatrix =FALSE)# Verify the decompositionL <-h5read("matrix.h5", "decompositions/chol")max(abs(A - L %*%t(L))) # Should be very small```## See Also::: {.see-also}- [bdInvCholesky_hdf5](bdInvCholesky_hdf5.html) for computing inverse using Cholesky decomposition- [bdSolve_hdf5](bdSolve_hdf5.html) for solving linear systems:::