riemtan
implements various Riemannian metrics for symmetric positive definite (SPD) matrices. It provides tools for computing logarithmic and exponential maps, vectorization operations, and statistical analyses on the manifold of SPD matrices.
The package implements five different metrics: - Affine Invariant Riemannian Metric (AIRM) - Log-Euclidean - Euclidean - Log-Cholesky - Bures-Wasserstein
You can install the released version of riemtan with:
# install.packages("devtools")
devtools::install_github("nicoesve/riemtan")
Here’s a basic example of computing the AIRM logarithm between two SPD matrices:
library(riemtan)
library(Matrix)
# Create two SPD matrices
sigma <- Matrix(c(2.0, 0.5, 0.5, 3.0), nrow = 2) |>
nearPD() |> _$mat |> pack()
lambda <- Matrix(c(1.5, 0.3, 0.3, 2.5), nrow = 2) |>
nearPD() |> _$mat |> pack()
# Compute AIRM logarithm
result <- airm_log(sigma, lambda)
For more complex analyses, use the CSample class:
# Create a sample of SPD matrices
sample <- CSample$new(
conns = list_of_matrices,
metric_obj = airm
)
# Compute Frechet mean
sample$compute_fmean()
# Get sample statistics
sample$variation
sample$sample_cov