This class represents a sample of connectomes, with various properties and methods to handle their tangent and vectorized images.
connectomesConnectomes data
tangent_imagesTangent images data
vector_imagesVector images data
sample_sizeSample size
matrix_sizeMatrix size
mfd_dimManifold dimension
is_centeredCentering status
frechet_meanFrechet mean
riem_metricRiemannian Metric used
variationVariation of the sample
sample_covSample covariance
ref_pointReference point for tangent or vectorized images
distancesDistances to the Frechet mean
batch_sizeBatch size for compute_fmean
new()Initialize a CSample object
CSample$new(
conns = NULL,
tan_imgs = NULL,
vec_imgs = NULL,
centered = NULL,
ref_pt = NULL,
metric_obj,
batch_size = NULL,
backend = NULL
)connsA list of connectomes (default is NULL).
tan_imgsA list of tangent images (default is NULL).
vec_imgsA matrix whose rows are vectorized images (default is NULL).
centeredBoolean indicating whether tangent or vectorized images are centered (default is NULL).
ref_ptA connectome (default is identity)
metric_objObject of class rmetric representing the Riemannian metric used.
batch_sizeThe batch size for compute_fmean (default is 32).
backendA DataBackend object (ListBackend or ParquetBackend). If NULL and conns is provided, a ListBackend will be created automatically.
A new CSample object.
load_connectomes_batched()Load connectomes in parallel batches from ParquetBackend. This method is particularly useful for large Parquet-backed datasets where loading all matrices at once would be memory-prohibitive.
CSample$load_connectomes_batched(
indices = NULL,
batch_size = 50,
progress = FALSE
)indicesOptional vector of indices to load. If NULL (default), loads all matrices.
batch_sizeNumber of matrices to load per batch (default: 50). Larger batches use more memory but may be faster.
progressLogical indicating whether to show progress (default: FALSE).
This method only works when the CSample was initialized with a ParquetBackend. It loads matrices in parallel batches, clearing the cache between batches to manage memory usage. Sequential loading is used for ListBackend.
A list of dppMatrix objects.
\dontrun{
# Create CSample with ParquetBackend
backend <- create_parquet_backend("my_data")
sample <- CSample$new(backend = backend, metric_obj = airm)# Load first 100 matrices in batches of 20 conns <- sample$load_connectomes_batched(indices = 1:100, batch_size = 20) }
compute_tangents()This function computes the tangent images from the connectomes.
CSample$compute_tangents(ref_pt = default_ref_pt(private$p), progress = FALSE)ref_ptA reference point, which must be a dppMatrix object (default is default_ref_pt).
progressLogical indicating whether to show progress (default: FALSE).
Error if ref_pt is not a dppMatrix object or if conns is not specified.
None
compute_conns()This function computes the connectomes from the tangent images.
CSample$compute_conns(progress = FALSE)progressLogical indicating whether to show progress (default: FALSE).
Error if tangent images are not specified.
None
compute_vecs()This function computes the vectorized tangent images from the tangent images.
CSample$compute_vecs(progress = FALSE)progressLogical indicating whether to show progress (default: FALSE).
Error if tangent images are not specified.
None
compute_unvecs()This function computes the tangent images from the vector images.
CSample$compute_unvecs(progress = FALSE)progressLogical indicating whether to show progress (default: FALSE).
Error if vec_imgs is not specified.
None
compute_fmean()This function computes the Frechet mean of the sample.
CSample$compute_fmean(
tol = 0.001,
max_iter = 100,
lr = 0.2,
batch_size = NULL,
progress = FALSE
)tolTolerance for the convergence of the mean (default is 0.05).
max_iterMaximum number of iterations for the computation (default is 20).
lrLearning rate for the optimization algorithm (default is 0.2).
batch_sizeThe batch size (default is the instance's batch_size).
progressLogical indicating whether to show progress (default: FALSE).
None
change_ref_pt()This function changes the reference point for the tangent images.
CSample$change_ref_pt(new_ref_pt, progress = FALSE)new_ref_ptA new reference point, which must be a dppMatrix object.
progressLogical indicating whether to show progress (default: FALSE).
Error if tangent images have not been computed or if new_ref_pt is not a dppMatrix object.
None
center()Center the sample
CSample$center()This function centers the sample by computing the Frechet mean if it is not already computed, and then changing the reference point to the computed Frechet mean. Error if tangent images are not specified. Error if the sample is already centered.
None. This function is called for its side effects.
compute_variation()Compute Variation
CSample$compute_variation()This function computes the variation of the sample. It first checks if the vector images are null, and if so, it computes the vectors, computing first the tangent images if necessary. If the sample is not centered, it centers the sample and recomputes the vectors. Finally, it calculates the variation as the mean of the sum of squares of the vector images. Error if vec_imgs is not specified.
None. This function is called for its side effects.
compute_dists()Compute distances
CSample$compute_dists()This function computes the distances of the elements of the sample to the Frechet mean. It first checks if the vector images are null, and if so, it computes the vectors, computing first the tangent images if necessary. If the sample is not centered, it centers the sample and recomputes the vectors. Finally, it calculates the distances as the Euclidean norms of the vector images. Error if vec_imgs is not specified.
None. This function is called for its side effects.
compute_sample_cov()Compute Sample Covariance
CSample$compute_sample_cov()This function computes the sample covariance matrix for the vector images. It first checks if the vector images are null, and if so, it computes the vectors, computing first the tangent images if necessary.
None. This function is called for its side effects.
clone()The objects of this class are cloneable with this method.
CSample$clone(deep = FALSE)deepWhether to make a deep clone.
## ------------------------------------------------
## Method `CSample$load_connectomes_batched`
## ------------------------------------------------
if (FALSE) {
# Create CSample with ParquetBackend
backend <- create_parquet_backend("my_data")
sample <- CSample$new(backend = backend, metric_obj = airm)
# Load first 100 matrices in batches of 20
conns <- sample$load_connectomes_batched(indices = 1:100, batch_size = 20)
}
Run the code above in your browser using DataLab