Skip to content

Conversation

@joewalter
Copy link
Member

WIP addressing #2163 and #4308.

Added a new private function, which checks the input to loose and adapts it if necessary (and also converts forward to surface oriented if required). Currently, only loose = None and loose=1. are supported for vol source spaces. Please let me know if loose orientation constraint should also be available for vol source spaces.

@codecov-io
Copy link

codecov-io commented Jun 9, 2017

Codecov Report

Merging #4312 into master will decrease coverage by 0.21%.
The diff coverage is 57.18%.

@@            Coverage Diff             @@
##           master    #4312      +/-   ##
==========================================
- Coverage   82.82%   82.61%   -0.22%     
==========================================
  Files         349      349              
  Lines       64424    65196     +772     
  Branches     9915    10153     +238     
==========================================
+ Hits        53361    53860     +499     
- Misses       8324     8540     +216     
- Partials     2739     2796      +57


def _check_loose(forward, loose):
"""Check loose parameter input."""
if is_fixed_orient(forward):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it mean I always have a warning when working with fixed ori?

I think we should not have a warning when user set loose to None explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added and loose is not None, so the warning will now only appear if loose is not None

"""Check loose parameter input."""
if is_fixed_orient(forward) and loose is not None:
warn('Ignoring loose parameter with forward operator '
'with fixed orientation.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say to set it to None to avoid this warning

if not (0 <= loose <= 1):
raise ValueError('Loose value should be smaller than 1 and '
'bigger than 0, or None for not loose '
'orientations.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

say what you got

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joewalter reminder here

raise ValueError('Loose value should be smaller than 1 and '
'bigger than 0, or None for not loose '
'orientations.')
if loose < 1 and not forward['surf_ori']:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say

if loose is not None and not forward['surf_ori']:

orient_prior[np.mod(np.arange(n_sources), 3) != 2] *= loose

if ((loose is not None) and
not all([item in [1., None] for item in loose.values()])):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should force loose=None rather than accepting 1.

noise_cov, depth=None)

# for free ori inv, loose=None and loose=1 should be equivalent
# for free ori inv, loose=None and loose=1. should be equivalent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eric89GXL are you ok to force loose=None for non surf ori forward?

@larsoner
Copy link
Member

larsoner commented Jun 10, 2017 via email

@agramfort
Copy link
Member

agramfort commented Jun 10, 2017 via email

@larsoner
Copy link
Member

larsoner commented Jun 10, 2017 via email

@larsoner
Copy link
Member

larsoner commented Jun 10, 2017 via email

@larsoner
Copy link
Member

larsoner commented Jun 10, 2017 via email

@agramfort
Copy link
Member

agramfort commented Jun 11, 2017 via email

@joewalter
Copy link
Member Author

Do we want to allow a loose orientation constraint for discrete source spaces? IIRC they are used for defining volume source spaces, so I am wondering whether we should treat them similarly to volume source spaces?

@agramfort
Copy link
Member

agramfort commented Jun 12, 2017 via email

@larsoner
Copy link
Member

larsoner commented Jun 12, 2017 via email

@agramfort
Copy link
Member

agramfort commented Jun 12, 2017 via email

@larsoner
Copy link
Member

Argh, we do have these lines:

    if mri is not None:
        for s in sp:
            _add_interpolator(s, mri, add_interpolator)
    elif sp[0]['type'] == 'vol':
        # If there is no interpolator, it's actually a discrete source space
        sp[0]['type'] = 'discrete'

So we change vol type to discrete if there is no mri. This seems a bit odd to me, since it's still defined on a volume grid in volume space. But maybe because it's because you can't easily / properly interpolate into a volume for viz...?

I think this use case is likely rare (?), but the case of user-defined discrete source spaces might also be rare. To be safe, I'm okay with forcing free ori for discrete for now -- we can always add support for it later if we find users need it.

@joewalter
Copy link
Member Author

Ok, I'll force free orientation with my next commit.

@joewalter
Copy link
Member Author

With regard to sparse solvers I thought of normalizing the vector (weight_tan1, weight_tan2, weight_normal) in order not to bias the solution towards sources with free orientation (I'd add a sparse_inv flag, so that nothing changes for MNE-type methods)

@larsoner
Copy link
Member

I'd add a sparse_inv flag, so that nothing changes for MNE-type methods

Why wouldn't you also want this for MNE methods, at least as an option? That way if I have 1000 fixed-orientation surface source-space points and 1000 free-orientation volume points, you could achieve roughly equivalent activation mapping into both (spatial distribution considerations aside), right?

@agramfort
Copy link
Member

agramfort commented Jun 12, 2017 via email

@joewalter
Copy link
Member Author

So the variance of a source depends on whether it is a free or fixed orientation source?

@joewalter
Copy link
Member Author

When we agree to only support loose or fixed orientation for surface-based source spaces, we can make the handling of loose much simpler, as we don't need the dict (so the check_loose function is much simpler) and we just add an info that loose parameter is ignored for volume and discrete source spaces.

@agramfort
Copy link
Member

agramfort commented Jun 13, 2017 via email

@larsoner
Copy link
Member

Sounds like a plan.

Does this also take care of #4313?

Is it possible/easy to update some example? Even a mixed-source-space MNE example might benefit from it.

'orientation.')
forward = convert_forward_solution(forward, surf_ori=True)
else:
raise ValueError('loose value must be None for not loose '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loose must be None for not loose orientations ?

this is unclear what you mean here.

else:
logger.info('Applying loose dipole orientations for surface-based '
'source spaces with loose=%f.' % loose)
idx_start = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add here

assert not is_fixed_orient(forward)

to avoid futur bugs

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any time to come back to this one, too? It'll need a (probably annoying) rebase

assert_true(_check_loose(fwd_fixed, 0.2)[1] is None)

del fwd, fwd_fixed
gc.collect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are really worried about memory, convert_forward_solution has copy=False to modify inplace


@testing.requires_testing_data
def test_check_loose():
"""Test _check_loose
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end with period, no newline before """ (we are slowly updating to latest docstring standard)

@larsoner
Copy link
Member

@joewalter what is left here? Just a rebase and a few minor remaining comments?

@larsoner
Copy link
Member

I don't think we should do this until 0.16 so we have some time to finish and then test, pushing to 0.16

@larsoner larsoner modified the milestones: 0.15, 0.16 Sep 22, 2017
@joewalter
Copy link
Member Author

I think it is a good idea to push this to 0.16 so we have enough time for improvements and tests

@joewalter joewalter closed this Sep 25, 2017
@agramfort agramfort reopened this Sep 25, 2017
@agramfort
Copy link
Member

let's not close. We'll take some code from here.

@joewalter
Copy link
Member Author

I think to make this one easier, we could split it in several PR. So we can faster merge parts of it, making rebasing simpler

@agramfort
Copy link
Member

agramfort commented Sep 26, 2017 via email

@larsoner
Copy link
Member

Perhaps the first split could take care of #4604. That would be nice to have for 0.15

@larsoner
Copy link
Member

Removing 0.16 tag

@larsoner larsoner removed this from the 0.16 milestone Feb 27, 2018
@larsoner
Copy link
Member

@joewalter any time to come back to this one?

@larsoner
Copy link
Member

This PR is way out of date at this point. Now that almost all code is refactored to use the same loose and depth paths, we should probably start with a fresh PR for this.

@larsoner larsoner closed this Mar 27, 2019
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

Successfully merging this pull request may close these issues.

4 participants