Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can have too big rank when beamforming #302

Open
YonatanGideoni opened this issue Jun 19, 2024 · 1 comment
Open

Can have too big rank when beamforming #302

YonatanGideoni opened this issue Jun 19, 2024 · 1 comment

Comments

@YonatanGideoni
Copy link

Summary:
When beamforming, eg. when using beamform_and_parcellate, the given rank can be larger than the covariance matrix' dimensions.

Versions:
Ubuntu 20.04
OSL version: 0.6

Expected behaviour:
Use covariance mat's rank if given one is too big - this is likely due to numerical issues.

Example logs:

sub-01_ses-1_task-3_meg_preproc_raw : *********************************
sub-01_ses-1_task-3_meg_preproc_raw : * SOURCE RECONSTRUCTION FAILED! *
sub-01_ses-1_task-3_meg_preproc_raw : *********************************
sub-01_ses-1_task-3_meg_preproc_raw : beamform_and_parcellate : <function beamform_and_parcellate at 0x7f76ac9a4f70>
sub-01_ses-1_task-3_meg_preproc_raw : <class 'ValueError'>
sub-01_ses-1_task-3_meg_preproc_raw : Invalid value for the rank parameter (263) given the shape of the input matrix (208 x 208).
  File "/auto/path/code/osl/osl/source_recon/batch.py", line 183, in run_src_chain
    func(src_dir, subject, preproc_file, smri_file, epoch_file, **userargs)
  File "/auto/path/code/osl/osl/source_recon/wrappers.py", line 737, in beamform_and_parcellate
    filters = beamforming.make_lcmv(
  File "/auto/path/code/osl/osl/source_recon/beamforming.py", line 177, in make_lcmv
    filters = _make_lcmv(
  File "<decorator-gen-603>", line 12, in _make_lcmv
  File "/auto/path/code/osl/osl/source_recon/beamforming.py", line 735, in _make_lcmv
    W, max_power_ori = _compute_beamformer(
  File "/auto/path/code/osl/osl/source_recon/beamforming.py", line 843, in _compute_beamformer
    Cm_inv, loading_factor, rank = _reg_pinv(Cm, reg, rank)
  File "path/.conda/envs/pnpl/lib/python3.10/site-packages/mne/utils/numerics.py", line 172, in _reg_pinv
    raise ValueError('Invalid value for the rank parameter (%d) given '

Possible fixes:
rank = min(rank, Cm.shape[0])

@cgohil8
Copy link
Collaborator

cgohil8 commented Jun 28, 2024

Adding that line has consequences for the beamforming, which likely will invalid it. It's unlikely we would implement this change.

I suspect your error arises due to a miss match between the channel types used to make the beamformer and the channel types it's applied to, or something similar along those lines.

Can you copy and paste your config.

A better solution might be to add more comprehensive validation of the source reconstruction parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants