| Title: | Latent Space Representations of fMRI Data |
|---|---|
| Description: | Provides S4 classes and methods for representing neuroimaging data in latent spaces. The LatentNeuroVec class offers a memory-efficient representation using matrix factorization (basis x loadings plus a per-voxel offset), enabling compact storage and efficient computation for PCA, temporal bases, graph and wavelet dictionaries, Slepian bases, HRBF atoms, and related fMRI decompositions. Integrates with the neuroim2 package for standard neuroimaging data structures. |
| Authors: | Bradley Buchsbaum [aut, cre] (ORCID: <https://orcid.org/0000-0002-1108-4866>) |
| Maintainer: | Bradley Buchsbaum <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-06-03 18:29:38 UTC |
| Source: | https://github.com/bbuchsbaum/fmrilatent |
Extract elements from a LatentNeuroVec. Use [[ to extract a single
volume as a SparseNeuroVol, or [ for 4D subsetting.
## S4 method for signature 'LatentNeuroVec,numeric' x[[i]] ## S4 method for signature 'LatentNeuroVec,numeric,numeric,ANY' x[i, j, k, l, ..., drop = TRUE] ## S4 method for signature 'LatentNeuroVec,matrix,missing,ANY' x[i, j, k, l, ..., drop = TRUE] ## S4 method for signature 'LatentNeuroVec,ANY,ANY,ANY' x[i, j, k, l, ..., drop = TRUE]## S4 method for signature 'LatentNeuroVec,numeric' x[[i]] ## S4 method for signature 'LatentNeuroVec,numeric,numeric,ANY' x[i, j, k, l, ..., drop = TRUE] ## S4 method for signature 'LatentNeuroVec,matrix,missing,ANY' x[i, j, k, l, ..., drop = TRUE] ## S4 method for signature 'LatentNeuroVec,ANY,ANY,ANY' x[i, j, k, l, ..., drop = TRUE]
x |
A |
i |
Numeric index for first dimension (x-axis) or volume index for |
j |
Numeric index for second dimension (y-axis). |
k |
Numeric index for third dimension (z-axis). |
l |
Numeric index for fourth dimension (time). |
... |
Additional arguments (unused). |
drop |
Logical, whether to drop dimensions (default TRUE). |
For [[: A SparseNeuroVol-class containing the computed volume.
For [: An array of extracted values.
mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) # Extract volumes vol1 <- lvec[[1]] vol_mid <- lvec[[2]] vol_last <- lvec[[dim(lvec)[4]]]mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) # Extract volumes vol1 <- lvec[[1]] vol_mid <- lvec[[2]] vol_last <- lvec[[dim(lvec)[4]]]
Describe the transform from raw to analysis coordinates
analysis_transform(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' analysis_transform(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' analysis_transform(x, ...) ## S4 method for signature 'ImplicitLatent' analysis_transform(x, ...) ## S4 method for signature 'LatentNeuroVec' analysis_transform(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' analysis_transform(x, ...)analysis_transform(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' analysis_transform(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' analysis_transform(x, ...) ## S4 method for signature 'ImplicitLatent' analysis_transform(x, ...) ## S4 method for signature 'LatentNeuroVec' analysis_transform(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' analysis_transform(x, ...)
x |
A latent object. |
... |
Additional arguments passed to methods. |
Transform descriptor or NULL. Downstream model-fitting code
should ordinarily consume coef_time(x, "analysis") rather than
reasoning about raw coordinates directly.
This helper lets the standalone BOLDZip-SR codec consume matrix-like shared basis assets without registering BOLDZip as an 'encode()' family. Matrix and template inputs are used as the detail basis by default and are orthonormalized because BOLDZip projection currently uses the transpose as the analysis operator.
as_boldzip_spatial_basis(x, ...)as_boldzip_spatial_basis(x, ...)
x |
A 'BoldZipSRSpatialBasis', matrix-like object, shared reference, or template object supporting [template_loadings()]. |
... |
Additional arguments reserved for methods. The default method accepts 'label', 'role', and 'orthonormalize'. |
A 'BoldZipSRSpatialBasis' object.
Bridges the neuroim2::ClusteredNeuroVol parcellation representation
to fmrilatent's ClusterReduction class, preserving label metadata.
as_cluster_reduction(cvol)as_cluster_reduction(cvol)
cvol |
A |
A ClusterReduction object with label metadata in info.
Convert to HaarLatent class
as_haar_latent(obj)as_haar_latent(obj)
obj |
Object to convert |
Object with HaarLatent class added
Attach HRBF metadata to an existing LatentNeuroVec
as_hrbf_latent(lvec, params, centres = NULL, sigmas = NULL)as_hrbf_latent(lvec, params, centres = NULL, sigmas = NULL)
lvec |
A LatentNeuroVec object |
params |
HRBF parameters list |
centres |
Optional matrix of HRBF centres |
sigmas |
Optional vector of HRBF sigmas |
The LatentNeuroVec with HRBF metadata attached
Coerce an object to an ImplicitLatent decoder
as_implicit_latent(x, ...)as_implicit_latent(x, ...)
x |
Object to coerce. |
... |
Additional arguments passed to methods. |
An object of class 'ImplicitLatent'.
Coerce a BOLDZip-SR payload to an ImplicitLatent
## S3 method for class 'BoldZipSR' as_implicit_latent(x, mask = NULL, domain = NULL, support = NULL, ...)## S3 method for class 'BoldZipSR' as_implicit_latent(x, mask = NULL, domain = NULL, support = NULL, ...)
x |
A 'BoldZipSR' object. |
mask |
Optional logical 3D array or 'LogicalNeuroVol' for volumetric wrapping. |
domain |
Optional decoded output domain. |
support |
Optional decoded support. Defaults to row indices. |
... |
Additional arguments ignored. |
An 'ImplicitLatent' whose decoder returns matrices as 'time x voxels', matching the rest of the implicit latent API.
Normalizes an incoming object to the canonical
portable_linear_map representation used internally by
encode_operator(), decoder(), and related
routines. Matrices and Matrix::Matrix objects are wrapped with
closure-based forward/adjoint_apply callbacks; list inputs
are validated and re-normalized with top-level source_support /
target_support preferred over provenance$* fallbacks.
as_portable_linear_map( x, source_domain_id = "", target_domain_id = "", source_support = NULL, target_support = NULL, provenance = list(), context = "portable linear map" )as_portable_linear_map( x, source_domain_id = "", target_domain_id = "", source_support = NULL, target_support = NULL, provenance = list(), context = "portable linear map" )
x |
An input operator. Either a base |
source_domain_id, target_domain_id
|
Optional character tags applied
only when |
source_support, target_support
|
Optional support descriptors applied
only when |
provenance |
Optional provenance list applied only when |
context |
Optional label used in error messages. |
A list in the canonical portable-linear-map form.
portable_linear_map,
validate_portable_linear_map.
m <- matrix(1:6, nrow = 2) op <- as_portable_linear_map(m, target_domain_id = "native") op$forward(c(1, 1, 1))m <- matrix(1:6, nrow = 2) op <- as_portable_linear_map(m, target_domain_id = "native") op$forward(c(1, 1, 1))
Reconstruct LatentNeuroVec as a 4D array
## S4 method for signature 'LatentNeuroVec' as.array(x, ...)## S4 method for signature 'LatentNeuroVec' as.array(x, ...)
x |
A |
... |
Ignored. |
A 4D numeric array with dimensions (x, y, z, time).
Reconstruct an ImplicitLatent as an array
## S3 method for class 'ImplicitLatent' as.array(x, time_idx = NULL, roi_mask = NULL, ...)## S3 method for class 'ImplicitLatent' as.array(x, time_idx = NULL, roi_mask = NULL, ...)
x |
An |
time_idx |
Optional integer time indices to keep. |
roi_mask |
Optional logical ROI mask; voxels outside the ROI are zero. |
... |
Additional arguments passed to the decoder. |
A numeric array with dimensions c(x, y, z, time).
Reconstruct LatentNeuroVec as a matrix (time x voxels)
## S4 method for signature 'LatentNeuroSurfaceVector' as.matrix(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' as.matrix(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' as.matrix(x, ...) ## S4 method for signature 'LatentNeuroVec' as.matrix(x, ...)## S4 method for signature 'LatentNeuroSurfaceVector' as.matrix(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' as.matrix(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' as.matrix(x, ...) ## S4 method for signature 'LatentNeuroVec' as.matrix(x, ...)
x |
A |
... |
Ignored. |
A numeric matrix with rows = time points, columns = mask voxels.
Coerce group-plus-delta loadings to a dense matrix
## S3 method for class 'GroupDeltaLoadings' as.matrix(x, ...)## S3 method for class 'GroupDeltaLoadings' as.matrix(x, ...)
x |
A 'GroupDeltaLoadings' object. |
... |
Ignored. |
Dense matrix of materialized loadings.
Convert HaarLatent to matrix
## S3 method for class 'HaarLatent' as.matrix(x, ...)## S3 method for class 'HaarLatent' as.matrix(x, ...)
x |
HaarLatent object |
... |
Additional arguments (unused) |
Matrix of reconstructed values
Reconstruct an ImplicitLatent as a matrix
## S3 method for class 'ImplicitLatent' as.matrix(x, time_idx = NULL, roi_mask = NULL, ...)## S3 method for class 'ImplicitLatent' as.matrix(x, time_idx = NULL, roi_mask = NULL, ...)
x |
An |
time_idx |
Optional integer time indices to keep. |
roi_mask |
Optional logical ROI mask for spatial subsetting. |
... |
Additional arguments passed to the decoder. |
A numeric matrix with rows = time and columns = voxels within the requested mask support.
Build an AWPT basis template
awpt_basis_template( parcellation, basis_spec = basis_awpt_wavelet(), loadings = NULL, anatomical_operator = NULL, conductance = NULL, coefficient_roughness = NULL, center = FALSE, ridge = 1e-08, label = "awpt_wavelet", ... )awpt_basis_template( parcellation, basis_spec = basis_awpt_wavelet(), loadings = NULL, anatomical_operator = NULL, conductance = NULL, coefficient_roughness = NULL, center = FALSE, ridge = 1e-08, label = "awpt_wavelet", ... )
parcellation |
A |
basis_spec |
An AWPT basis specification created by |
loadings |
Optional explicit template loadings matrix. When supplied,
fmrilatent skips wave-packet lifting and uses these loadings directly as
the decoder basis |
anatomical_operator |
Optional field-space roughness operator on the
template domain. When supplied, the coefficient roughness is computed as
|
conductance |
Optional symmetric field-space conductance matrix. When
supplied, fmrilatent builds the corresponding graph Laplacian and then
forms |
coefficient_roughness |
Optional coefficient-space roughness matrix.
This bypasses field-space construction and is stored directly as |
center |
Logical; if |
ridge |
Small positive ridge added to the Gram diagonal if needed. |
label |
Optional label stored in metadata. |
... |
Additional arguments passed to the underlying lift path. |
An AWPTBasisTemplate.
Average subject conductance matrices on a shared template graph
awpt_mean_conductance( conductances, method = c("log_euclidean", "arithmetic"), shrinkage = 0, enforce_psd = TRUE, tol = 1e-08 )awpt_mean_conductance( conductances, method = c("log_euclidean", "arithmetic"), shrinkage = 0, enforce_psd = TRUE, tol = 1e-08 )
conductances |
List of symmetric conductance matrices on the same template graph. |
method |
Averaging rule. |
shrinkage |
Optional shrinkage toward the isotropic identity. |
enforce_psd |
Logical; if |
tol |
Numerical tolerance for SPD operations. |
A symmetric averaged conductance matrix.
Build an AWPT field operator from a conductance matrix
awpt_operator_from_conductance( conductance, normalize = c("none", "sym", "rw"), tol = 1e-08 )awpt_operator_from_conductance( conductance, normalize = c("none", "sym", "rw"), tol = 1e-08 )
conductance |
Symmetric conductance matrix on the template graph. |
normalize |
Laplacian normalization convention. |
tol |
Numerical tolerance. |
A field-space roughness operator.
Build an AWPT field operator from subject conductance summaries
awpt_operator_from_subject_conductances( conductances, mean_method = c("log_euclidean", "arithmetic"), normalize = c("none", "sym", "rw"), shrinkage = 0, enforce_psd = TRUE, tol = 1e-08 )awpt_operator_from_subject_conductances( conductances, mean_method = c("log_euclidean", "arithmetic"), normalize = c("none", "sym", "rw"), shrinkage = 0, enforce_psd = TRUE, tol = 1e-08 )
conductances |
List of subject conductance matrices on a shared template graph. |
mean_method |
Averaging rule for the conductance mean. |
normalize |
Laplacian normalization convention. |
shrinkage |
Optional shrinkage toward an isotropic baseline before Laplacian construction. |
enforce_psd |
Logical; if |
tol |
Numerical tolerance. |
A list with conductance_mean and operator.
Build a surface AWPT basis template
awpt_surface_basis_template( geometry, basis_spec = basis_awpt_wavelet(), support = NULL, loadings = NULL, centers = NULL, anatomical_operator = NULL, conductance = NULL, coefficient_roughness = NULL, measure = NULL, center = FALSE, ridge = 1e-08, label = "surface_awpt_wavelet" )awpt_surface_basis_template( geometry, basis_spec = basis_awpt_wavelet(), support = NULL, loadings = NULL, centers = NULL, anatomical_operator = NULL, conductance = NULL, coefficient_roughness = NULL, measure = NULL, center = FALSE, ridge = 1e-08, label = "surface_awpt_wavelet" )
geometry |
A |
basis_spec |
An AWPT basis specification created by |
support |
Surface support as vertex indices or a logical vector over all vertices. |
loadings |
Optional explicit surface decoder loadings. |
centers |
Optional support-local center indices used for automatic wave-packet construction. |
anatomical_operator |
Optional field-space roughness operator on the supported surface domain. |
conductance |
Optional conductance matrix on the supported surface graph. |
coefficient_roughness |
Optional coefficient-space roughness matrix. |
measure |
Optional support-aligned weighting or mass information. |
center |
Logical; if |
ridge |
Small positive ridge added to the Gram diagonal if needed. |
label |
Optional label stored in metadata. |
A SurfaceAWPTBasisTemplate.
Extract the basis matrix from a latent space representation. For
LatentNeuroVec objects, this returns the temporal basis matrix
with dimensions (nTime x k) where k is the number of components.
basis(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' basis(x) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' basis(x) ## S4 method for signature 'BlockLatentNeuroVector' basis(x) ## S4 method for signature 'LatentNeuroVec' basis(x)basis(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' basis(x) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' basis(x) ## S4 method for signature 'BlockLatentNeuroVector' basis(x) ## S4 method for signature 'LatentNeuroVec' basis(x)
x |
An object containing a basis matrix (e.g., |
... |
Additional arguments (currently unused) |
The basis matrix (typically time x components)
mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) b_matrix <- basis(lvec) dim(b_matrix)mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) b_matrix <- basis(lvec) dim(b_matrix)
Extract the basis asset behind a latent object
basis_asset(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' basis_asset(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' basis_asset(x, ...) ## S4 method for signature 'ImplicitLatent' basis_asset(x, ...) ## S4 method for signature 'LatentNeuroVec' basis_asset(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' basis_asset(x, ...)basis_asset(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' basis_asset(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' basis_asset(x, ...) ## S4 method for signature 'ImplicitLatent' basis_asset(x, ...) ## S4 method for signature 'LatentNeuroVec' basis_asset(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' basis_asset(x, ...)
x |
A latent object. |
... |
Additional arguments passed to methods. |
Basis asset object or NULL.
AWPT wave-packet basis specification
basis_awpt_wavelet( scales = c(1, 2, 4, 8), order = 30L, threshold = 1e-06, k_neighbors = 6L, penalty_rule = c("inverse_scale", "inverse_scale_sq", "scale", "none", "custom"), custom_weights = NULL )basis_awpt_wavelet( scales = c(1, 2, 4, 8), order = 30L, threshold = 1e-06, k_neighbors = 6L, penalty_rule = c("inverse_scale", "inverse_scale_sq", "scale", "none", "custom"), custom_weights = NULL )
scales |
Numeric vector of anatomical wave-packet scales. |
order |
Polynomial approximation order for the underlying heat-wavelet construction. |
threshold |
Threshold for small coefficients. |
k_neighbors |
Graph neighborhood parameter. |
penalty_rule |
Rule used to convert scales into roughness weights. |
custom_weights |
Optional explicit weights matching |
A spec_awpt_wavelet object.
Extract a basis decoder from a template asset
basis_decoder(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' basis_decoder(template, ...) ## S4 method for signature 'AWPTBasisTemplate' basis_decoder(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' basis_decoder(template, ...) ## S4 method for signature 'ParcelBasisTemplate' basis_decoder(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' basis_decoder(template, ...)basis_decoder(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' basis_decoder(template, ...) ## S4 method for signature 'AWPTBasisTemplate' basis_decoder(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' basis_decoder(template, ...) ## S4 method for signature 'ParcelBasisTemplate' basis_decoder(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' basis_decoder(template, ...)
template |
A template object. |
... |
Additional arguments passed to methods. |
Basis decoder view object.
Diffusion wavelet basis specification
basis_diffusion_wavelet( target_rank = 2000L, oversample = 20L, threshold = NULL, max_scales = 1L, epsilon = NULL, seed = 1L, sparsify_eps = NULL )basis_diffusion_wavelet( target_rank = 2000L, oversample = 20L, threshold = NULL, max_scales = 1L, epsilon = NULL, seed = 1L, sparsify_eps = NULL )
target_rank |
Cap on retained components per scale (keeps runtime bounded). |
oversample |
Oversampling for randomized range finder. |
threshold |
Deprecated alias for 'sparsify_eps'. |
max_scales |
Maximum diffusion scales to compute. |
epsilon |
Optional precision (unused in capped-rank path; kept for API parity). |
seed |
Optional integer seed for deterministic randomized range finding. |
sparsify_eps |
Absolute value threshold to enforce sparsity in compressed operators. Stored as 'threshold' for compatibility. |
A 'spec_diffusion_wavelet' basis specification descriptor.
'basis_flat()' creates a descriptor for methods that should lift a reduction without estimating local components, typically as a simple parcel/cluster indicator basis.
basis_flat()basis_flat()
An empty list with class 'spec_flat'.
Heat wavelet basis specification
basis_heat_wavelet(scales = c(1, 2, 4, 8), order = 30, threshold = 1e-06)basis_heat_wavelet(scales = c(1, 2, 4, 8), order = 30, threshold = 1e-06)
scales |
Numeric vector of heat diffusion scales. |
order |
Polynomial approximation order. |
threshold |
Threshold for small coefficients. |
A 'spec_heat_wavelet' object for 'lift()'.
'basis_pca()' creates a lightweight descriptor for parcel- or cluster-local PCA bases. The descriptor is consumed by 'lift(ClusterReduction, spec_pca, data = ...)', where 'data' supplies the time-by-voxel matrix used to estimate the components.
basis_pca(k = 3, whiten = FALSE)basis_pca(k = 3, whiten = FALSE)
k |
Positive integer number of PCA components. |
whiten |
Logical scalar. 'basis_pca()' records this request, but 'lift(ClusterReduction, spec_pca)' returns unwhitened loadings and emits a warning when 'whiten = TRUE'; the higher-level 'encode(spec_space_pca())' path applies whitening after projection. |
A list with class 'spec_pca' containing 'k' and 'whiten'.
'basis_slepian()' creates a lightweight descriptor for graph/Slepian basis construction during 'lift()' or spatial encoding. It records the requested component count and Slepian flavor; the actual basis is computed later by a 'lift()' method for the supplied reduction.
basis_slepian(k = 3, type = "laplacian")basis_slepian(k = 3, type = "laplacian")
k |
Positive integer number of Slepian components. |
type |
Character scalar naming the Slepian basis flavor. The built-in spatial methods use '"laplacian"'. |
A list with class 'spec_slepian' containing 'k' and 'type'.
Benchmark encode/decode round-trips
benchmark_roundtrip( mask_dims = c(16, 16, 8), n_time = 10L, methods = c("slepian_space", "hrbf", "wavelet_active", "bspline_hrbf_st"), iterations = 1L )benchmark_roundtrip( mask_dims = c(16, 16, 8), n_time = 10L, methods = c("slepian_space", "hrbf", "wavelet_active", "bspline_hrbf_st"), iterations = 1L )
mask_dims |
Integer vector length 3 for spatial dims. |
n_time |
Integer time points. |
methods |
Character vector of families: "slepian_space", "hrbf", "wavelet_active", "bspline_hrbf_st". |
iterations |
Integer iterations per method (default 1 to stay fast). |
A data.frame/tibble with timings and reconstruction error.
Construct a bilateral surface latent object
BilatLatentNeuroSurfaceVector(left, right, label = "", meta = list())BilatLatentNeuroSurfaceVector(left, right, label = "", meta = list())
left |
Left |
right |
Right |
label |
Optional label. |
meta |
Optional metadata list. |
A BilatLatentNeuroSurfaceVector.
An explicit bilateral surface latent representation composed of left and
right LatentNeuroSurfaceVector objects.
leftLeft-hemisphere latent surface object.
rightRight-hemisphere latent surface object.
labelCharacter label.
metaLightweight metadata list.
Construct a block-domain latent object
BlockLatentNeuroVector(blocks, label = "", meta = list())BlockLatentNeuroVector(blocks, label = "", meta = list())
blocks |
Named list of explicit latent objects sharing a common basis. |
label |
Optional label. |
meta |
Optional metadata list. |
A BlockLatentNeuroVector.
An explicit block-domain latent representation composed of multiple named latent blocks sharing a common coefficient basis. Intended for hybrid domains such as bilateral cortical surfaces plus volumetric subcortex.
blocksNamed list of explicit latent objects.
labelCharacter label.
metaLightweight metadata list.
Construct sparse innovation event settings for BOLDZip-SR
boldzip_events(max_events = 256L, threshold_sd = 3, paired_fraction = 0.25)boldzip_events(max_events = 256L, threshold_sd = 3, paired_fraction = 0.25)
max_events |
Maximum number of residual events to store. |
threshold_sd |
Residual event threshold in robust standard deviations. |
paired_fraction |
Minimum paired split amplitude agreement. |
A 'BoldZipSREvents' settings object.
Constructs an experimental graph-adapted spatial basis from a symmetric adjacency matrix. Low-frequency graph Laplacian eigenvectors become coarse carrier support functions and the following higher-frequency eigenvectors become detail atoms. This is a materialized small-to-medium graph MVP, not a production graph-wavelet operator.
boldzip_graph_spatial_basis( adjacency, n_coarse = 8L, n_detail = NULL, normalized = TRUE, label = NULL )boldzip_graph_spatial_basis( adjacency, n_coarse = 8L, n_detail = NULL, normalized = TRUE, label = NULL )
adjacency |
Symmetric non-negative adjacency matrix. |
n_coarse |
Number of low-frequency eigenvectors to use as 'phi_c'. |
n_detail |
Number of following eigenvectors to use as 'phi_d'. Defaults to all remaining eigenvectors. |
normalized |
Whether to use the normalized graph Laplacian. |
label |
Optional label stored in metadata. |
A 'BoldZipSRSpatialBasis' object.
Reconstruct a matrix from parcel-average time series
boldzip_parcel_reconstruct(X, parcels)boldzip_parcel_reconstruct(X, parcels)
X |
Numeric matrix with dimensions 'voxels x time'. |
parcels |
Integer, factor, or character vector with one parcel label per row of 'X'. |
Matrix with the same dimensions as 'X', expanded from parcel means.
Construct reliability-aware quantization settings for BOLDZip-SR
boldzip_quantization(base_step = 0, epsilon = 1e-06)boldzip_quantization(base_step = 0, epsilon = 1e-06)
base_step |
Base quantization step. Set to 0 to disable quantization. |
epsilon |
Small positive value used in reliability-shaped step sizes. |
A 'BoldZipSRQuantization' settings object.
Construct split-half reliability settings for BOLDZip-SR
boldzip_reliability( split = c("odd_even", "halves"), min_texture_reliability = 0, min_temporal_reliability = 0 )boldzip_reliability( split = c("odd_even", "halves"), min_texture_reliability = 0, min_temporal_reliability = 0 )
split |
Split strategy. '"odd_even"' pairs adjacent odd/even time points; '"halves"' pairs the first and second half of the run. |
min_texture_reliability |
Minimum held-out reliability required to keep a fine-detail texture loading. |
min_temporal_reliability |
Minimum carrier reliability required before temporal coefficients are kept. Carriers below this threshold are zeroed. |
A 'BoldZipSRReliability' settings object.
Build a matrix spatial basis descriptor for BOLDZip-SR
boldzip_spatial_basis( phi_c = NULL, phi_d = NULL, label = NULL, basis_asset = NULL )boldzip_spatial_basis( phi_c = NULL, phi_d = NULL, label = NULL, basis_asset = NULL )
phi_c |
Optional coarse basis matrix with rows equal to voxels. |
phi_d |
Optional detail basis matrix with rows equal to voxels. If 'NULL', the detail basis is the identity basis. |
label |
Optional label stored in metadata. |
basis_asset |
Optional source template or shared-basis object used to build this descriptor. |
A 'BoldZipSRSpatialBasis' object.
Decode an experimental BOLDZip-SR object
boldzip_sr_decode(object, time_idx = NULL, roi = NULL)boldzip_sr_decode(object, time_idx = NULL, roi = NULL)
object |
A 'BoldZipSR' object. |
time_idx |
Optional integer time indices to return. |
roi |
Optional integer or logical row subset to return. |
Reconstructed matrix with rows as voxels/grayordinates and columns as time points.
'boldzip_sr_encode()' is an experimental matrix-level implementation of Split-Reliable Graph Carrier Compression. It expects a matrix with rows as voxels or grayordinates and columns as time points. The implementation stores temporally compressed carriers, sparse high-resolution texture loadings, and sparse split-reliable residual events. It is intended as a research prototype, not a production binary codec.
boldzip_sr_encode( X, spatial_basis = NULL, k_carriers = 96L, temporal_k = NULL, temporal_spec = NULL, q_texture = 2L, texture_lags = 0L, reliability = boldzip_reliability(), quantization = boldzip_quantization(), events = boldzip_events(), center = TRUE, label = NULL )boldzip_sr_encode( X, spatial_basis = NULL, k_carriers = 96L, temporal_k = NULL, temporal_spec = NULL, q_texture = 2L, texture_lags = 0L, reliability = boldzip_reliability(), quantization = boldzip_quantization(), events = boldzip_events(), center = TRUE, label = NULL )
X |
Numeric matrix with dimensions 'voxels x time'. |
spatial_basis |
Optional 'BoldZipSRSpatialBasis' object or list with 'phi_c' and 'phi_d' matrices. If omitted, the detail basis is identity and carriers are learned from 'X' directly. |
k_carriers |
Number of carrier time courses to learn. |
temporal_k |
Number of DCT coefficients per carrier. Defaults to 'ceiling(n_time / 4)' when 'temporal_spec' is 'NULL'. |
temporal_spec |
Optional temporal basis descriptor. May be a 'SharedTemporalSpec', 'spec_time_dct', 'spec_time_bspline', or numeric basis matrix with rows equal to time points. When supplied, it determines the temporal basis and 'temporal_k'. |
q_texture |
Maximum number of carrier loadings per detail atom. |
texture_lags |
Integer vector of allowed carrier lags for texture loading fits. A positive lag uses 'Z_k(t - lag)'. |
reliability |
Reliability settings from [boldzip_reliability()]. |
quantization |
Quantization settings from [boldzip_quantization()]. |
events |
Event settings from [boldzip_events()]. |
center |
Whether to store and remove a voxel-wise mean before fitting. |
label |
Optional label stored in metadata. |
A 'BoldZipSR' object.
Summarize an experimental BOLDZip-SR payload
boldzip_sr_payload_summary(object)boldzip_sr_payload_summary(object)
object |
A 'BoldZipSR' object. |
Data frame with component counts and approximate object bytes.
Simulate data with BOLDZip-SR carrier, texture, and event structure
boldzip_sr_simulate( n_voxels = 40L, n_time = 80L, k_carriers = 3L, q_texture = 1L, n_events = 8L, noise_sd = 0.05, seed = NULL )boldzip_sr_simulate( n_voxels = 40L, n_time = 80L, k_carriers = 3L, q_texture = 1L, n_events = 8L, noise_sd = 0.05, seed = NULL )
n_voxels |
Number of spatial rows. |
n_time |
Number of time points. |
k_carriers |
Number of latent carrier time courses. |
q_texture |
Number of non-zero carrier loadings per voxel. |
n_events |
Number of paired impulse events to add. |
noise_sd |
Independent Gaussian noise standard deviation. |
seed |
Optional random seed. |
List containing 'X', 'mu', 'carriers', 'texture', and 'events'.
Reconstruct a matrix from a low-rank SVD baseline
boldzip_svd_reconstruct(X, rank, center = TRUE)boldzip_svd_reconstruct(X, rank, center = TRUE)
X |
Numeric matrix with dimensions 'voxels x time'. |
rank |
SVD rank. |
center |
Whether to remove and restore row means. |
Matrix with the same dimensions as 'X'.
Create a BasisHandle for a B-spline temporal basis
bspline_basis_handle( n_time, k, degree = 3L, knots = NULL, boundary_knots = NULL, include_intercept = FALSE, orthonormalize = TRUE, id = NULL, label = NULL )bspline_basis_handle( n_time, k, degree = 3L, knots = NULL, boundary_knots = NULL, include_intercept = FALSE, orthonormalize = TRUE, id = NULL, label = NULL )
n_time |
Integer, number of time points. |
k |
Integer, number of spline basis functions (df). |
degree |
Degree of the spline (default 3). |
knots |
Optional interior knots (scaled 0-1). |
boundary_knots |
Optional boundary knots (scaled 0-1). |
include_intercept |
Logical; include intercept column (default FALSE). |
orthonormalize |
Logical; orthonormalize columns when materialized. |
id |
Optional registry key (generated if NULL). |
label |
Optional human-readable label. |
A BasisHandle.
Constructs a multi-level spatial basis from nested parcellations using graph Laplacian eigenvectors. The resulting template can be reused to efficiently encode multiple datasets that share the same mask geometry.
build_hierarchical_template( mask, parcellations, k_per_level, k_neighbors = 6L, ridge = 1e-08, solver = c("chol", "qr"), label = "hierarchical_laplacian" )build_hierarchical_template( mask, parcellations, k_per_level, k_neighbors = 6L, ridge = 1e-08, solver = c("chol", "qr"), label = "hierarchical_laplacian" )
mask |
LogicalNeuroVol or logical array (3D) defining the domain. |
parcellations |
List of integer vectors (one per level) of length = #voxels in mask. Levels must be nested: each child parcel maps to exactly one parent parcel in the previous level. |
k_per_level |
Integer vector giving #modes per parcel at each level. |
k_neighbors |
k for local graph construction inside parcels. |
ridge |
Small diagonal ridge added to |
solver |
Solver choice: "chol" (default) or "qr" fallback. |
label |
Optional label stored in meta. |
HierarchicalBasisTemplate (primal basis B + cached solver and metadata).
Convenience wrapper that combines 'build_schaefer_levels()' with 'build_hierarchical_template()' to produce a ready-to-use template with geodesic-informed parcel clustering.
build_schaefer_hierarchical_template( mask, parcels = 400, networks = 17, space = "fsaverage6", k_levels = c(16, 32, 64), k_per_level = c(8, 5, 3, 1), vol_atlas = NULL, alpha = 0.5, beta = 0.3, gamma = 0.2, d0 = 30, component_policy = "largest", cache = TRUE, k_neighbors = 6L, ridge = 1e-08, solver = c("chol", "qr") )build_schaefer_hierarchical_template( mask, parcels = 400, networks = 17, space = "fsaverage6", k_levels = c(16, 32, 64), k_per_level = c(8, 5, 3, 1), vol_atlas = NULL, alpha = 0.5, beta = 0.3, gamma = 0.2, d0 = 30, component_policy = "largest", cache = TRUE, k_neighbors = 6L, ridge = 1e-08, solver = c("chol", "qr") )
mask |
LogicalNeuroVol defining the 3D brain mask (MNI space). |
parcels |
Integer. Number of Schaefer parcels (100, 200, 300, 400, 500, 600, 800, 1000). |
networks |
Integer. Yeo network variant (7 or 17). |
space |
Character. Surface space ("fsaverage6", "fsaverage", "fsaverage5"). |
k_levels |
Integer vector of cluster counts for coarser levels, ordered coarse→fine. The finest level is always the original Schaefer parcellation. Example: c(16, 32, 64) produces 4 levels: L0=16, L1=32, L2=64, L3=Schaefer-parcels. |
k_per_level |
Integer vector of eigenmodes per parcel at each level. Length must match length(k_levels) + 1 (for the finest Schaefer level). |
vol_atlas |
Optional. Pre-loaded volumetric Schaefer atlas (NeuroVol with parcel IDs). If NULL, attempts to load via neuroatlas::get_schaefer_atlas(). |
alpha |
Weight for boundary contact in similarity (default 0.5). |
beta |
Weight for geodesic kernel in similarity (default 0.3). |
gamma |
Weight for Yeo network agreement in similarity (default 0.2). |
d0 |
Scale for geodesic exponential kernel (default 30 mm). |
component_policy |
How to handle fragmented parcels ("error", "largest", "each", "merge"). |
cache |
Logical. Use cached geodesic distances if available (default TRUE). |
k_neighbors |
k for local graph construction inside parcels. |
ridge |
Small diagonal ridge for Gram matrix stability. |
solver |
Solver choice: "chol" or "qr". |
HierarchicalBasisTemplate object.
build_hierarchical_template, build_schaefer_levels
Constructs nested parcellation levels for the hierarchical template by: 1. Loading Schaefer surface atlas from neuroatlas 2. Computing geodesic distances and boundary contacts via neurosurf 3. Building a parcel similarity matrix (geodesic + boundary + network) 4. Performing spectral Ward clustering to create coarser levels 5. Mapping surface parcels back to volumetric voxel labels
Real-data glue to finish: - Provide fsaverage Schaefer surfaces (via 'neuroatlas::schaefer_surf') so we can compute geodesic/boundary terms. - Provide the volumetric Schaefer atlas aligned to the MNI mask (via 'neuroatlas::get_schaefer_atlas'). - Ensure mask and volumetric atlas share resolution/origin/spacing; this function assumes 2 mm MNI unless you pass a custom 'vol_atlas'. - Subcortex is **not** handled here; add it separately when assembling the full template.
build_schaefer_levels( mask, parcels = 400, networks = 17, space = "fsaverage6", k_levels = c(16, 32, 64), vol_atlas = NULL, alpha = 0.5, beta = 0.3, gamma = 0.2, d0 = 30, component_policy = c("largest", "error", "each", "merge"), cache = TRUE )build_schaefer_levels( mask, parcels = 400, networks = 17, space = "fsaverage6", k_levels = c(16, 32, 64), vol_atlas = NULL, alpha = 0.5, beta = 0.3, gamma = 0.2, d0 = 30, component_policy = c("largest", "error", "each", "merge"), cache = TRUE )
mask |
LogicalNeuroVol defining the 3D brain mask (MNI space). |
parcels |
Integer. Number of Schaefer parcels (100, 200, 300, 400, 500, 600, 800, 1000). |
networks |
Integer. Yeo network variant (7 or 17). |
space |
Character. Surface space ("fsaverage6", "fsaverage", "fsaverage5"). |
k_levels |
Integer vector of cluster counts for coarser levels, ordered coarse→fine. The finest level is always the original Schaefer parcellation. Example: c(16, 32, 64) produces 4 levels: L0=16, L1=32, L2=64, L3=Schaefer-parcels. |
vol_atlas |
Optional. Pre-loaded volumetric Schaefer atlas (NeuroVol with parcel IDs). If NULL, attempts to load via neuroatlas::get_schaefer_atlas(). |
alpha |
Weight for boundary contact in similarity (default 0.5). |
beta |
Weight for geodesic kernel in similarity (default 0.3). |
gamma |
Weight for Yeo network agreement in similarity (default 0.2). |
d0 |
Scale for geodesic exponential kernel (default 30 mm). |
component_policy |
How to handle fragmented parcels ("error", "largest", "each", "merge"). |
cache |
Logical. Use cached geodesic distances if available (default TRUE). |
Requires 'neuroatlas' and 'neurosurf' packages. The surface atlas provides geodesic distances and boundary topology; the volumetric atlas maps parcels to mask voxels.
A list with components:
levels |
List of integer vectors (length = #voxels in mask), one per level, nested. |
network |
Character vector of Yeo network labels per finest-level parcel. |
hemi |
Character vector of hemisphere ("L"/"R") per finest-level parcel. |
geo_dist_lh, geo_dist_rh
|
Parcel geodesic distance matrices (for diagnostics). |
boundary_lh, boundary_rh
|
Boundary contact matrices (LH/RH). |
Cluster-based reduction (e.g., supervoxels or atlas)
mapInteger vector (voxel order) mapping each voxel to a cluster id.
cluster_idsUnique cluster ids present in 'map'.
Coarsened graph reduction (e.g., prolongation from coarse to fine)
P_matrixSparse prolongation matrix (fine x coarse).
coarse_adjOptional sparse adjacency on the coarse graph.
Extract coefficient-space metric from a latent object
coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'LatentNeuroSurfaceVector' coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'ImplicitLatent' coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'LatentNeuroVec' coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'BlockLatentNeuroVector' coef_metric(x, coordinates = c("analysis", "raw"), ...)coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'LatentNeuroSurfaceVector' coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'ImplicitLatent' coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'LatentNeuroVec' coef_metric(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'BlockLatentNeuroVector' coef_metric(x, coordinates = c("analysis", "raw"), ...)
x |
A latent object. |
coordinates |
Coordinate system for the requested metric. |
... |
Additional arguments passed to methods. |
Matrix-like metric representation or NULL. For
transport-backed latent objects, analysis coordinates are Euclidean by
contract in v1. Raw-coordinate metrics are returned when the
raw-to-analysis transform exposes a linear matrix representation.
Extract coefficient time series from a latent object
coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'LatentNeuroSurfaceVector' coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'ImplicitLatent' coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'LatentNeuroVec' coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'BlockLatentNeuroVector' coef_time(x, coordinates = c("analysis", "raw"), ...)coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'LatentNeuroSurfaceVector' coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'ImplicitLatent' coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'LatentNeuroVec' coef_time(x, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'BlockLatentNeuroVector' coef_time(x, coordinates = c("analysis", "raw"), ...)
x |
A latent object. |
coordinates |
Coordinate system for the returned coefficients. |
... |
Additional arguments passed to methods. |
Numeric matrix with rows = time and columns = latent coefficients.
Compare BOLDZip-SR against simple reconstruction baselines
compare_boldzip_sr(X, fit, parcels = NULL, svd_ranks = NULL)compare_boldzip_sr(X, fit, parcels = NULL, svd_ranks = NULL)
X |
Original matrix with rows as voxels/grayordinates and columns as time points. |
fit |
A 'BoldZipSR' object. |
parcels |
Optional parcel labels for a parcel-average baseline. |
svd_ranks |
Optional integer vector of SVD ranks. |
Data frame with method, MSE, RMSE, correlation, and scalar payload estimates.
Concatenates two or more LatentNeuroVec objects along the temporal dimension.
## S4 method for signature 'LatentNeuroVec,LatentNeuroVec' concat(x, y, ...)## S4 method for signature 'LatentNeuroVec,LatentNeuroVec' concat(x, y, ...)
x |
First |
y |
Second |
... |
Additional |
A new LatentNeuroVec if all objects are compatible, otherwise
a NeuroVecSeq-class.
mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) combined <- concat(lvec, lvec) dim(combined)mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) combined <- concat(lvec, lvec) dim(combined)
Utility to turn a hierarchical clustering (on parcels) into a nested set of parcel label vectors that downstream code can lift into voxel space. Real data glue: you will pass the hclust built on a parcel-level similarity graph (e.g., Schaefer-400 parcel graph constructed from surface geodesics and boundary contacts); then map these parcel labels back to voxels using the volumetric atlas.
cut_hclust_nested(hc, k_levels)cut_hclust_nested(hc, k_levels)
hc |
hclust object (e.g., from spectral_ward_hclust()). |
k_levels |
Integer vector of cluster counts, ordered coarse→fine (e.g., c(16, 32, 64, 400)). |
List of integer label vectors (same length as hc$labels), one per level, nested by construction.
Create a BasisHandle for a DCT temporal basis
dct_basis_handle(n_time, k, norm = c("ortho", "none"), id = NULL, label = NULL)dct_basis_handle(n_time, k, norm = c("ortho", "none"), id = NULL, label = NULL)
n_time |
Number of time points. |
k |
Number of components. |
norm |
Normalization passed to [build_dct_basis()]. |
id |
Optional registry key; if NULL a deterministic id is derived from parameters. |
label |
Optional human-readable label. |
A BasisHandle object.
Decode coefficient-space vectors into an output space
decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'ImplicitLatent' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'LatentNeuroVec' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'BlockLatentNeuroVector' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... )decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'ImplicitLatent' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'LatentNeuroVec' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... ) ## S4 method for signature 'BlockLatentNeuroVector' decode_coefficients( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), wrap = c("none", "auto"), ... )
x |
A latent object. |
gamma |
Coefficient-space vector or matrix. |
space |
Output space to decode into. |
coordinates |
Coordinate system used by |
wrap |
If |
... |
Additional arguments passed to methods. |
Numeric vector or matrix in the requested output space, or a
domain-aware wrapper when wrap = "auto".
Push coefficient covariance into an output space
decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'ImplicitLatent' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'LatentNeuroVec' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'BlockLatentNeuroVector' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... )decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'ImplicitLatent' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'LatentNeuroVec' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'BlockLatentNeuroVector' decode_covariance( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... )
x |
A latent object. |
Sigma |
Coefficient covariance matrix. |
space |
Output space to decode into. |
coordinates |
Coordinate system used by |
diag_only |
Logical; if |
... |
Additional arguments passed to methods. |
Numeric vector or matrix in the requested output space.
Get a decoder view for a latent object
decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'ImplicitLatent' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'LatentNeuroVec' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'BlockLatentNeuroVector' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... )decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'ImplicitLatent' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'LatentNeuroVec' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'BlockLatentNeuroVector' decoder( x, space = c("native", "template"), coordinates = c("analysis", "raw"), ... )
x |
A latent object. |
space |
Output space to decode into. |
coordinates |
Coordinate system consumed by the decoder. |
... |
Additional arguments passed to methods. |
Decoder view object.
Diffusion wavelet latent constructor (explicit basis)
diffusion_wavelet_latent( X, mask, reduction = NULL, spec = basis_diffusion_wavelet(), k_neighbors = 6L, label = "" )diffusion_wavelet_latent( X, mask, reduction = NULL, spec = basis_diffusion_wavelet(), k_neighbors = 6L, label = "" )
X |
Matrix time x voxels (mask order). |
mask |
LogicalNeuroVol or 3D logical array. |
reduction |
ClusterReduction; if NULL, defaults to one cluster per voxel. |
spec |
diffusion wavelet spec (basis_diffusion_wavelet()). |
k_neighbors |
k for graph building. |
label |
Optional label. |
A 'LatentNeuroVec' object.
Wraps a diffusion-wavelet 'lift()' call so multiple 'LatentNeuroVec' instances can share the same spatial dictionary without embedding the full matrix in each object.
diffusion_wavelet_loadings_handle( reduction, basis_spec = basis_diffusion_wavelet(), data = NULL, k_neighbors = 6L, id = NULL, label = "diffusion-wavelet" )diffusion_wavelet_loadings_handle( reduction, basis_spec = basis_diffusion_wavelet(), data = NULL, k_neighbors = 6L, id = NULL, label = "diffusion-wavelet" )
reduction |
Graph/cluster reduction used by 'lift()'. |
basis_spec |
Basis specification; defaults to 'basis_diffusion_wavelet()'. |
data |
Ignored by diffusion-wavelet lifting; accepted only to keep the lifted-handle constructor signature aligned across families. |
k_neighbors |
k for graph building when lifting. |
id |
Optional registry id; provide a stable string to reuse across sessions. If NULL, a deterministic id is derived from the spec and reduction. |
label |
Optional human-readable label. |
A LoadingsHandle.
Generates Discrete Prolate Spheroidal Sequences (DPSS) for a given series length and bandwidth. Uses an internal RcppEigen solver over the prolate matrix; suitable for moderate 'n_time'. For very long series, a tridiagonal solver can replace the backend with the same interface.
dpss_time_basis( n_time, tr, bandwidth, k = NULL, backend = c("tridiag", "dense") )dpss_time_basis( n_time, tr, bandwidth, k = NULL, backend = c("tridiag", "dense") )
n_time |
Integer length of the time dimension. |
tr |
Repetition time in seconds. |
bandwidth |
Half-bandwidth in Hz (typical BOLD range 0.008–0.1). |
k |
Optional number of tapers; defaults to |
backend |
DPSS backend. Only |
Numeric matrix (n_time x k) with orthonormal columns.
Encode data into a latent representation using a spec
encode( x, spec, mask, reduction = NULL, materialize = c("auto", "handle", "matrix"), label = "", ... )encode( x, spec, mask, reduction = NULL, materialize = c("auto", "handle", "matrix"), label = "", ... )
x |
Matrix (time x voxels in mask order). |
spec |
Standard encode spec object created by 'spec_time_*', 'spec_space_*', or 'spec_st'. AWPT specs created by [basis_awpt_wavelet()] describe shared templates and are intentionally not accepted by 'encode()'; use [encode_awpt()] or [encode_operator()] for transport-backed AWPT fits. |
mask |
LogicalNeuroVol or logical array (required for spatial pieces). |
reduction |
Optional GraphReduction (for spatial specs). |
materialize |
"handle", "matrix", or "auto" (default "handle"). |
label |
Optional label. |
... |
Additional arguments passed to methods. |
The return class depends on the spec family:
'spec_space_slepian', 'spec_space_heat', 'spec_space_hrbf', 'spec_space_pca', and 'spec_space_wavelet_active' return a [LatentNeuroVec], which is a concrete 'ExplicitLatent' (the virtual marker defined at 'R/all_class.R'). It stores an explicit 'basis x loadings + offset' factorization.
'spec_time_slepian', 'spec_time_dct', and 'spec_time_bspline' likewise return a [LatentNeuroVec] ('ExplicitLatent').
**Always** returns an 'ImplicitLatent' (a decoder-only / separable representation), even when both the time and space factors are fully explicit dense bases. 'ImplicitLatent' is *not* an 'ExplicitLatent'.
return a 'TransportLatent', which is also *not* an 'ExplicitLatent'.
In short: 'ExplicitLatent' is the virtual S4 marker inherited by [LatentNeuroVec]; 'ImplicitLatent' and 'TransportLatent' are S3 classes that deliberately do not inherit it.
For standard in-mask matrix encoders, 'encode()' routes to the S3 generic [encode_spec()], which dispatches on the spec class and builds the latent object directly. Transport-backed AWPT is the explicit exception: an AWPT basis spec is used to build a shared template, while the subject fit also requires a 'basis_asset' and 'field_operator'. Those assets are not part of the standard 'encode_spec()' signature, so AWPT enters through [encode_awpt()] or [encode_operator()] instead of [encode()].
A [LatentNeuroVec] reconstructs its data as 'basis (length = number of in-mask voxels) added back after the low-rank term. The offset is owned by the encoder's *lift* step, which is the single place that decides whether and how to center:
Only 'spec_space_pca' produces a non-empty offset, and only when 'center = TRUE' (the default): the per-voxel column means are removed before the PCA and stored in the 'offset' slot so reconstruction restores them. The mean removal is performed exactly once, inside 'lift.basis_pca' (see the 'fmrilatent.mean_scores' attribute it returns); the encode caller does not re-center. With 'center = FALSE', PCA stores 'offset = numeric(0)'.
All other explicit families ('spec_space_slepian', 'spec_space_heat', 'spec_space_hrbf', 'spec_time_slepian', 'spec_time_dct', 'spec_time_bspline') store 'offset = numeric(0)', i.e. no offset.
By convention 'offset = numeric(0)' means "no offset" and reconstruction treats it as a zero vector; a populated 'offset' always has one entry per in-mask voxel. The shared '.encode_center()' helper is the single implementation of column-mean centering used by the offset-producing paths.
Encode data using the AWPT model
encode_awpt( x, basis_asset, field_operator = NULL, observation_operator = NULL, mask = NULL, domain = NULL, support = NULL, spatial_lambda = 0, temporal_lambda = 0, temporal_order = 1L, sparse_lambda = 0, sparse_mode = c("none", "group_l2", "lasso"), max_iter = 200L, tol = 1e-06, center = TRUE, run_info = NULL, label = "", ... )encode_awpt( x, basis_asset, field_operator = NULL, observation_operator = NULL, mask = NULL, domain = NULL, support = NULL, spatial_lambda = 0, temporal_lambda = 0, temporal_order = 1L, sparse_lambda = 0, sparse_mode = c("none", "group_l2", "lasso"), max_iter = 200L, tol = 1e-06, center = TRUE, run_info = NULL, label = "", ... )
x |
Numeric matrix (time x target samples) or a |
basis_asset |
An |
field_operator |
Subject field operator. See
|
observation_operator |
Legacy alias for |
mask |
Optional volumetric target mask for the field-operator target domain. |
domain |
Optional non-volumetric target domain. |
support |
Optional target support aligned to |
spatial_lambda |
Strength of the anatomical roughness penalty. |
temporal_lambda |
Strength of temporal smoothing. |
temporal_order |
Temporal difference order for smoothing. |
sparse_lambda |
Strength of optional sparse atom selection. |
sparse_mode |
Sparse penalty mode. Use |
max_iter |
Maximum iterations for sparse AWPT optimization. |
tol |
Relative convergence tolerance for sparse AWPT optimization. |
center |
Logical; if |
run_info |
Optional run metadata; |
label |
Optional label stored in metadata. |
... |
Reserved for future extensions. |
AWPT does not expose a separate ridge penalty. The returned metadata records
lambda = 0; the anatomical roughness penalty is recorded separately as
spatial_lambda.
A TransportLatent object with AWPT metadata.
Note: unlike parcel and AWPT encoding, hierarchical encoding does not
center the data. The returned offset is always numeric(0).
encode_hierarchical( X, template, label = NULL, mask = NULL, materialize = c("handle", "auto", "matrix") )encode_hierarchical( X, template, label = NULL, mask = NULL, materialize = c("handle", "auto", "matrix") )
X |
matrix time x voxels (mask order) matching template mask |
template |
HierarchicalBasisTemplate |
label |
Optional label for the resulting LatentNeuroVec (defaults to template label) |
mask |
Optional mask to validate against the template mask before encoding. When supplied, it must match the template exactly. |
materialize |
"handle", "matrix", or "auto" for template loadings. |
LatentNeuroVec with basis = time x atoms coefficients, loadings = template loadings
Encode data using a shared basis asset and subject field operator
encode_operator( x, template, field_operator = NULL, observation_operator = NULL, mask = NULL, domain = NULL, support = NULL, lambda = 0, center = TRUE, run_info = NULL, spatial_lambda = lambda, spatial_penalty = NULL, temporal_lambda = 0, temporal_order = 1L, sparse_lambda = 0, sparse_mode = c("none", "group_l2", "lasso"), max_iter = 200L, tol = 1e-06, label = "", ... )encode_operator( x, template, field_operator = NULL, observation_operator = NULL, mask = NULL, domain = NULL, support = NULL, lambda = 0, center = TRUE, run_info = NULL, spatial_lambda = lambda, spatial_penalty = NULL, temporal_lambda = 0, temporal_order = 1L, sparse_lambda = 0, sparse_mode = c("none", "group_l2", "lasso"), max_iter = 200L, tol = 1e-06, label = "", ... )
x |
Numeric matrix (time x target samples) or a |
template |
Shared basis asset providing |
field_operator |
Subject field operator mapping template field samples to observed native samples. |
observation_operator |
Legacy alias for |
mask |
Optional volumetric target mask for the field-operator target domain. |
domain |
Optional non-volumetric target domain, for example a surface geometry. |
support |
Optional target support aligned to |
lambda |
Ridge penalty strength. |
center |
Logical; if |
run_info |
Optional run metadata carried on the resulting latent object. |
spatial_lambda |
Strength of the spatial coefficient penalty. |
spatial_penalty |
Optional coefficient-space roughness matrix or diagonal weights. |
temporal_lambda |
Strength of temporal smoothing. |
temporal_order |
Difference order used for temporal smoothing. |
sparse_lambda |
Strength of optional sparse coefficient shrinkage. |
sparse_mode |
Sparse penalty mode. Use |
max_iter |
Maximum iterations for sparse AWPT optimization. |
tol |
Relative convergence tolerance for sparse AWPT optimization. |
label |
Optional label stored in metadata. |
... |
Reserved for future extensions. |
The external field-operator contract is intentionally narrow. 'fmrilatent' consumes an operator-like object with:
n_source, n_target
Source and target dimensions.
source_domain_id, target_domain_id
Stable domain identifiers.
forward(z)Applies the operator to template field samples.
adjoint_apply(y)Applies the adjoint map.
provenance$target_maskOptional target-domain mask when
the caller does not pass mask explicitly.
On the main quadratic and sparse transport/AWPT paths, coefficient recovery is matrix-free: ‘fmrilatent' uses the operator’s forward and adjoint methods rather than materializing the full subject decoder.
A TransportLatent object.
Dispatch standard encoding based on spec type
encode_spec(x, spec, ...)encode_spec(x, spec, ...)
x |
Data matrix. |
spec |
Spec object. |
... |
Additional arguments passed to methods. |
'encode_spec()' is the S3 dispatch seam for standard 'encode()' specs: temporal, spatial, hierarchical, parcel, and spatiotemporal specs. AWPT's 'basis_awpt_wavelet()' object is a template-construction spec, not a complete subject-encoding spec, because AWPT fitting additionally needs a shared template/basis asset and subject field or observation operators. AWPT therefore uses the parallel transport API [encode_awpt()] / [encode_operator()].
Encoded representation.
Encode data using transport-backed latent semantics
encode_transport( x, basis_asset, field_operator = NULL, observation_operator = NULL, mask = NULL, domain = NULL, support = NULL, lambda = 0, center = TRUE, run_info = NULL, spatial_lambda = lambda, spatial_penalty = NULL, temporal_lambda = 0, temporal_order = 1L, sparse_lambda = 0, sparse_mode = c("none", "group_l2", "lasso"), max_iter = 200L, tol = 1e-06, label = "", ... )encode_transport( x, basis_asset, field_operator = NULL, observation_operator = NULL, mask = NULL, domain = NULL, support = NULL, lambda = 0, center = TRUE, run_info = NULL, spatial_lambda = lambda, spatial_penalty = NULL, temporal_lambda = 0, temporal_order = 1L, sparse_lambda = 0, sparse_mode = c("none", "group_l2", "lasso"), max_iter = 200L, tol = 1e-06, label = "", ... )
x |
Numeric matrix (time x target samples) or a |
basis_asset |
Shared basis asset. |
field_operator |
Subject field operator. See
|
observation_operator |
Legacy alias for |
mask |
Optional volumetric target mask for the field-operator target domain. |
domain |
Optional non-volumetric target domain. |
support |
Optional target support aligned to |
lambda |
Ridge penalty strength. |
center |
Logical; if |
run_info |
Optional run metadata carried on the resulting latent object. |
spatial_lambda |
Strength of the spatial coefficient penalty. |
spatial_penalty |
Optional coefficient-space roughness matrix or diagonal weights. |
temporal_lambda |
Strength of temporal smoothing. |
temporal_order |
Difference order used for temporal smoothing. |
sparse_lambda |
Strength of optional sparse coefficient shrinkage. |
sparse_mode |
Sparse penalty mode. Use |
max_iter |
Maximum iterations for sparse AWPT optimization. |
tol |
Relative convergence tolerance for sparse AWPT optimization. |
label |
Optional label stored in metadata. |
... |
Reserved for future extensions. |
A TransportLatent object.
Evaluate BOLDZip-SR reconstruction quality
evaluate_boldzip_sr(X, object, reliability_weights = NULL)evaluate_boldzip_sr(X, object, reliability_weights = NULL)
X |
Original matrix with rows as voxels/grayordinates and columns as time points. |
object |
A 'BoldZipSR' object or a reconstructed matrix. |
reliability_weights |
Optional matrix or vector of reliability weights. |
Named numeric vector with reconstruction metrics.
Returns the active fmrilatent compatibility profile. This is used to opt into strict behavior for external packages that require historical semantics.
fmrilatent_compat_profile(profile = NULL)fmrilatent_compat_profile(profile = NULL)
profile |
Optional explicit profile name. If 'NULL', uses 'getOption("fmrilatent.compat", "native")'. |
A single character string profile identifier.
Removes cached materialized matrices from the internal registry. Use this to free memory or force re-materialization of handles.
fmrilatent_registry_clear(type = c("all", "basis", "loadings"))fmrilatent_registry_clear(type = c("all", "basis", "loadings"))
type |
Which registry to clear: "basis", "loadings", or "all" (default). |
Invisibly, the number of entries removed.
# Clear all cached matrices fmrilatent_registry_clear() # Clear only basis matrices fmrilatent_registry_clear("basis")# Clear all cached matrices fmrilatent_registry_clear() # Clear only basis matrices fmrilatent_registry_clear("basis")
The handle registry caches materialized matrices for BasisHandle and
LoadingsHandle objects. This can improve performance and reduce memory
duplication when multiple LatentNeuroVec objects share the same handle
IDs.
fmrilatent_registry_enable() fmrilatent_registry_disable() fmrilatent_registry_enabled()fmrilatent_registry_enable() fmrilatent_registry_disable() fmrilatent_registry_enabled()
Set fmrilatent_registry_disable() to turn off caching (useful for
deterministic benchmarking or to avoid retaining large matrices).
Invisibly, TRUE.
The cache is bounded. Each registry (basis and loadings) holds at most
getOption("fmrilatent.registry.max_entries", 256) materialized
matrices; once full, the least-recently-used entry is evicted on the next
registration. Both registration and retrieval count as a use. Set the option
to Inf (or a non-positive value) to restore an unbounded cache, or call
fmrilatent_registry_clear() to drop everything immediately.
fmrilatent_registry_disable() fmrilatent_registry_enable()fmrilatent_registry_disable() fmrilatent_registry_enable()
Returns the IDs of all cached matrices in the registry.
fmrilatent_registry_list(type = c("all", "basis", "loadings"))fmrilatent_registry_list(type = c("all", "basis", "loadings"))
type |
Which registry to list: "basis", "loadings", or "all" (default). |
Character vector of registered IDs.
# See what's cached fmrilatent_registry_list()# See what's cached fmrilatent_registry_list()
Returns count and approximate memory usage of cached matrices.
fmrilatent_registry_stats(type = c("all", "basis", "loadings"))fmrilatent_registry_stats(type = c("all", "basis", "loadings"))
type |
Which registry: "basis", "loadings", or "all" (default). |
A list with count and bytes for each registry type.
fmrilatent_registry_stats()fmrilatent_registry_stats()
Creates a small synthetic dataset suitable for testing encode_spec methods.
Useful for extension packages that implement custom encoders.
fmrilatent_test_data(dims = c(3L, 3L, 2L), n_time = 8L)fmrilatent_test_data(dims = c(3L, 3L, 2L), n_time = 8L)
dims |
Integer vector of spatial dimensions (default |
n_time |
Number of time points (default 8). |
A list with elements:
X |
Numeric matrix (n_time x n_voxels) of random data. |
mask |
Logical array of dimensions |
dims |
The spatial dimensions used. |
n_time |
The number of time points used. |
td <- fmrilatent_test_data() dim(td$X) # 8 x 18 dim(td$mask) # 3 x 3 x 2td <- fmrilatent_test_data() dim(td$X) # 8 x 18 dim(td$mask) # 3 x 3 x 2
Retrieves the registration entry for a given encoder family.
get_encoder(family)get_encoder(family)
family |
Character string identifying the encoder family. |
A list with elements spec_fn, description, and package.
enc <- get_encoder("time_dct") spec <- enc$spec_fn(k = 5)enc <- get_encoder("time_dct") spec <- enc$spec_fn(k = 5)
These classes describe how voxels are grouped or coarsened before a basis is computed and lifted back to ambient space. Implementations of 'lift()' for specific combinations (e.g., supervoxel + Slepian, parcel PCA) live in external packages or downstream code; fmrilatent ships only the contracts.
mask'LogicalNeuroVol' defining the ambient domain.
infoOptional list for implementation-specific metadata.
Represent subject loadings as group shared loadings plus a delta
group_delta_loadings(group, delta = NULL, scale = 1, id = NULL, meta = list())group_delta_loadings(group, delta = NULL, scale = 1, id = NULL, meta = list())
group |
Matrix-like shared/group loadings or a 'SharedReference'. |
delta |
Optional subject-specific loading delta. If 'NULL', a zero delta is used. |
scale |
Numeric multiplier applied to 'delta'. |
id |
Optional id. |
meta |
Optional advisory metadata. |
A 'GroupDeltaLoadings' object.
Build Haar latent representation
haar_latent( X, mask, levels = NULL, z_seed = 42L, threshold = list(type = "none", value = 0) )haar_latent( X, mask, levels = NULL, z_seed = 42L, threshold = list(type = "none", value = 0) )
X |
Numeric matrix (time x voxels within mask). |
mask |
LogicalNeuroVol or 3D logical array. |
levels |
Decomposition levels (optional). |
z_seed |
Integer Morton seed (default 42). |
threshold |
Threshold list passed to 'haar_wavelet_forward'. |
An object of class 'HaarLatent' containing coefficients and metadata.
Get metadata from Haar latent object
haar_meta(x)haar_meta(x)
x |
A Haar latent object |
Metadata list or NULL
Forward Haar wavelet transform (mask-adaptive, Morton order)
haar_wavelet_forward( X, mask, levels = NULL, z_seed = 42L, threshold = list(type = "none", value = 0) )haar_wavelet_forward( X, mask, levels = NULL, z_seed = 42L, threshold = list(type = "none", value = 0) )
X |
Numeric matrix with time in rows and voxels (masked) in columns. |
mask |
3D logical array or LogicalNeuroVol defining the mask. |
levels |
Number of decomposition levels; defaults to ceil(log2(max(dim(mask)))). |
z_seed |
Integer seed for Morton ordering (tie-breaking). |
threshold |
List with fields 'type' ("none" | "absolute" | "relative_to_root_std") and 'value'. |
List with elements 'coeff' (list(root, detail)), 'meta' (counts, Morton hash, etc.).
Inverse Haar wavelet transform
haar_wavelet_inverse( coeff, mask, levels = NULL, z_seed = NULL, roi_mask = NULL, time_idx = NULL, levels_keep = NULL )haar_wavelet_inverse( coeff, mask, levels = NULL, z_seed = NULL, roi_mask = NULL, time_idx = NULL, levels_keep = NULL )
coeff |
Output from 'haar_wavelet_forward()' (list with root/detail matrices). |
mask |
3D logical array or LogicalNeuroVol. |
levels |
Integer levels (defaults to 'meta$levels' if present). |
z_seed |
Integer Morton seed (defaults to 'meta$z_seed'). |
roi_mask |
Optional ROI mask (same dims as mask) to subset voxels before returning. |
time_idx |
Optional integer vector of time indices to subset rows. |
levels_keep |
Optional integer vector of detail levels to include (1 = finest, 'levels' = coarsest). Levels not listed are zeroed, enabling coarse/partial reconstruction without full detail. |
Matrix (time x voxels) reconstructed (or subsetted if ROI/time specified).
Heat wavelet latent constructor (explicit basis)
heat_wavelet_latent( X, mask, reduction = NULL, spec = basis_heat_wavelet(), k_neighbors = 6L, label = "" )heat_wavelet_latent( X, mask, reduction = NULL, spec = basis_heat_wavelet(), k_neighbors = 6L, label = "" )
X |
Matrix time x voxels (mask order) |
mask |
LogicalNeuroVol or 3D logical array |
reduction |
ClusterReduction; if NULL, defaults to one cluster per voxel |
spec |
heat wavelet spec (basis_heat_wavelet()) |
k_neighbors |
k for local graph building |
label |
Optional label |
A 'LatentNeuroVec' object.
Wraps a heat-wavelet 'lift()' call so multiple 'LatentNeuroVec' instances can share the same spatial dictionary without embedding the full matrix in each object.
heat_wavelet_loadings_handle( reduction, basis_spec = basis_heat_wavelet(), data = NULL, k_neighbors = 6L, id = NULL, label = "heat-wavelet" )heat_wavelet_loadings_handle( reduction, basis_spec = basis_heat_wavelet(), data = NULL, k_neighbors = 6L, id = NULL, label = "heat-wavelet" )
reduction |
Graph/cluster reduction used by 'lift()'. |
basis_spec |
Basis specification; defaults to 'basis_heat_wavelet()'. |
data |
Ignored by heat-wavelet lifting; accepted only to keep the lifted-handle constructor signature aligned across families. |
k_neighbors |
Number of neighbors used for local graph construction when materializing the lifted basis. |
id |
Optional registry id; provide a stable string to reuse across sessions. If NULL, a deterministic id is derived from the spec and reduction. |
label |
Optional human-readable label. |
A LoadingsHandle.
A template-only, data-agnostic container for hierarchical Laplacian frames. Stores the sparse spatial dictionary (primal basis), a cached solver for the Gram matrix, and the parcellation hierarchy metadata. Intended to be built offline for a fixed template (e.g., MNI) and reused for encoding fMRI data.
maskLogicalNeuroVol defining the domain (3D).
spaceNeuroSpace (typically 4D with a singleton time dim) matching the mask.
levelsList of integer vectors (one per level) giving parcel ids per voxel (mask order).
parentsList mapping child parcel ids to parent ids for each level > 1.
loadingsSparse Matrix (voxels x atoms) containing concatenated atoms B.
gram_factorCached factorization of (e.g., dCHMsimpl from Matrix::Cholesky).
atomsdata.frame describing each atom (col_id, level, parcel_id, parent_id, mode, label).
metaList for auxiliary metadata (atlas names, k_per_level, ridge, version).
Utilities to generate analytic HRBF bases, project data, reconstruct, and build 'LatentNeuroVec' objects. Parameters are kept simple and in-R only (no descriptors or HDF5).
hrbf_generate_basis(params, mask) hrbf_project_matrix(X, mask, params) hrbf_reconstruct_matrix(coeff, mask, params)hrbf_generate_basis(params, mask) hrbf_project_matrix(X, mask, params) hrbf_reconstruct_matrix(coeff, mask, params)
params |
List with fields: - 'sigma0' (numeric, default 6) - 'levels' (integer, default 3) - 'radius_factor' (numeric, default 2.5) - 'num_extra_fine_levels' (integer, default 0) - 'kernel_type' (\"gaussian\", \"wendland_c4\", or \"wendland_c6\") - 'seed' (integer) for deterministic Poisson sampling |
mask |
'LogicalNeuroVol' mask defining voxel locations. |
X |
Numeric matrix with time in rows and voxels in columns. |
coeff |
Coefficient matrix with rows = time points. |
For 'hrbf_generate_basis', a sparse matrix with one row per HRBF atom and columns matching mask voxels.
Build a LatentNeuroVec using an HRBF basis
hrbf_latent(X, mask, params = list(), label = "")hrbf_latent(X, mask, params = list(), label = "")
X |
Numeric matrix (time x voxels within mask). |
mask |
'LogicalNeuroVol'. |
params |
HRBF parameter list (see 'hrbf_generate_basis'). |
label |
Optional character label. |
A 'LatentNeuroVec' with 'basis = coefficients', 'loadings = t(HRBF_basis)'.
Retrieve HRBF metadata if present
hrbf_meta(x)hrbf_meta(x)
x |
A LatentNeuroVec object |
HRBF metadata list or NULL if not HRBF-tagged
Computes only the requested voxels (and optional timepoints) without materializing the full dense volume. Useful for fast indexed access.
hrbf_reconstruct_partial(coeff, mask, params, voxel_idx, time_idx = NULL)hrbf_reconstruct_partial(coeff, mask, params, voxel_idx, time_idx = NULL)
coeff |
Coefficient matrix (time x atoms). |
mask |
'LogicalNeuroVol'. |
params |
HRBF parameter list. |
voxel_idx |
Integer vector of voxel linear indices (within the mask grid). |
time_idx |
Optional integer vector of time indices; defaults to all rows. |
Matrix of shape length(time_idx) x length(voxel_idx).
Construct an ImplicitLatent object
implicit_latent( coeff, decoder, meta, mask = NULL, domain = NULL, support = NULL )implicit_latent( coeff, decoder, meta, mask = NULL, domain = NULL, support = NULL )
coeff |
Arbitrary coefficient payload (list or matrix) needed by decoder. |
decoder |
Function(time_idx = NULL, roi_mask = NULL, levels_keep = NULL) returning matrix. |
meta |
List metadata; must include 'family' string. |
mask |
Logical 3D array (or LogicalNeuroVol) describing volumetric support. |
domain |
Optional decoded output domain. For non-volumetric latent objects,
supply a domain such as a |
support |
Optional decoded output support. For volumetric latent objects this
is usually derived from |
An object of class 'ImplicitLatent'.
Get metadata from ImplicitLatent object
implicit_meta(x)implicit_meta(x)
x |
An ImplicitLatent object |
Metadata list or NULL
Test whether a latent object is explicit
is_explicit_latent(x, ...) ## S4 method for signature 'ExplicitLatent' is_explicit_latent(x, ...) ## S4 method for signature 'ImplicitLatent' is_explicit_latent(x, ...)is_explicit_latent(x, ...) ## S4 method for signature 'ExplicitLatent' is_explicit_latent(x, ...) ## S4 method for signature 'ImplicitLatent' is_explicit_latent(x, ...)
x |
A latent object. |
... |
Additional arguments (unused). |
Logical scalar; TRUE when the object stores explicit basis and
loadings matrices.
Test if object is a Haar latent representation
is_haar_latent(x)is_haar_latent(x)
x |
Object to test |
Logical indicating if x is a Haar latent
Check whether an object is a HierarchicalBasisTemplate
is_hierarchical_template(x)is_hierarchical_template(x)
x |
object to test |
Logical scalar.
Check if latent object carries HRBF metadata
is_hrbf_latent(x)is_hrbf_latent(x)
x |
Object to test |
Logical indicating if x has HRBF metadata
Test if object is an ImplicitLatent
is_implicit_latent(x)is_implicit_latent(x)
x |
Object to test |
Logical indicating if x is an ImplicitLatent
Test whether an object is a surface basis template
is_surface_template(x)is_surface_template(x)
x |
Object to test. |
Logical scalar.
Test whether an object is a supported template
is_template(x)is_template(x)
x |
object to test |
Logical scalar.
Test whether an object is a transport-backed latent object
is_transport_latent(x)is_transport_latent(x)
x |
Object to test. |
Logical scalar.
Builds a LatentNeuroVec whose loadings are a heat-wavelet
LoadingsHandle and whose basis is a placeholder zero matrix of
n_time x k (where k is determined by the heat-wavelet
loadings, not by the caller). The caller is expected to overwrite
lvec@basis with real coefficients (e.g. fitted from data) before
the object represents a valid factorization.
latent_dct_heatwavelet( n_time, k_time = NULL, mask, cluster_map = NULL, reduction = NULL, hw_basis_spec = NULL, offset = numeric(0), label = "DCT + heat-wavelet" )latent_dct_heatwavelet( n_time, k_time = NULL, mask, cluster_map = NULL, reduction = NULL, hw_basis_spec = NULL, offset = numeric(0), label = "DCT + heat-wavelet" )
n_time |
Number of time points. |
k_time |
Optional ignored legacy argument. The number of components is determined by the heat-wavelet loadings. Supplying a non-NULL value warns with class 'fmrilatent_warning_deprecated'. |
mask |
LogicalNeuroVol or logical array mask (3D). |
cluster_map |
Optional integer vector mapping voxels (mask order) to clusters. |
reduction |
Graph reduction object; if NULL, built via 'make_cluster_reduction(mask, cluster_map)' with default one-cluster-per-voxel map. |
hw_basis_spec |
Heat-wavelet basis spec; defaults to 'basis_heat_wavelet()'. |
offset |
Optional voxel-wise offset (length n_vox). |
label |
Optional label. |
Despite the name, no DCT basis is constructed: the "dct" reference
predates the spec/encoder pipeline and is retained for API
compatibility. For an encoded DCT-temporal + heat-wavelet-spatial
pipeline see spec_st(time = spec_time_dct(...), space = spec_space_heat(...))
passed to encode.
A LatentNeuroVec with placeholder basis matrix.
Extract the decoded domain associated with a latent object
latent_domain(x, ...) ## S4 method for signature 'ImplicitLatent' latent_domain(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' latent_domain(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' latent_domain(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' latent_domain(x, ...) ## S4 method for signature 'LatentNeuroVec' latent_domain(x, ...)latent_domain(x, ...) ## S4 method for signature 'ImplicitLatent' latent_domain(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' latent_domain(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' latent_domain(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' latent_domain(x, ...) ## S4 method for signature 'LatentNeuroVec' latent_domain(x, ...)
x |
A latent object. |
... |
Additional arguments passed to methods. |
Domain object or identifier.
Simple factory to build a spec and encode in one call
latent_factory( family, x, mask, reduction = NULL, ..., materialize = "auto", label = "" )latent_factory( family, x, mask, reduction = NULL, ..., materialize = "auto", label = "" )
family |
Character scalar naming one of the standard 'encode()' families. See **Accepted family names** for the canonical names and supported aliases. |
x |
Data matrix (time x voxels). |
mask |
Mask (required for spatial families). |
reduction |
Optional GraphReduction for spatial specs. |
... |
Passed to spec constructors and encode(). |
materialize |
"handle", "matrix", or "auto" (default "handle"). |
label |
Optional label for the resulting object. |
The class follows the same per-family contract as [encode()]: explicit spatial families and explicit temporal families return a [LatentNeuroVec] (a concrete 'ExplicitLatent'); the spatiotemporal families ('st_slepian', 'st_bspline_hrbf') build a 'spec_st' and therefore always return an 'ImplicitLatent'. See the '@return' section of [encode()] for the full taxonomy.
Canonical names are listed first; aliases in parentheses are accepted for compatibility.
'time_dct' ('dct_time'), 'time_slepian' ('slepian_time').
'space_slepian' ('slepian_space'), 'space_pca' ('pca_space'), 'space_parcel' ('parcel_space'), 'space_heat' ('heat_space'), 'space_hrbf' ('hrbf_space'), 'space_wavelet_active' ('wavelet_active'), and 'hierarchical'.
'st' (requires explicit 'time' and 'space' specs), 'st_slepian' ('slepian_st'), and 'st_bspline_hrbf' ('bspline_hrbf_st').
AWPT is intentionally not a 'latent_factory()' family because it requires a shared 'basis_asset' and a subject 'field_operator'; use [encode_awpt()] or [encode_operator()] for AWPT subject fitting.
Get lightweight metadata from a latent object
latent_meta(x, ...) ## S4 method for signature 'ImplicitLatent' latent_meta(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' latent_meta(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' latent_meta(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' latent_meta(x, ...) ## S4 method for signature 'LatentNeuroVec' latent_meta(x, ...)latent_meta(x, ...) ## S4 method for signature 'ImplicitLatent' latent_meta(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' latent_meta(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' latent_meta(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' latent_meta(x, ...) ## S4 method for signature 'LatentNeuroVec' latent_meta(x, ...)
x |
A latent object. |
... |
Additional arguments (unused). |
Metadata list.
Runs a user-supplied function 'fun' for each neighborhood using only latent quantities. 'fun' is called with arguments '(B, L_V, M_V, idx, ...)', where: - 'B' is the basis matrix (time x k) - 'L_V' is the loadings restricted to the neighborhood (|V| x k) - 'M_V = t(L_V) - 'idx' is the voxel indices of the neighborhood 'fun' should return any R object; results are collected in a list.
latent_searchlight(basis, loadings, neighborhoods, fun, ...)latent_searchlight(basis, loadings, neighborhoods, fun, ...)
basis |
Matrix or BasisHandle (time x k) from a LatentNeuroVec. |
loadings |
Matrix or LoadingsHandle (voxels x k) from a LatentNeuroVec. |
neighborhoods |
List of integer vectors of voxel indices (mask order). |
fun |
Function(B, L_V, M_V, idx, ...) returning a result per neighborhood. |
... |
Passed through to 'fun'. |
List of results, one per neighborhood.
Extract the decoded support associated with a latent object
latent_support(x, ...) ## S4 method for signature 'ImplicitLatent' latent_support(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' latent_support(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' latent_support(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' latent_support(x, ...) ## S4 method for signature 'LatentNeuroVec' latent_support(x, ...)latent_support(x, ...) ## S4 method for signature 'ImplicitLatent' latent_support(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' latent_support(x, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' latent_support(x, ...) ## S4 method for signature 'BlockLatentNeuroVector' latent_support(x, ...) ## S4 method for signature 'LatentNeuroVec' latent_support(x, ...)
x |
A latent object. |
... |
Additional arguments passed to methods. |
Support object for the latent representation.
Construct a LatentNeuroSurfaceVector
LatentNeuroSurfaceVector( basis, loadings, geometry, support = NULL, offset = NULL, label = "", meta = list() )LatentNeuroSurfaceVector( basis, loadings, geometry, support = NULL, offset = NULL, label = "", meta = list() )
basis |
Temporal basis matrix ( |
loadings |
Surface loadings matrix ( |
geometry |
A |
support |
Surface support as vertex indices or a logical vector over all vertices. |
offset |
Optional numeric vector of length |
label |
Optional label. |
meta |
Optional metadata list. |
A LatentNeuroSurfaceVector.
An explicit latent representation for surface-domain neuroimaging data. The
data are stored as a temporal basis matrix and a surface loadings matrix over
a supported set of vertices on a neurosurf geometry.
basisA Matrix or BasisHandle with dimensions
(nTime x k).
loadingsA Matrix or LoadingsHandle with dimensions
(nVerticesInSupport x k).
offsetOptional numeric vector of length nVerticesInSupport.
geometrySurface domain object, typically a
neurosurf::SurfaceGeometry or neurosurf::SurfaceSet.
supportInteger vector of vertex indices within geometry.
labelCharacter label.
metaLightweight metadata list.
Constructs a LatentNeuroVec-class object, which provides a memory-efficient
representation of neuroimaging data using matrix factorization. This is particularly useful
for dimensionality reduction techniques (e.g., PCA or ICA).
LatentNeuroVec( basis, loadings, space, mask, offset = NULL, label = "", meta = list(), expect_dense = FALSE )LatentNeuroVec( basis, loadings, space, mask, offset = NULL, label = "", meta = list(), expect_dense = FALSE )
basis |
A numeric or |
loadings |
A numeric or |
space |
A |
mask |
A |
offset |
Optional numeric vector of length |
label |
Optional character label for the object. |
meta |
Optional list of metadata (e.g., HRBF params or centres). |
expect_dense |
Logical; if 'TRUE', suppress the informational message emitted when a base-matrix 'basis'/'loadings' is dense (>50 families (e.g. diffusion wavelets) where a dense factor is by design. Defaults to 'FALSE', preserving the original message behavior. |
Construct a LatentNeuroVec Object
The data is represented as the product:
where:
B is the basis matrix ()
L is the loadings matrix ()
c is an optional offset vector (length p)
n is the number of time points
p is the number of voxels in the mask
k is the number of components
A new LatentNeuroVec-class instance.
# Example data n_timepoints <- 4 n_components <- 2 mask_array <- array(TRUE, dim = c(2, 2, 1)) n_voxels <- sum(mask_array) # Create basis & loadings basis <- Matrix::Matrix(seq_len(n_timepoints * n_components), nrow = n_timepoints, ncol = n_components ) loadings <- Matrix::Matrix(seq_len(n_voxels * n_components) / 10, nrow = n_voxels, ncol = n_components, sparse = TRUE ) # Create space (2x2x1 volume, 4 timepoints) spc <- neuroim2::NeuroSpace(c(2, 2, 1, n_timepoints)) # Create mask mask_vol <- neuroim2::LogicalNeuroVol(mask_array, neuroim2::NeuroSpace(c(2, 2, 1))) # Construct LatentNeuroVec lvec <- LatentNeuroVec( basis = basis, loadings = loadings, space = spc, mask = mask_vol, expect_dense = TRUE ) dim(lvec)# Example data n_timepoints <- 4 n_components <- 2 mask_array <- array(TRUE, dim = c(2, 2, 1)) n_voxels <- sum(mask_array) # Create basis & loadings basis <- Matrix::Matrix(seq_len(n_timepoints * n_components), nrow = n_timepoints, ncol = n_components ) loadings <- Matrix::Matrix(seq_len(n_voxels * n_components) / 10, nrow = n_voxels, ncol = n_components, sparse = TRUE ) # Create space (2x2x1 volume, 4 timepoints) spc <- neuroim2::NeuroSpace(c(2, 2, 1, n_timepoints)) # Create mask mask_vol <- neuroim2::LogicalNeuroVol(mask_array, neuroim2::NeuroSpace(c(2, 2, 1))) # Construct LatentNeuroVec lvec <- LatentNeuroVec( basis = basis, loadings = loadings, space = spc, mask = mask_vol, expect_dense = TRUE ) dim(lvec)
A class that represents a 4-dimensional neuroimaging array using a latent space decomposition. It stores the data as a set of basis functions (dictionary) and a corresponding set of loadings (coefficients), enabling efficient representation and manipulation of high-dimensional data.
LatentNeuroVec inherits from NeuroVec-class
and AbstractSparseNeuroVec-class. The original 4D data
can be reconstructed as:
where v indexes voxels within the mask and t indexes time points.
This approach is especially useful for large datasets where storing the full 4D array is expensive. Common use cases include:
PCA-reduced fMRI data
ICA decompositions
Dictionary learning representations
Any matrix factorization of neuroimaging data
basisA Matrix or BasisHandle where each column represents a basis
vector in the latent space. Dimensions are (nTime x k) where k is the number of components.
loadingsA Matrix or LoadingsHandle (often sparse) containing the
coefficients for each basis vector across the spatial dimensions. Dimensions are
(nVoxels x k).
offsetA numeric vector representing a constant offset term for
each voxel or spatial location. Length is nVoxels (within mask).
mapA IndexLookupVol object representing the mapping from 3D coordinates
to linear indices within the mask.
labelA character string representing the label for the latent vector.
metaA list storing lightweight metadata (e.g., HRBF params, centers).
LatentNeuroVec inherits from:
NeuroVec-class - base 4D neuroimaging class
AbstractSparseNeuroVec-class - sparse representation framework
NeuroVec-class,
AbstractSparseNeuroVec-class,
LatentNeuroVec constructor function.
n_timepoints <- 4 n_components <- 2 mask_array <- array(TRUE, dim = c(2, 2, 1)) n_voxels <- sum(mask_array) # Create basis (temporal) & loadings (spatial) basis <- Matrix::Matrix(seq_len(n_timepoints * n_components), nrow = n_timepoints, ncol = n_components ) loadings <- Matrix::Matrix(seq_len(n_voxels * n_components) / 10, nrow = n_voxels, ncol = n_components, sparse = TRUE ) # Create space (2x2x1 volume, 4 timepoints) spc <- neuroim2::NeuroSpace(c(2, 2, 1, n_timepoints)) # Create mask mask_vol <- neuroim2::LogicalNeuroVol(mask_array, neuroim2::NeuroSpace(c(2, 2, 1))) # Construct LatentNeuroVec lvec <- LatentNeuroVec( basis = basis, loadings = loadings, space = spc, mask = mask_vol, expect_dense = TRUE ) dim(lvec)n_timepoints <- 4 n_components <- 2 mask_array <- array(TRUE, dim = c(2, 2, 1)) n_voxels <- sum(mask_array) # Create basis (temporal) & loadings (spatial) basis <- Matrix::Matrix(seq_len(n_timepoints * n_components), nrow = n_timepoints, ncol = n_components ) loadings <- Matrix::Matrix(seq_len(n_voxels * n_components) / 10, nrow = n_voxels, ncol = n_components, sparse = TRUE ) # Create space (2x2x1 volume, 4 timepoints) spc <- neuroim2::NeuroSpace(c(2, 2, 1, n_timepoints)) # Create mask mask_vol <- neuroim2::LogicalNeuroVol(mask_array, neuroim2::NeuroSpace(c(2, 2, 1))) # Construct LatentNeuroVec lvec <- LatentNeuroVec( basis = basis, loadings = loadings, space = spc, mask = mask_vol, expect_dense = TRUE ) dim(lvec)
Lift reduced bases back to voxel space (abstract generic)
lift(reduction, basis_spec, data = NULL, ...)lift(reduction, basis_spec, data = NULL, ...)
reduction |
A 'GraphReduction' subclass describing topology. |
basis_spec |
A basis specification (e.g., 'basis_slepian()'). |
data |
Optional data for data-driven bases (e.g., PCA). |
... |
Additional arguments passed to methods (e.g., k_neighbors). |
Typically a voxel x components 'Matrix' (often sparse) or an implementation-defined object for implicit decoders.
Lift diffusion wavelets for clustered reduction
## S4 method for signature 'ClusterReduction,spec_diffusion_wavelet' lift(reduction, basis_spec, data = NULL, k_neighbors = 6L, ...)## S4 method for signature 'ClusterReduction,spec_diffusion_wavelet' lift(reduction, basis_spec, data = NULL, k_neighbors = 6L, ...)
reduction |
ClusterReduction describing voxel-to-cluster map. |
basis_spec |
Diffusion wavelet spec (basis_diffusion_wavelet()). |
data |
Ignored for this graph-only spatial dictionary; accepted only for the shared 'lift()' method signature. |
k_neighbors |
k for graph building (cluster centroids). |
... |
Additional arguments (unused). |
Matrix of loadings (voxels x components) concatenating scaling bases across scales.
Lift heat wavelets for clustered reduction
## S4 method for signature 'ClusterReduction,spec_heat_wavelet' lift(reduction, basis_spec, data = NULL, k_neighbors = 6L, ...)## S4 method for signature 'ClusterReduction,spec_heat_wavelet' lift(reduction, basis_spec, data = NULL, k_neighbors = 6L, ...)
reduction |
ClusterReduction describing voxel-to-cluster map. |
basis_spec |
Heat wavelet spec (basis_heat_wavelet()). |
data |
Ignored for this graph-only spatial dictionary; accepted only for the shared 'lift()' method signature. |
k_neighbors |
k for local graph building. |
... |
Additional arguments (unused). |
Sparse Matrix (voxels x components).
Computes PCA eigenvectors within each cluster and assembles a global block-sparse loadings matrix (voxels x components). This is typically used with 'encode(..., spec_space_pca(...), reduction = ...)'.
## S4 method for signature 'ClusterReduction,spec_pca' lift( reduction, basis_spec, data = NULL, center = TRUE, scale = FALSE, offset = NULL, backend = c("auto", "svds", "svd"), ... )## S4 method for signature 'ClusterReduction,spec_pca' lift( reduction, basis_spec, data = NULL, center = TRUE, scale = FALSE, offset = NULL, backend = c("auto", "svds", "svd"), ... )
reduction |
ClusterReduction describing voxel-to-cluster map. |
basis_spec |
PCA basis specification (from 'basis_pca()'). |
data |
Required numeric matrix (time x voxels in mask order). Unlike graph-only lift methods, PCA consumes 'data' to estimate cluster-local components and aborts when it is 'NULL'. |
center |
Logical; center voxels before PCA (default TRUE). |
scale |
Logical; scale voxels before PCA (default FALSE). |
offset |
Optional numeric vector of voxel means (length n_vox). If provided and 'center = TRUE', this is used instead of recomputing 'colMeans(data)'. |
backend |
SVD backend: "auto" (default), "svds" (RSpectra), or "svd" (base). |
... |
Unused. |
'lift(ClusterReduction, spec_pca)' always returns unwhitened spatial loadings. If 'basis_spec$whiten' is 'TRUE', the method emits a classed warning because whitening requires the projected temporal scores and is therefore the caller's responsibility. The standard 'encode(..., spec_space_pca(whiten = TRUE))' path handles this post-lift whitening using the 'fmrilatent.singular_values' attribute attached here.
A sparse Matrix (voxels x components) with attribute 'fmrilatent.singular_values' giving per-component singular values.
Lift spatial Slepians for clustered reduction
## S4 method for signature 'ClusterReduction,spec_slepian' lift(reduction, basis_spec, data = NULL, k_neighbors = 6L, ...)## S4 method for signature 'ClusterReduction,spec_slepian' lift(reduction, basis_spec, data = NULL, k_neighbors = 6L, ...)
reduction |
ClusterReduction describing voxel-to-cluster map. |
basis_spec |
Slepian basis specification (from 'basis_slepian()'). |
data |
Ignored for this graph-only spatial dictionary; accepted only for the shared 'lift()' method signature. |
k_neighbors |
k for local graph building. |
... |
Additional arguments (unused). |
Sparse Matrix (voxels x components), block-concatenated over clusters.
This method exists to provide a clear error when no concrete lift is registered. External packages should implement methods for specific (reduction, basis_spec) signatures.
## S4 method for signature 'GraphReduction,ANY' lift(reduction, basis_spec, data = NULL, ...)## S4 method for signature 'GraphReduction,ANY' lift(reduction, basis_spec, data = NULL, ...)
reduction |
A 'GraphReduction' subclass. |
basis_spec |
A basis specification object. |
data |
Optional data for data-driven bases. |
... |
Additional arguments (unused in default method). |
This method does not return; it aborts with a classed unsupported-operation error.
Access elements of a LatentNeuroVec using linear (1D) indexing.
Reconstructs values on-the-fly from the basis and loadings factorization.
Access elements of a LatentNeuroVec using linear (1D) indices
into the 4D array representation.
## S4 method for signature 'LatentNeuroVec,numeric' linear_access(x, i) ## S4 method for signature 'LatentNeuroVec,integer' linear_access(x, i)## S4 method for signature 'LatentNeuroVec,numeric' linear_access(x, i) ## S4 method for signature 'LatentNeuroVec,integer' linear_access(x, i)
x |
A |
i |
Numeric index vector |
Numeric vector of reconstructed values
The reconstructed values at the specified indices
Returns a data.frame describing all registered encoder families, including both built-in encoders and those added by external packages.
list_encoders()list_encoders()
A data.frame with columns: family, description, package.
list_encoders()list_encoders()
Compatibility entry point for external callers that need explicit control over centre/sigma inputs and output column-space semantics.
lna_hrbf_basis_from_params( params, mask, centres = NULL, sigmas = NULL, full_grid = TRUE, compat_profile = NULL, mask_world_coords = NULL, mask_arr = NULL, mask_linear_indices = NULL )lna_hrbf_basis_from_params( params, mask, centres = NULL, sigmas = NULL, full_grid = TRUE, compat_profile = NULL, mask_world_coords = NULL, mask_arr = NULL, mask_linear_indices = NULL )
params |
HRBF parameter list. |
mask |
'LogicalNeuroVol' mask defining voxel locations. |
centres |
Optional numeric matrix ('K x 3') of world-space centres. |
sigmas |
Optional numeric vector ('K') of sigma values for 'centres'. |
full_grid |
Logical. If 'TRUE', basis columns index the full mask grid ('length(as.array(mask))'); if 'FALSE', columns index active mask voxels. |
compat_profile |
Optional explicit compatibility profile identifier. |
mask_world_coords |
Optional precomputed active-voxel world coords. |
mask_arr |
Optional precomputed logical mask array. |
mask_linear_indices |
Optional precomputed active-voxel linear indices. |
Sparse matrix with one row per HRBF atom.
Load a hierarchical template from disk
load_hierarchical_template(file)load_hierarchical_template(file)
file |
Path to .rds produced by save_hierarchical_template |
HierarchicalBasisTemplate
Load a saved template from disk
load_template(file)load_template(file)
file |
Path to a template RDS file. |
A supported template object.
Extract the loadings matrix from a latent space representation. For
LatentNeuroVec objects, this returns the spatial loadings matrix
with dimensions (nVoxels x k) where k is the number of components and
nVoxels is the number of voxels within the mask.
loadings(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' loadings(x) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' loadings(x) ## S4 method for signature 'BlockLatentNeuroVector' loadings(x) ## S4 method for signature 'LatentNeuroVec' loadings(x)loadings(x, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' loadings(x) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' loadings(x) ## S4 method for signature 'BlockLatentNeuroVector' loadings(x) ## S4 method for signature 'LatentNeuroVec' loadings(x)
x |
An object containing loadings (e.g., |
... |
Additional arguments (currently unused) |
The loadings matrix (typically voxels x components)
mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) l_matrix <- loadings(lvec) dim(l_matrix)mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) l_matrix <- loadings(lvec) dim(l_matrix)
Create a ClusterReduction from a mask and voxel-to-cluster map
make_cluster_reduction(mask, map)make_cluster_reduction(mask, map)
mask |
A |
map |
Integer vector (mask order) mapping each voxel to a cluster id. |
A ClusterReduction object.
Create a coarsened graph reduction
make_coarsened_reduction(mask, P_matrix, coarse_adj = NULL, info = list())make_coarsened_reduction(mask, P_matrix, coarse_adj = NULL, info = list())
mask |
'LogicalNeuroVol' or array-like mask defining the fine domain. |
P_matrix |
Fine-by-coarse sparse prolongation matrix. |
coarse_adj |
Optional coarse-by-coarse sparse adjacency matrix. |
info |
Optional metadata list. |
A valid 'CoarsenedReduction'.
Extract the index map from a latent space representation. For
LatentNeuroVec objects, this returns the IndexLookupVol
that maps 3D coordinates to linear mask indices.
## S4 method for signature 'LatentNeuroVec' map(x)## S4 method for signature 'LatentNeuroVec' map(x)
x |
An object containing a map (e.g., |
The index lookup object
Extract the brain mask from a latent space representation. For
LatentNeuroVec objects, this returns the LogicalNeuroVol
defining which voxels are included in the representation.
## S4 method for signature 'ImplicitLatent' mask(x) ## S4 method for signature 'LatentNeuroVec' mask(x)## S4 method for signature 'ImplicitLatent' mask(x) ## S4 method for signature 'LatentNeuroVec' mask(x)
x |
An object containing a mask (e.g., |
The logical mask volume
Safely converts a LogicalNeuroVol or array-like mask to a plain
logical array, with informative error messages on failure.
mask_to_array(mask, location = "unknown function")mask_to_array(mask, location = "unknown function")
mask |
A |
location |
Character string used in error messages to identify the caller. |
A logical array.
Materialize group-plus-delta loadings
materialize_group_delta_loadings(x)materialize_group_delta_loadings(x)
x |
A 'GroupDeltaLoadings' object. |
Matrix-like materialized loadings.
The handoff contract records the boundary between in-memory representation responsibilities owned by fmrilatent and persistent archive responsibilities owned by neuroarchive. It is intentionally a manifest, not a lazy archive reader or file locator.
neuroarchive_handoff_contract( representation = NULL, components = list(), templates = list(), references = list(), meta = list() )neuroarchive_handoff_contract( representation = NULL, components = list(), templates = list(), references = list(), meta = list() )
representation |
Optional fmrilatent representation object. |
components |
Optional list of shared component contracts. |
templates |
Optional list of reusable template assets. |
references |
Optional list of in-session shared references. |
meta |
Optional advisory metadata. |
A 'NeuroarchiveHandoffContract'.
Extract the offset vector from a latent space representation. For
LatentNeuroVec objects, this returns the voxel-wise offset
(mean or intercept) that is added after the basis x loadings reconstruction.
## S4 method for signature 'ANY' offset(object, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' offset(object, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' offset(object, ...) ## S4 method for signature 'BlockLatentNeuroVector' offset(object, ...) ## S4 method for signature 'LatentNeuroVec' offset(object, ...)## S4 method for signature 'ANY' offset(object, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' offset(object, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' offset(object, ...) ## S4 method for signature 'BlockLatentNeuroVector' offset(object, ...) ## S4 method for signature 'LatentNeuroVec' offset(object, ...)
object |
An object containing an offset (e.g., |
... |
Additional arguments for methods. The generic keeps the
|
The offset vector (length = number of voxels in mask)
mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) off_vector <- offset(lvec) length(off_vector)mask <- neuroim2::LogicalNeuroVol( array(TRUE, dim = c(2, 2, 1)), neuroim2::NeuroSpace(c(2, 2, 1)) ) lvec <- LatentNeuroVec( basis = matrix(1:6, nrow = 3), loadings = matrix(seq_len(8) / 10, nrow = 4), space = neuroim2::NeuroSpace(c(2, 2, 1, 3)), mask = mask, expect_dense = TRUE ) off_vector <- offset(lvec) length(off_vector)
Computes a spatial dictionary within each parcel using lift()
and caches the Gram factorization for efficient projection. The resulting
template can be reused across subjects via spec_space_parcel().
parcel_basis_template( parcellation, basis_spec = basis_slepian(k = 5), data = NULL, center = TRUE, ridge = 1e-08, ... )parcel_basis_template( parcellation, basis_spec = basis_slepian(k = 5), data = NULL, center = TRUE, ridge = 1e-08, ... )
parcellation |
A |
basis_spec |
A basis specification for |
data |
Optional numeric matrix (time x voxels, mask order). Required
for data-driven specs like |
center |
Logical; if |
ridge |
Small positive scalar added to the Gram diagonal if Cholesky fails (default 1e-8). |
... |
Additional arguments passed to |
The default basis_slepian(k) computes the k smallest eigenvectors
of the graph Laplacian built from voxel coordinates within each parcel.
These smooth spatial functions form a data-independent dictionary suitable
for projecting any subject's data.
For data-driven bases, pass basis_pca(k) with data = a
training matrix (e.g., group-average data). The resulting PCA loadings
are then fixed and reused for each subject.
A "ParcelBasisTemplate" object (S3) with components:
Sparse Matrix (voxels x atoms), block-diagonal by parcel.
Cached Cholesky factorization of .
ClusterReduction used.
The spec that produced the loadings.
Whether centering is applied when building/projecting.
List with family, k, ridge,
label_map, and cluster_map.
spec_space_parcel, as_cluster_reduction,
lift, basis_slepian, basis_pca
## Not run: # Geometric (Laplacian) basis -- no training data needed atlas <- load_atlas("schaefer_400") tmpl <- parcel_basis_template(atlas, basis_slepian(k = 8)) lvec <- encode(bold, spec_space_parcel(tmpl)) # Data-driven shared PCA basis tmpl_pca <- parcel_basis_template(atlas, basis_pca(k = 5), data = group_bold) lvec <- encode(subj_bold, spec_space_parcel(tmpl_pca)) ## End(Not run)## Not run: # Geometric (Laplacian) basis -- no training data needed atlas <- load_atlas("schaefer_400") tmpl <- parcel_basis_template(atlas, basis_slepian(k = 8)) lvec <- encode(bold, spec_space_parcel(tmpl)) # Data-driven shared PCA basis tmpl_pca <- parcel_basis_template(atlas, basis_pca(k = 5), data = group_bold) lvec <- encode(subj_bold, spec_space_parcel(tmpl_pca)) ## End(Not run)
Combines geometric and functional priors into a parcel–parcel similarity matrix W used to cluster Schaefer parcels into coarser levels. Real data glue: - 'boundary_contact': from surface meshes (fsaverage), compute fraction of shared boundary between parcels. - 'geo_dist': geodesic distance between parcel centroids on the surface (fallback: Euclidean in MNI). - 'yeo17': network labels from the Schaefer/Yeo annotation (hemisphere-specific).
parcel_similarity_matrix( boundary_contact, geo_dist, yeo17, alpha = 0.5, beta = 0.3, gamma = 0.2, d0 = 30 )parcel_similarity_matrix( boundary_contact, geo_dist, yeo17, alpha = 0.5, beta = 0.3, gamma = 0.2, d0 = 30 )
boundary_contact |
Numeric matrix [n_parc x n_parc], symmetric, contact fraction (0..1). |
geo_dist |
Numeric matrix [n_parc x n_parc], symmetric geodesic distances (mm). |
yeo17 |
Integer or factor vector of length n_parc with Yeo17 network labels. |
alpha |
Weight for boundary contact (default 0.5). |
beta |
Weight for geodesic kernel (default 0.3). |
gamma |
Weight for Yeo17 agreement (default 0.2). |
d0 |
Scale for geodesic exponential (default 30 mm). |
Similarity matrix W (symmetric, zero diagonal).
Derive parent maps for a nested set of parcellations
parent_maps_from_levels(levels)parent_maps_from_levels(levels)
levels |
List of integer label vectors (all same length), coarse to fine or fine to coarse; order agnostic. |
List of integer named vectors: parents[[lvl]] maps child ids (names) at level lvl to parent ids at lvl-1; parents[[1]] is integer(0).
Plot Gram matrix of a basis (orthogonality check)
plot_basis_gram(basis)plot_basis_gram(basis)
basis |
Matrix or BasisHandle. |
ggplot heatmap (if ggplot2 available); otherwise shows base image.
Plot benchmark results
plot_benchmark_roundtrip(df)plot_benchmark_roundtrip(df)
df |
Data frame from benchmark_roundtrip. |
ggplot object if ggplot2 available; otherwise prints df.
Plot temporal Slepians (DPSS)
plot_slepian_temporal(basis, max_components = 6L)plot_slepian_temporal(basis, max_components = 6L)
basis |
Matrix (time x k) or BasisHandle (kind = "slepian_temporal"). |
max_components |
Maximum components to display (default 6). |
A ggplot object (if ggplot2 available); otherwise invisibly plots with base graphics.
Plot a spatial atom (loading vector) on a mask
plot_spatial_atom(loadings, mask, idx = 1L, main = NULL)plot_spatial_atom(loadings, mask, idx = 1L, main = NULL)
loadings |
Matrix (voxels x k) or LoadingsHandle. |
mask |
LogicalNeuroVol or logical array defining voxel order. |
idx |
Component index (1-based). |
main |
Optional title. |
Invisibly, the 3D array plotted.
The portable linear map is the seam 'fmrilatent' uses to consume subject
field operators from neurofunctor (or any other producer) without pulling
in file-format-specific warp code. A portable linear map represents a
single linear operator together with enough metadata to compose,
adjoint, and (optionally) materialize it.
An object satisfies the contract if it is either
a base matrix or Matrix::Matrix, or
a list with the following fields:
n_source, n_target
Positive integer scalar dimensions of the source and target sample vectors.
forward(x, ...)Function applying the operator to
source-space data. Accepts a vector of length n_source or a
matrix with n_source rows; returns a vector/matrix with
n_target rows.
adjoint_apply(y, ...) (alias adjoint)Function applying the discrete adjoint (or a declared alternative) to target-space data.
source_domain_id, target_domain_id
Stable
character identifiers for the source and target domains. Used for
composition safety and provenance digests. .compose_linear_maps()
requires matching domain ids across the junction unless at least one
side is an empty string ("unspecified").
source_support, target_support
Optional
descriptors of the sample layout on each side (for example a
LogicalNeuroVol, a 3D logical mask, surface vertex indices, or
a vector of sample ids). When present these let fmrilatent
reconstruct domain-aware outputs; when absent it falls back to
provenance$target_support / provenance$target_mask.
adjoint_conventionCharacter tag identifying the
adjoint convention. Defaults to "euclidean_discrete" (the
discrete transpose under the standard Euclidean inner product).
Covariance pushforward paths such as decode_covariance() and
.project_covariance_diag() currently require this value;
operators using another convention must be re-normalized before
being handed to the pushforward code.
provenanceOptional named list of provenance metadata.
fmrilatent interprets a small set of reserved keys:
target_mask, target_support, target_domain
Legacy fallback locations read by
.resolve_transport_target_support() when the top-level
fields are absent. New producers should set the top-level
fields instead.
source_supportLegacy fallback for the top-level field of the same name.
coordinatesAppended with value "raw" when
the map has been wrapped with
.transform_linear_map_coordinates().
All other keys are advisory and carried through composition verbatim. Producers should prefer top-level fields over provenance entries for anything fmrilatent actually reads.
materialize(...) (optional)Returns the dense
n_target x n_source matrix representation. Used only when a
caller explicitly asks for it; the main encode and decode paths are
matrix-free and only call forward/adjoint_apply.
contract_versionInteger scalar identifying the
contract revision. Auto-filled by as_portable_linear_map()
to 1L in this release. Future revisions will bump this tag
so producers and consumers can negotiate compatibility.
Producer-form vs canonical form on TransportLatent.
transport_latent() records the raw producer object at
x$field_operator (and its legacy alias x$observation_operator)
as a back-reference for debugging and round-trip. The canonical
portable-linear-map representation used internally by all encode/decode
math is at x$transport$field_operator. Consumers that need to
introspect the operator should always read the canonical form.
Producers (such as neurofunctor::compile_observation_operator) can
return either a bare callback list or a wrapped object. Call
as_portable_linear_map() to coerce any accepted input to the
canonical contract and validate_portable_linear_map() to verify
that an input already satisfies it without coercing.
Predict from a BOLDZip-SR codec payload
## S3 method for class 'BoldZipSR' predict(object, time_idx = NULL, roi = NULL, ...)## S3 method for class 'BoldZipSR' predict(object, time_idx = NULL, roi = NULL, ...)
object |
A 'BoldZipSR' object. |
time_idx |
Optional integer time indices to return. |
roi |
Optional integer or logical row subset to return. |
... |
Additional arguments passed to [boldzip_sr_decode()]. |
Reconstructed matrix with rows as voxels/grayordinates and columns as time points.
Predict method for HaarLatent
## S3 method for class 'HaarLatent' predict(object, roi_mask = NULL, time_idx = NULL, levels_keep = NULL, ...)## S3 method for class 'HaarLatent' predict(object, roi_mask = NULL, time_idx = NULL, levels_keep = NULL, ...)
object |
HaarLatent object |
roi_mask |
Optional ROI mask |
time_idx |
Optional time indices |
levels_keep |
Optional levels to keep |
... |
Additional arguments passed to decoder |
Matrix of predicted values
Predict method for ImplicitLatent
## S3 method for class 'ImplicitLatent' predict(object, roi_mask = NULL, time_idx = NULL, levels_keep = NULL, ...)## S3 method for class 'ImplicitLatent' predict(object, roi_mask = NULL, time_idx = NULL, levels_keep = NULL, ...)
object |
ImplicitLatent object |
roi_mask |
Optional ROI mask |
time_idx |
Optional time indices |
levels_keep |
Optional levels to keep |
... |
Additional arguments (unused) |
Matrix of predicted values
Print method for ParcelBasisTemplate
## S3 method for class 'ParcelBasisTemplate' print(x, ...)## S3 method for class 'ParcelBasisTemplate' print(x, ...)
x |
A ParcelBasisTemplate object. |
... |
Ignored. |
The input 'x', invisibly.
Print method for SurfaceBasisTemplate
## S3 method for class 'SurfaceBasisTemplate' print(x, ...)## S3 method for class 'SurfaceBasisTemplate' print(x, ...)
x |
A |
... |
Ignored. |
The input 'x', invisibly.
Compatibility wrapper for decoder-based coefficient projection
project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'ImplicitLatent' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'LatentNeuroVec' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'BlockLatentNeuroVector' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... )project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'ImplicitLatent' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'LatentNeuroVec' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... ) ## S4 method for signature 'BlockLatentNeuroVector' project_effect( x, gamma, space = c("native", "template"), coordinates = c("analysis", "raw"), ... )
x |
A latent object. |
gamma |
Coefficient-space vector or matrix. |
space |
Output space to decode into. |
coordinates |
Coordinate system used by |
... |
Additional arguments passed to methods. |
Numeric vector or matrix in the requested output space.
Project coefficients only (no LatentNeuroVec wrapper)
project_hierarchical(template, X)project_hierarchical(template, X)
template |
HierarchicalBasisTemplate to use for projection |
X |
matrix time x voxels (mask order) matching template mask |
Matrix of coefficients (time x atoms)
Compatibility wrapper for decoder-based covariance pushforward
project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'ImplicitLatent' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'LatentNeuroVec' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'BlockLatentNeuroVector' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... )project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'ImplicitLatent' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'LatentNeuroSurfaceVector' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'LatentNeuroVec' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... ) ## S4 method for signature 'BlockLatentNeuroVector' project_vcov( x, Sigma, space = c("native", "template"), coordinates = c("analysis", "raw"), diag_only = TRUE, ... )
x |
A latent object. |
Sigma |
Coefficient covariance matrix. |
space |
Output space to decode into. |
coordinates |
Coordinate system used by |
diag_only |
Logical; if |
... |
Additional arguments passed to methods. |
Numeric vector or matrix in the requested output space.
Reconstructs a latent object into a 4D array over its spatial support.
reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'ImplicitLatent' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'BlockLatentNeuroVector' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'LatentNeuroVec' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...)reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'ImplicitLatent' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'BlockLatentNeuroVector' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'LatentNeuroVec' reconstruct_array(x, time_idx = NULL, roi_mask = NULL, ...)
x |
A latent object. |
time_idx |
Optional integer time indices to keep. |
roi_mask |
Optional logical ROI mask; voxels outside the ROI are zero. |
... |
Additional arguments passed to methods. |
Numeric 4D array.
Provides a common reconstruction interface for both explicit
LatentNeuroVec objects and implicit decoder-backed latent objects.
reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'ImplicitLatent' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'BlockLatentNeuroVector' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'LatentNeuroVec' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...)reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'ImplicitLatent' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'LatentNeuroSurfaceVector' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'BlockLatentNeuroVector' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...) ## S4 method for signature 'LatentNeuroVec' reconstruct_matrix(x, time_idx = NULL, roi_mask = NULL, ...)
x |
A latent object. |
time_idx |
Optional integer time indices to keep. |
roi_mask |
Optional logical ROI mask for spatial subsetting. |
... |
Additional arguments passed to methods. |
Numeric matrix with rows = time and columns = voxels within the requested mask support.
Registers a spec constructor so it can be discovered via list_encoders
and retrieved via get_encoder.
register_encoder(family, spec_fn, description = "", package = "")register_encoder(family, spec_fn, description = "", package = "")
family |
Character string identifying the encoder family (e.g. "time_slepian"). |
spec_fn |
The spec constructor function (e.g. |
description |
Character string describing the encoder. |
package |
Character string naming the package that provides this encoder. |
External packages typically register their encoders in their .onLoad
hook so the registry is populated when the package is loaded:
.onLoad <- function(libname, pkgname) {
if (requireNamespace("fmrilatent", quietly = TRUE)) {
fmrilatent::register_encoder(
"my_encoder", spec_my_encoder,
description = "My custom encoder",
package = pkgname
)
}
}
The S3 method itself is exported via the package's NAMESPACE in the usual
way (S3method(encode_spec, spec_my_encoder)).
Registering the same family twice issues a warning and overwrites the previous entry.
Invisibly, TRUE.
The registry is for discovery and introspection only. It does
not participate in actual encoding. encode routes work
through the S3 generic encode_spec, which dispatches on the class of
the spec object. That means an external package contributing a new encoder
family must do both:
Define a spec constructor whose return value carries a distinctive
class (e.g. class(spec) <- c("spec_my_encoder", "list")).
Define an S3 method encode_spec.spec_my_encoder(x, spec, ...)
that builds the actual LatentNeuroVec (or other latent type).
Optionally call register_encoder() so that
list_encoders() surfaces the family for users.
Calling register_encoder() alone is not enough: without an
encode_spec.spec_* method, encode() will fall through to
encode_spec.default and raise an error.
Transport-backed AWPT is an intentional parallel API, not a registry-dispatch
family. basis_awpt_wavelet() describes a shared template basis, while
subject fitting also needs a template/basis asset plus subject field or
observation operators. Use encode_awpt or
encode_operator for those fits; do not expect
register_encoder() or encode() to route AWPT subject encoding.
encode, list_encoders, get_encoder
register_encoder("test_enc", identity, "A test encoder", "mypkg") list_encoders() get_encoder("test_enc")register_encoder("test_enc", identity, "A test encoder", "mypkg") list_encoders() get_encoder("test_enc")
Register a lazy handle materializer
register_handle_kind(kind, materializer, type = c("basis", "loadings"))register_handle_kind(kind, materializer, type = c("basis", "loadings"))
kind |
Character scalar handle kind. |
materializer |
Function that accepts a handle and returns a matrix-like object. |
type |
Registry to update: |
Invisibly, the registered kind.
Extracts columns from a reconstruction matrix that correspond to voxels inside an ROI mask. This is a shared utility used by decoder functions to handle ROI subsetting consistently.
roi_subset_columns(rec_mat, mask_arr, roi_mask = NULL)roi_subset_columns(rec_mat, mask_arr, roi_mask = NULL)
rec_mat |
Numeric matrix (time x voxels-in-mask) to subset. |
mask_arr |
Logical array (the full brain mask). |
roi_mask |
Logical array (the ROI mask), or |
The subsetted matrix, or rec_mat unchanged when
roi_mask is NULL.
mask <- array(c(TRUE, TRUE, FALSE, TRUE), dim = c(2, 2, 1)) rec <- matrix(1:9, nrow = 3, ncol = 3) # 3 time x 3 masked voxels roi <- array(c(TRUE, FALSE, FALSE, TRUE), dim = c(2, 2, 1)) roi_subset_columns(rec, mask, roi) # keeps columns 1 and 3mask <- array(c(TRUE, TRUE, FALSE, TRUE), dim = c(2, 2, 1)) rec <- matrix(1:9, nrow = 3, ncol = 3) # 3 time x 3 masked voxels roi <- array(c(TRUE, FALSE, FALSE, TRUE), dim = c(2, 2, 1)) roi_subset_columns(rec, mask, roi) # keeps columns 1 and 3
Save a hierarchical template to disk
save_hierarchical_template(template, file, compress = "xz")save_hierarchical_template(template, file, compress = "xz")
template |
HierarchicalBasisTemplate |
file |
Path to .rds file |
compress |
Compression passed to saveRDS (default "xz") |
The path in 'file', invisibly.
Save a template object to disk
save_template(template, file, compress = "xz", ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' save_template(template, file, compress = "xz", ...) ## S4 method for signature 'AWPTBasisTemplate' save_template(template, file, compress = "xz", ...) ## S4 method for signature 'HierarchicalBasisTemplate' save_template(template, file, compress = "xz", ...) ## S4 method for signature 'ParcelBasisTemplate' save_template(template, file, compress = "xz", ...) ## S4 method for signature 'SurfaceBasisTemplate' save_template(template, file, compress = "xz", ...)save_template(template, file, compress = "xz", ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' save_template(template, file, compress = "xz", ...) ## S4 method for signature 'AWPTBasisTemplate' save_template(template, file, compress = "xz", ...) ## S4 method for signature 'HierarchicalBasisTemplate' save_template(template, file, compress = "xz", ...) ## S4 method for signature 'ParcelBasisTemplate' save_template(template, file, compress = "xz", ...) ## S4 method for signature 'SurfaceBasisTemplate' save_template(template, file, compress = "xz", ...)
template |
A template object. |
file |
Output path. |
compress |
Compression passed to |
... |
Additional arguments passed to methods. |
Normalized output path, invisibly.
Extract time series data from a LatentNeuroVec. Reconstructs
values on-the-fly from the basis and loadings factorization.
Extract time series data from a LatentNeuroVec at specified
spatial coordinates or voxel indices.
## S4 method for signature 'LatentNeuroVec,integer' series(x, i, j, k, ..., drop = TRUE) ## S4 method for signature 'LatentNeuroVec,numeric' series(x, i, j, k, ..., drop = TRUE) ## S4 method for signature 'LatentNeuroVec,ANY' series(x, i, j, k, ..., drop = TRUE)## S4 method for signature 'LatentNeuroVec,integer' series(x, i, j, k, ..., drop = TRUE) ## S4 method for signature 'LatentNeuroVec,numeric' series(x, i, j, k, ..., drop = TRUE) ## S4 method for signature 'LatentNeuroVec,ANY' series(x, i, j, k, ..., drop = TRUE)
x |
A |
i, j, k
|
Spatial indices (x, y, z coordinates) |
... |
Additional arguments passed to methods |
drop |
Logical; drop dimensions of length 1 (default TRUE) |
Matrix or vector of time series values
A matrix or vector of time series values
Print a summary of a LatentNeuroVec object including dimensions,
component count, memory usage, and sparsity information.
Print a formatted summary of a LatentNeuroVec object showing
dimensions, components, memory usage, and other relevant information.
## S4 method for signature 'LatentNeuroSurfaceVector' show(object) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' show(object) ## S4 method for signature 'BlockLatentNeuroVector' show(object) ## S4 method for signature 'LatentNeuroVec' show(object)## S4 method for signature 'LatentNeuroSurfaceVector' show(object) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' show(object) ## S4 method for signature 'BlockLatentNeuroVector' show(object) ## S4 method for signature 'LatentNeuroVec' show(object)
object |
A |
Called for side effect (printing). Returns NULL invisibly.
Invisibly returns NULL; called for side effect of printing
Slepian spatial latent constructor (explicit basis)
slepian_spatial_latent( X, mask, reduction = NULL, spec = basis_slepian(), k_neighbors = 6L, label = "" )slepian_spatial_latent( X, mask, reduction = NULL, spec = basis_slepian(), k_neighbors = 6L, label = "" )
X |
Matrix time x voxels (mask order). |
mask |
LogicalNeuroVol or 3D logical array. |
reduction |
ClusterReduction; if NULL, defaults to one cluster per voxel. |
spec |
Slepian basis spec (basis_slepian()). |
k_neighbors |
k for local graph building. |
label |
Optional label. |
A 'LatentNeuroVec' object.
Create a LoadingsHandle for spatial Slepians (graph Laplacian)
slepian_spatial_loadings_handle( reduction, basis_spec = basis_slepian(), data = NULL, k_neighbors = 6L, id = NULL, label = "slepian-spatial" )slepian_spatial_loadings_handle( reduction, basis_spec = basis_slepian(), data = NULL, k_neighbors = 6L, id = NULL, label = "slepian-spatial" )
reduction |
Graph reduction (e.g., ClusterReduction). |
basis_spec |
Slepian basis spec (from 'basis_slepian()'). |
data |
Optional data passed to 'lift()' (if needed). |
k_neighbors |
Number of neighbors used for local graph construction when materializing the lifted basis. |
id |
Optional registry id; generated if NULL. |
label |
Optional label. |
This constructor lifts the spatial dictionary eagerly so the returned handle records the realized dimensions and registers a fingerprinted cache entry. Repeated constructor calls may therefore recompute the lift even when later 'loadings_mat()' calls can reuse the registry cache.
A LoadingsHandle.
Spatiotemporal Slepian latent (implicit, separable)
slepian_spatiotemporal_latent( X, mask, tr, bandwidth = 0.1, k_time = NULL, reduction = NULL, k_space = 3L, k_neighbors = 6L, label = "" )slepian_spatiotemporal_latent( X, mask, tr, bandwidth = 0.1, k_time = NULL, reduction = NULL, k_space = 3L, k_neighbors = 6L, label = "" )
X |
Numeric matrix time x voxels (mask order). |
mask |
LogicalNeuroVol or 3D logical array. |
tr |
Repetition time (seconds). |
bandwidth |
Half-bandwidth in Hz for temporal Slepians (default 0.1). |
k_time |
Number of temporal Slepians; if NULL uses floor(2*NW)-1. |
reduction |
ClusterReduction for spatial graph; if NULL, one cluster per voxel. |
k_space |
Number of spatial Slepians per cluster (default 3). |
k_neighbors |
k-NN for spatial graph (default 6). |
label |
Optional label. |
An 'ImplicitLatent' with decoder using separable Slepians.
Create a BasisHandle for temporal Slepians (DPSS)
slepian_temporal_handle( n_time, tr, bandwidth = 0.1, k = NULL, backend = c("tridiag", "dense"), id = NULL, label = NULL )slepian_temporal_handle( n_time, tr, bandwidth = 0.1, k = NULL, backend = c("tridiag", "dense"), id = NULL, label = NULL )
n_time |
Integer number of time points. |
tr |
Repetition time (seconds). |
bandwidth |
Half-bandwidth in Hz (default 0.1). |
k |
Optional number of tapers/components. |
backend |
Backend passed to 'dpss_time_basis'; only "tridiag" is currently supported. |
id |
Optional registry key (generated if NULL). |
label |
Optional human-readable label. |
A BasisHandle.
LatentNeuroVec using a temporal DPSS basis
slepian_temporal_latent( X, mask, tr, bandwidth = 0.1, k = NULL, denoise = TRUE, backend = c("tridiag", "dense"), label = "" )slepian_temporal_latent( X, mask, tr, bandwidth = 0.1, k = NULL, denoise = TRUE, backend = c("tridiag", "dense"), label = "" )
X |
Numeric matrix (time x voxels within mask). |
mask |
'LogicalNeuroVol'. |
tr |
Repetition time in seconds. |
bandwidth |
Half-bandwidth in Hz (default 0.1). |
k |
Optional number of tapers; see 'dpss_time_basis'. |
denoise |
If TRUE, truncate to 'floor(2 * NW) - 1' (Shannon number). |
backend |
DPSS computation backend passed to 'dpss_time_basis'; only
|
label |
Optional character label. |
'LatentNeuroVec' with DPSS temporal basis and voxel loadings.
Create hierarchical template spec
spec_hierarchical_template(template = NULL, template_file = NULL)spec_hierarchical_template(template = NULL, template_file = NULL)
template |
HierarchicalBasisTemplate object |
template_file |
Path to saved template file |
Spec object of class spec_hierarchical
Spatial heat-wavelet spec (graph diffusion)
spec_space_heat( scales = c(1, 2, 4, 8), order = 30L, threshold = NULL, k_neighbors = 6L, sparsify_eps = NULL )spec_space_heat( scales = c(1, 2, 4, 8), order = 30L, threshold = NULL, k_neighbors = 6L, sparsify_eps = NULL )
scales |
Heat scales. |
order |
Polynomial order. |
threshold |
Deprecated alias for 'sparsify_eps'. |
k_neighbors |
k-NN graph parameter. |
sparsify_eps |
Non-negative threshold for small heat-wavelet coefficients. This is stored as 'threshold' for compatibility. |
A 'spec_space_heat' object.
Spatial HRBF spec
spec_space_hrbf( params = list(), sigma0 = NULL, levels = NULL, radius_factor = NULL, num_extra_fine_levels = NULL, kernel_type = NULL, kernel_type_fine_levels = NULL, seed = NULL, ... )spec_space_hrbf( params = list(), sigma0 = NULL, levels = NULL, radius_factor = NULL, num_extra_fine_levels = NULL, kernel_type = NULL, kernel_type_fine_levels = NULL, seed = NULL, ... )
params |
Optional named list for advanced or compatibility HRBF parameters. Explicit formals override entries with the same names. |
sigma0 |
Base kernel width. 'NULL' uses the HRBF default ('6'). |
levels |
Number of dyadic resolution levels. 'NULL' uses the HRBF default ('3L'). |
radius_factor |
Atom support radius as a multiple of level width. 'NULL' uses the HRBF default ('2.5'). |
num_extra_fine_levels |
Optional extra fine levels. 'NULL' uses the HRBF default ('0L'). |
kernel_type |
Radial kernel family. 'NULL' uses '"gaussian"'. |
kernel_type_fine_levels |
Kernel family for extra fine levels. 'NULL' uses the HRBF default. |
seed |
Random seed. 'NULL' uses the HRBF default ('1L'). |
... |
Additional named HRBF parameters for advanced use. |
A 'spec_space_hrbf' object.
Creates a spec for projecting data onto a pre-built
"ParcelBasisTemplate". The loadings are fixed (shared across
subjects); only the temporal scores and per-subject offset vary.
spec_space_parcel(template)spec_space_parcel(template)
template |
A |
A spec_space_parcel object for encode().
## Not run: tmpl <- parcel_basis_template(atlas, basis_slepian(k = 8)) lvec_s1 <- encode(bold_s1, spec_space_parcel(tmpl)) lvec_s2 <- encode(bold_s2, spec_space_parcel(tmpl)) # Same loadings; different basis (scores) and offset ## End(Not run)## Not run: tmpl <- parcel_basis_template(atlas, basis_slepian(k = 8)) lvec_s1 <- encode(bold_s1, spec_space_parcel(tmpl)) lvec_s2 <- encode(bold_s2, spec_space_parcel(tmpl)) # Same loadings; different basis (scores) and offset ## End(Not run)
Computes PCA eigenvectors within each cluster/parcel specified by a 'ClusterReduction' and returns a block-sparse spatial dictionary.
spec_space_pca( k = NULL, center = TRUE, whiten = FALSE, backend = c("auto", "svds", "svd"), scale = FALSE )spec_space_pca( k = NULL, center = TRUE, whiten = FALSE, backend = c("auto", "svds", "svd"), scale = FALSE )
k |
Optional components per cluster. If 'NULL', encoders use their family default ('3L'). |
center |
Logical; center voxels before PCA (default TRUE). When TRUE, voxel means are stored in 'LatentNeuroVec@offset'. |
whiten |
Logical; if TRUE, return whitened scores (unit-variance) and rescaled loadings such that reconstruction is unchanged. |
backend |
SVD backend: "auto" (default), "svds" (RSpectra), or "svd" (base). |
scale |
Logical; scale voxels before PCA (default FALSE). Passed through to 'lift(ClusterReduction, spec_pca)'. |
A 'spec_space_pca' object.
Spatial Slepian spec
spec_space_slepian(k = NULL, k_neighbors = 6L)spec_space_slepian(k = NULL, k_neighbors = 6L)
k |
Optional components per cluster. If 'NULL', encoders use their family default ('3L'). |
k_neighbors |
k-NN graph parameter. |
A 'spec_space_slepian' object.
Spatial wavelet (active pencil) spec
spec_space_wavelet_active( levels_space = 2L, levels_time = 0L, select_threshold = NULL, threshold = NULL )spec_space_wavelet_active( levels_space = 2L, levels_time = 0L, select_threshold = NULL, threshold = NULL )
levels_space |
Spatial lifting levels. |
levels_time |
Optional time lifting levels. |
select_threshold |
Non-negative active-set coefficient threshold after the spatial transform. This is stored as 'threshold' for compatibility. |
threshold |
Deprecated alias for 'select_threshold'. |
A 'spec_space_wavelet_active' object.
Spatiotemporal spec (separable)
spec_st(time, space, core_mode = c("auto", "explicit"))spec_st(time, space, core_mode = c("auto", "explicit"))
time |
Temporal spec ('spec_time_*'). |
space |
Spatial spec ('spec_space_*'). |
core_mode |
Controls the returned representation. '"auto"' (the default) always returns an 'ImplicitLatent' (decoder-only separable form). '"explicit"' returns an explicit [LatentNeuroVec] (the separable 'basis materializable, which holds for every currently supported 'spec_st' combination; if the factors are not both materializable it falls back to 'ImplicitLatent' with a 'fmrilatent_warning_explicit_core_unavailable' warning. The reconstruction is identical either way. |
A 'spec_st' object.
Temporal B-spline spec
spec_time_bspline( k = NULL, degree = 3L, include_intercept = FALSE, orthonormalize = TRUE )spec_time_bspline( k = NULL, degree = 3L, include_intercept = FALSE, orthonormalize = TRUE )
k |
Optional number of components (df). If 'NULL', the encoder uses 'min(5, n_time)' at encode time. |
degree |
Spline degree (default 3). |
include_intercept |
Logical include intercept. |
orthonormalize |
Logical orthonormalize columns (default TRUE). |
A 'spec_time_bspline' object.
Temporal DCT spec
spec_time_dct(k = NULL, norm = c("ortho", "none"))spec_time_dct(k = NULL, norm = c("ortho", "none"))
k |
Optional number of components. If 'NULL', the encoder uses all available DCT columns ('k = n_time') at encode time. |
norm |
Normalization ("ortho" or "none"). |
A 'spec_time_dct' object.
Temporal Slepian/DPSS spec
spec_time_slepian( tr, bandwidth = 0.1, k = NULL, backend = c("tridiag", "dense") )spec_time_slepian( tr, bandwidth = 0.1, k = NULL, backend = c("tridiag", "dense") )
tr |
Repetition time (seconds). |
bandwidth |
Half-bandwidth in Hz (default 0.1). |
k |
Optional number of components (default floor(2*NW)-1). |
backend |
Backend to use. Only "tridiag" is currently supported. |
A 'spec_time_slepian' object for 'encode()' / 'spec_st()'.
Produces an hclust over parcels using a spectral embedding of the similarity matrix, then Ward linkage. Real data glue: supply W from 'parcel_similarity_matrix()', 'hemi' from parcel hemisphere labels, and 'network' from Yeo17 labels. Penalties bias merges to stay within hemisphere/network until higher in the tree.
spectral_ward_hclust(W, k_embed = 3, hemi = NULL, network = NULL)spectral_ward_hclust(W, k_embed = 3, hemi = NULL, network = NULL)
W |
Similarity matrix (symmetric). |
k_embed |
Embedding dimension (2 or 3). |
hemi |
Optional factor/character vector (n_parc) to enforce within-hemisphere merges first. |
network |
Optional factor/character vector (n_parc) (e.g., Yeo17) to enforce within-network merges until relaxed. |
hclust object.
Build a shared surface basis template
surface_basis_template( geometry, loadings, support = NULL, roughness = NULL, measure = NULL, ridge = 1e-08, label = "surface_basis", meta = list() )surface_basis_template( geometry, loadings, support = NULL, roughness = NULL, measure = NULL, ridge = 1e-08, label = "surface_basis", meta = list() )
geometry |
A |
loadings |
A matrix-like decoder basis with rows aligned to |
support |
Surface support as vertex indices or a logical vector over all surface nodes. Defaults to the full surface. |
roughness |
Optional coefficient-space roughness matrix. |
measure |
Optional support-aligned weighting or mass information. |
ridge |
Small diagonal ridge added to the Gram matrix if needed. |
label |
Optional label stored in metadata. |
meta |
Optional additional metadata. |
A SurfaceBasisTemplate object.
Extract the domain associated with a template
template_domain(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_domain(template, ...) ## S4 method for signature 'AWPTBasisTemplate' template_domain(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_domain(template, ...) ## S4 method for signature 'ParcelBasisTemplate' template_domain(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_domain(template, ...)template_domain(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_domain(template, ...) ## S4 method for signature 'AWPTBasisTemplate' template_domain(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_domain(template, ...) ## S4 method for signature 'ParcelBasisTemplate' template_domain(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_domain(template, ...)
template |
A template object. |
... |
Additional arguments passed to methods. |
Domain object or identifier.
Extract template loadings
template_loadings(x, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_loadings(x, ...) ## S4 method for signature 'AWPTBasisTemplate' template_loadings(x, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_loadings(x, ...) ## S4 method for signature 'ParcelBasisTemplate' template_loadings(x, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_loadings(x, ...)template_loadings(x, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_loadings(x, ...) ## S4 method for signature 'AWPTBasisTemplate' template_loadings(x, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_loadings(x, ...) ## S4 method for signature 'ParcelBasisTemplate' template_loadings(x, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_loadings(x, ...)
x |
A template object. |
... |
Additional arguments (unused). |
Spatial loadings matrix stored by the template.
Extract template mask
template_mask(x, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_mask(x, ...) ## S4 method for signature 'AWPTBasisTemplate' template_mask(x, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_mask(x, ...) ## S4 method for signature 'ParcelBasisTemplate' template_mask(x, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_mask(x, ...)template_mask(x, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_mask(x, ...) ## S4 method for signature 'AWPTBasisTemplate' template_mask(x, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_mask(x, ...) ## S4 method for signature 'ParcelBasisTemplate' template_mask(x, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_mask(x, ...)
x |
A template object. |
... |
Additional arguments (unused). |
Mask associated with the template.
Extract optional measure or mass information for a template
template_measure(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_measure(template, ...) ## S4 method for signature 'AWPTBasisTemplate' template_measure(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_measure(template, ...) ## S4 method for signature 'ParcelBasisTemplate' template_measure(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_measure(template, ...)template_measure(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_measure(template, ...) ## S4 method for signature 'AWPTBasisTemplate' template_measure(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_measure(template, ...) ## S4 method for signature 'ParcelBasisTemplate' template_measure(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_measure(template, ...)
template |
A template object. |
... |
Additional arguments passed to methods. |
Optional measure or mass object, or NULL.
Extract template metadata
template_meta(x, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_meta(x, ...) ## S4 method for signature 'AWPTBasisTemplate' template_meta(x, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_meta(x, ...) ## S4 method for signature 'ParcelBasisTemplate' template_meta(x, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_meta(x, ...)template_meta(x, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_meta(x, ...) ## S4 method for signature 'AWPTBasisTemplate' template_meta(x, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_meta(x, ...) ## S4 method for signature 'ParcelBasisTemplate' template_meta(x, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_meta(x, ...)
x |
A template object. |
... |
Additional arguments (unused). |
Metadata list.
Project data onto a template
template_project(x, data, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_project(x, data, ...) ## S4 method for signature 'AWPTBasisTemplate' template_project(x, data, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_project(x, data, ...) ## S4 method for signature 'ParcelBasisTemplate' template_project(x, data, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_project(x, data, ...)template_project(x, data, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_project(x, data, ...) ## S4 method for signature 'AWPTBasisTemplate' template_project(x, data, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_project(x, data, ...) ## S4 method for signature 'ParcelBasisTemplate' template_project(x, data, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_project(x, data, ...)
x |
A template object. |
data |
Numeric matrix (time x voxels in mask order). |
... |
Additional arguments passed to methods. |
A list with coefficients (time x atoms/components) and
offset (voxel means or numeric(0)).
Query the rank of a template basis
template_rank(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_rank(template, ...) ## S4 method for signature 'AWPTBasisTemplate' template_rank(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_rank(template, ...) ## S4 method for signature 'ParcelBasisTemplate' template_rank(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_rank(template, ...)template_rank(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_rank(template, ...) ## S4 method for signature 'AWPTBasisTemplate' template_rank(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_rank(template, ...) ## S4 method for signature 'ParcelBasisTemplate' template_rank(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_rank(template, ...)
template |
A template object. |
... |
Additional arguments passed to methods. |
Integer scalar rank.
Extract the spatial roughness operator for a template asset
template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'AWPTBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'ParcelBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'SurfaceBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...)template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'AWPTBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'ParcelBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...) ## S4 method for signature 'SurfaceBasisTemplate' template_roughness(template, coordinates = c("analysis", "raw"), ...)
template |
A shared basis asset. |
coordinates |
Coordinate system for the returned roughness operator. |
... |
Additional arguments passed to methods. |
Matrix-like roughness operator or NULL.
Extract the support associated with a template
template_support(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_support(template, ...) ## S4 method for signature 'AWPTBasisTemplate' template_support(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_support(template, ...) ## S4 method for signature 'ParcelBasisTemplate' template_support(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_support(template, ...)template_support(template, ...) ## S4 method for signature 'SurfaceAWPTBasisTemplate' template_support(template, ...) ## S4 method for signature 'AWPTBasisTemplate' template_support(template, ...) ## S4 method for signature 'HierarchicalBasisTemplate' template_support(template, ...) ## S4 method for signature 'ParcelBasisTemplate' template_support(template, ...) ## S4 method for signature 'SurfaceBasisTemplate' template_support(template, ...)
template |
A template object. |
... |
Additional arguments passed to methods. |
Support object describing the decoded support of the template.
Construct a transport-backed implicit latent object
transport_latent( coeff_raw, basis_asset, field_operator = NULL, observation_operator = NULL, mask = NULL, domain = NULL, support = NULL, coeff_analysis = NULL, analysis_transform = NULL, offset = numeric(0), run_info = NULL, meta = list() )transport_latent( coeff_raw, basis_asset, field_operator = NULL, observation_operator = NULL, mask = NULL, domain = NULL, support = NULL, coeff_analysis = NULL, analysis_transform = NULL, offset = numeric(0), run_info = NULL, meta = list() )
coeff_raw |
Raw coefficient matrix (time x k). |
basis_asset |
Shared basis asset. |
field_operator |
Subject field operator satisfying the
contract documented in |
observation_operator |
Legacy alias for |
mask |
Target-domain mask for volumetric reconstruction. |
domain |
Optional target domain for non-volumetric reconstruction. |
support |
Optional target support for non-volumetric reconstruction. |
coeff_analysis |
Optional analysis-coordinate coefficient matrix (time x k). |
analysis_transform |
Optional transform descriptor from raw to analysis coordinates. |
offset |
Optional voxel offset vector in target space. |
run_info |
Optional run metadata. |
meta |
Optional metadata list. |
'transport_latent()' stores the 'fmrilatent' side of the operator-backed
workflow: shared basis asset, subject field operator, raw and
analysis-space coefficients, and decoder views for native or template
projection. It does not fit GLMs or carry statistical summaries. Downstream
model-fitting code should ordinarily consume
coef_time(x, coordinates = "analysis"), then return coefficient-space
effects and covariance matrices for projection with
decode_coefficients() and decode_covariance().
A TransportLatent object inheriting from ImplicitLatent.
Validate that parcellation levels are nested
validate_nested_parcellations(levels)validate_nested_parcellations(levels)
levels |
List of integer label vectors (same length) representing parcellations. |
Invisibly TRUE; stops with an error if nesting fails or lengths differ.
Validate the fmrilatent-to-neuroarchive handoff contract
validate_neuroarchive_handoff_contract(x, error = TRUE)validate_neuroarchive_handoff_contract(x, error = TRUE)
x |
Object to validate. |
error |
If 'TRUE', throw on failure; otherwise return 'FALSE'. |
Invisibly, 'x' on success, or 'FALSE' when 'error = FALSE'.
Returns the normalized canonical form invisibly when x satisfies
the portable_linear_map contract. The canonical return
value lets callers use the result directly rather than paying
normalization a second time via as_portable_linear_map().
Set error = FALSE to receive FALSE on failure instead of
a stop.
validate_portable_linear_map(x, context = "portable linear map", error = TRUE)validate_portable_linear_map(x, context = "portable linear map", error = TRUE)
x |
Object to validate. |
context |
Optional label used in error messages. |
error |
If |
Invisibly: the normalized portable-linear-map list on success,
or FALSE when error = FALSE and validation fails. On
failure with error = TRUE (the default), an error is raised.
portable_linear_map,
as_portable_linear_map.
op <- validate_portable_linear_map(matrix(1:4, 2, 2)) op$n_source op$n_target validate_portable_linear_map(list(forward = function(x) x), error = FALSE)op <- validate_portable_linear_map(matrix(1:4, 2, 2)) op$n_source op$n_target validate_portable_linear_map(list(forward = function(x) x), error = FALSE)
Checks that a template asset exposes the method-neutral surface expected by shared-structure consumers: loadings, rank, support/domain, measure, roughness, decoder, and projection behavior.
validate_template_protocol(template, error = TRUE)validate_template_protocol(template, error = TRUE)
template |
Template object. |
error |
If 'TRUE', throw on failure; otherwise return 'FALSE'. |
Invisibly, a manifest describing the verified protocol.
Convert voxel subset to an rgsp graph
voxel_subset_to_gsp(mask, voxel_indices, k_neighbors = 6L)voxel_subset_to_gsp(mask, voxel_indices, k_neighbors = 6L)
mask |
LogicalNeuroVol or 3D logical array. |
voxel_indices |
Integer vector of voxel indices (mask order). |
k_neighbors |
Number of nearest neighbours for k-NN graph. |
'gsp_graph' object (from rgsp).
Active-pencil wavelet latent (CDF 5/3)
wavelet_active_latent( X, mask, levels_space = 2L, levels_time = 0L, threshold = 0 )wavelet_active_latent( X, mask, levels_space = 2L, levels_time = 0L, threshold = 0 )
X |
Numeric matrix (time x voxels in mask order) or 4D array. |
mask |
LogicalNeuroVol or 3D logical array. |
levels_space |
Integer spatial lifting levels (default 2). |
levels_time |
Integer temporal lifting levels (default 0 = none). |
threshold |
Optional hard threshold after space transform. |
An 'ImplicitLatent' with decoder supporting 'time_idx' and 'roi_mask'.
Wrap flat decoded outputs into a domain-native representation
wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'ImplicitLatent' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'LatentNeuroSurfaceVector' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'BlockLatentNeuroVector' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'LatentNeuroVec' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...)wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'ImplicitLatent' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'LatentNeuroSurfaceVector' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'BilatLatentNeuroSurfaceVector' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'BlockLatentNeuroVector' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...) ## S4 method for signature 'LatentNeuroVec' wrap_decoded(x, values, time_idx = NULL, space = c("native", "template"), ...)
x |
A latent object. |
values |
Flat decoded values, typically as a vector or matrix. |
time_idx |
Optional integer time indices associated with |
space |
Output space to wrap into. |
... |
Additional arguments passed to methods. |
Domain-native wrapped representation.