| compute_frechet_mean | R Documentation |
This function computes the Frechet mean of a sample using an iterative algorithm with optional parallel processing.
compute_frechet_mean(
sample,
tol = 0.05,
max_iter = 20,
lr = 0.2,
batch_size = 32,
progress = FALSE
)
sample |
An object of class |
tol |
A numeric value specifying the tolerance for convergence. Default is 0.05. |
max_iter |
An integer specifying the maximum number of iterations. Default is 20. |
lr |
A numeric value specifying the learning rate. Default is 0.2. |
batch_size |
Integer. The number of samples to process in each batch during computation. Default is 32. |
progress |
Logical indicating whether to show progress during computation (default: FALSE). Requires progressr package. |
The function iteratively updates the reference point of the sample until the change in the reference point is less than the specified tolerance or the maximum number of iterations is reached. If the tangent images are not already computed, they will be computed before starting the iterations.
When parallel processing is enabled (via set_parallel_plan()), the relocate() function will use parallel
processing for relocating tangent images in each iteration, which can significantly speed up computation
for large samples.
The computed Frechet mean as a dppMatrix object.
if (requireNamespace("Matrix", quietly = TRUE)) {
library(Matrix)
# Load the AIRM metric object
data(airm)
# Create a CSample object with example data
conns <- list(
diag(2) |> Matrix::nearPD() |> _$mat |> Matrix::pack(),
diag(c(2, 3)) |> Matrix::nearPD() |> _$mat |> Matrix::pack()
)
sample <- CSample$new(conns = conns, metric_obj = airm)
# Compute the Frechet mean
compute_frechet_mean(sample, tol = 0.01, max_iter = 50, lr = 0.1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.