This article covers two research-facing surfaces that build on the
core LatentNeuroVec workflow:
The examples are intentionally small. They demonstrate object flow and sanity checks rather than compression claims for production-scale fMRI.
shared_reference() is intentionally an in-session cache.
It can avoid duplicating a matrix within an R session, but it does not
create archive paths, checksums, HDF5 datasets, or lazy file
readers.
shared_reference_clear()
loadings_ref <- shared_reference(template_loadings(tmpl), kind = "loadings")
shared_reference_info(loadings_ref)[c("kind", "has_cached_value", "persistence")]
#> $kind
#> [1] "loadings"
#>
#> $has_cached_value
#> [1] TRUE
#>
#> $persistence
#> [1] "session"Group-plus-delta loadings represent a subject-specific dictionary as a shared group matrix plus a small subject delta.
delta <- Matrix(0, nrow = nrow(template_loadings(tmpl)), ncol = template_rank(tmpl),
sparse = TRUE)
delta[1, 1] <- 0.05
subject_loadings <- group_delta_loadings(loadings_ref, delta, scale = 1)
materialized <- materialize_group_delta_loadings(subject_loadings)
data.frame(
rows = nrow(materialized),
cols = ncol(materialized),
max_abs_delta = max(abs(as.matrix(materialized - template_loadings(tmpl))))
)
#> rows cols max_abs_delta
#> 1 9 3 0.05The neuroarchive handoff contract makes the package boundary
explicit: fmrilatent owns in-memory representation
contracts and decode/project behavior; archive packages own persistent
stores and locators.
handoff <- neuroarchive_handoff_contract(
representation = lat,
components = list(component),
templates = list(tmpl),
references = list(loadings_ref)
)
data.frame(
fmrilatent_items = length(handoff$fmrilatent_owns),
neuroarchive_items = length(handoff$neuroarchive_owns),
persistent = handoff$persistent,
has_archive_locator = !is.null(handoff$archive_locator)
)
#> fmrilatent_items neuroarchive_items persistent has_archive_locator
#> 1 6 6 FALSE FALSEBOLDZip-SR works at the matrix level with rows as voxels or
grayordinates and columns as time points. This orientation is different
from encode(), which uses time x voxels.
The model stores:
n_voxels <- 8L
n_time <- 24L
tt <- seq_len(n_time)
carrier <- sin(2 * pi * tt / n_time)
texture <- seq(0.25, 2, length.out = n_voxels)
baseline <- seq(-1, 1, length.out = n_voxels)
X_vt <- texture %*% t(carrier)
X_vt <- sweep(X_vt, 1L, baseline, "+")
dim(X_vt)
#> [1] 8 24The example is exactly rank one after centering, so one carrier and a full DCT temporal budget should reconstruct it to numerical precision.
fit <- boldzip_sr_encode(
X_vt,
k_carriers = 1L,
temporal_k = n_time,
q_texture = 1L,
reliability = boldzip_reliability(min_texture_reliability = 0.1),
events = boldzip_events(max_events = 0L)
)
X_hat <- boldzip_sr_decode(fit)
metrics <- evaluate_boldzip_sr(X_vt, fit)
data.frame(
mse = signif(metrics[["mse"]], 3),
rmse = signif(metrics[["rmse"]], 3),
payload_scalars = metrics[["payload_scalars"]],
finite_reconstruction = all(is.finite(X_hat))
)
#> mse rmse payload_scalars finite_reconstruction
#> 1 3.27e-30 1.81e-15 650 TRUEThe payload summary reports where the stored scalar budget goes. It is an accounting diagnostic, not a binary file-size estimate.
boldzip_sr_payload_summary(fit)
#> component scalar_count bytes
#> 1 carriers_theta 24 408
#> 2 texture_loadings 42 1464
#> 3 events 0 1352
#> 4 baseline_mu 8 112
#> 5 basis_metadata 576 5720
#> 6 total_object 650 21184The codec can also use a graph-derived coarse/detail spatial basis. The small path graph below creates orthonormal Laplacian eigenvectors; low frequencies become carriers and higher frequencies become detail atoms.
adjacency <- matrix(0, nrow = 6L, ncol = 6L)
for (idx in seq_len(5L)) {
adjacency[idx, idx + 1L] <- 1
adjacency[idx + 1L, idx] <- 1
}
graph_basis <- boldzip_graph_spatial_basis(
adjacency,
n_coarse = 2L,
n_detail = 3L
)
gram_error <- max(abs(crossprod(cbind(graph_basis$phi_c, graph_basis$phi_d)) - diag(5L)))
data.frame(
coarse_atoms = ncol(graph_basis$phi_c),
detail_atoms = ncol(graph_basis$phi_d),
max_gram_error = signif(gram_error, 3)
)
#> coarse_atoms detail_atoms max_gram_error
#> 1 2 3 1.07e-15Use shared basis contracts when you need a reusable representation boundary: the same spatial dictionary, explicit projection behavior, and a clean handoff to downstream model-fitting or archive code.
Use BOLDZip-SR when you want to experiment with a compression-oriented carrier/texture/event decomposition. In its current form it is an experimental matrix codec, not a production bitstream format.