Shared spatial dictionaries are useful when multiple subjects should be represented in the same spatial coordinates. The dictionary is built once from a template reduction or training sample; each subject gets its own coefficient time series and offset.
Two subject matrices can share the same dictionary while having different coefficient time series.
set.seed(19)
X_subject1 <- X_train + matrix(rnorm(length(X_train), sd = 0.01), nrow = n_time)
X_subject2 <- 0.8 * X_train + matrix(rnorm(length(X_train), sd = 0.01), nrow = n_time)
lat1 <- encode(X_subject1, spec_space_parcel(tmpl), mask = mask_vol)
lat2 <- encode(X_subject2, spec_space_parcel(tmpl), mask = mask_vol)
data.frame(
subject = c("subject1", "subject2"),
coefficient_rows = c(nrow(coef_time(lat1)), nrow(coef_time(lat2))),
coefficient_cols = c(ncol(coef_time(lat1)), ncol(coef_time(lat2))),
rmse = round(c(
sqrt(mean((as.matrix(lat1) - X_subject1)^2)),
sqrt(mean((as.matrix(lat2) - X_subject2)^2))
), 6)
)
#> subject coefficient_rows coefficient_cols rmse
#> 1 subject1 8 3 0.008307
#> 2 subject2 8 3 0.008162The spatial loadings are the shared part. The coefficients are the subject-specific part.
data.frame(
same_loading_shape = identical(dim(loadings(lat1)), dim(loadings(lat2))),
max_loading_difference = max(abs(loadings(lat1) - loadings(lat2))),
coefficient_difference = max(abs(coef_time(lat1) - coef_time(lat2)))
)
#> same_loading_shape max_loading_difference coefficient_difference
#> 1 TRUE 0 0.3927821Use vignette("shared-structure-boldzip") when you need
the lower-level shared-structure contracts and archive handoff
boundaries.