Skip to content

share_comps fails on rank-reduced fits: sphere inversion requires full rank #253

Closed

Description

@neuromechanist

Reported by @sunyuhongwr in #221 (comment): with the new rank-deficient MEG handling, enabling share_comps=True raises RuntimeError: Component sharing needs an invertible sphere... because _identify_shared_comps computes Spinv = torch.linalg.inv(self.sphere). Under rank reduction (#223) the sphere is (n_kept, n_channels) and has no inverse, and a square sphere fitted on rank-deficient data is singular, so component sharing is unusable on exactly the data class (Maxwell-filtered Elekta MEG) that motivated #221/#223.

Why invertibility is not actually required

The inverse is only used to de-sphere the mixing columns back to sensor space before the cosine-similarity comparison (Fortran identify_shared_comps, amica15.f90:1898). The reference's own back-map under PCA reduction is the pseudo-inverse Spinv(nx, numeigs) (amica15.f90:550-560), not a true inverse. Replacing inv(sphere) with pinv(sphere) is therefore the faithful generalization: for a square full-rank sphere pinv == inv to machine precision (and the |cos| threshold comp_thresh ~0.99 cannot flip on a ~1e-15 perturbation), and for a rank-reduced sphere it maps the columns into the retained sensor-space subspace, which is exactly the U_r-mapping the reporter proposed (cosine similarity after a common orthonormal embedding is unchanged).

Work

  • torch_impl: _identify_shared_comps uses torch.linalg.pinv(self.sphere); remove the invertibility RuntimeError (torch_impl/core.py:1687-1702)
  • numpy_impl: same change in identify_shared_components if the backend can hold a reduced sphere; otherwise record the divergence in docs/guides/amica-differences.md (.rules/backend_parity.md)
  • Test on real sample EEG projected to a lower-rank subspace (the Support for Maxwell-filtered Elekta MEG data #221 recipe): multi-model fit with share_comps=True completes, finite parameters, sensible shared_components()
  • Full-rank regression: merge decisions on full-rank data unchanged by the inv -> pinv swap

Related: #221, #223, #60.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions