Status (May 2025)
estimation_method = "crossnobis"
is currently disabled in contrast_rsa_model()
. The code only whitened fold-means and did not compute the unbiased squared Euclidean distances required by Eq. (5) of Diedrichsen & Kriegeskorte (2017). This document specifies the steps to implement Crossnobis correctly, end-to-end.
| Component | Change |
|-----------|--------|
| contrast_rsa_model()
| Re-allow estimation_method = "crossnobis"
; add argument whitening_matrix_W = NULL
that is stored in the model spec. |
| compute_crossvalidated_means_sl()
| No change – new function will be used. |
| New helper compute_crossnobis_distances_sl()
| Returns a named vector d_crossnobis
of length (K(K-1)/2). |
| train_model.contrast_rsa_model()
| Branch: if obj$estimation_method == "crossnobis"
, call the new helper to obtain dvec_sl
directly (skip Ĝ, lower-tri step). Still compute U_hat_sl
(via existing function) so that Δ and Σ_q β_q Δ_q,v remain available. |
| Searchlight plumbing | Ensure whitening_matrix_W
is forwarded (either via ...
at run_searchlight()
or by storing it in the model spec and passing down). |
compute_crossnobis_distances_sl()
sl_data
(N × P)mvpa_design
(with Y
conditions & block_var
/cv grouping)cv_spec
(provides get_nfolds()
& train_indices()
)whitening_matrix_W
(optional)cond_levels
= levels(mvpa_design$Y).M
folds and allocate accumulator cross_sum
(length = Kpairs) initialised to 0.m
:μ̂_{c,m}
= mean pattern of condition c
computed only on training samples of that fold (same logic as existing mean function).μ̂_{c,m} ← μ̂_{c,m} %*% W
.M_folds[m, c, p]
.(i,j)
(vector index k
):(m,n)
with m ≠ n
:δ̂_{k,m} ← μ̂_{i,m} − μ̂_{j,m}
δ̂_{k,n} ← μ̂_{i,n} − μ̂_{j,n}
cross_sum[k] += crossprod(δ̂_{k,m}, δ̂_{k,n})
M≤10
, K≤12
, P≤500
, feasible.δ̂
on the fly; no need to store full array if we loop cleverly.d_crossnobis[k] ← cross_sum[k] / (M*(M-1)*P)
"condA_vs_condB"
in lower-tri order to match how contrast RDMs are vectorised elsewhere.dvec_sl
from Ĝ_sl
.include_vec
handling (exclude intra-run pairs) still applies – we set forbidden entries to NA
before regression.Xmat
(contrast RDMs) is unchanged; we only swap the dependent variable.μ̂_{c,m}
undefined, exclude all pairwise distances involving that condition from regression; flag with na_reason
.M < 2
(e.g., leave-one-out CV) → abort: cannot form cross-products with m≠n
.W
→ warn & skip whitening.W = I
vs. no whitening.contrasts_rsa_model(estimation_method="crossnobis")
; ensure no error and reasonable output.compute_crossnobis_distances_sl()
+ tests.train_model.contrast_rsa_model()
.whitening_matrix_W
.| Week | Deliverable | |------|-------------| | 1 | Helper function + unit tests pass | | 2 | Integration into train_model + searchlight plumbing | | 3 | Documentation, vignette, example rebuild | | 4 | Profiling & optional Rcpp optimisation |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.