Skip to content

FIX: FEMA input index should filter on rows, not columns. #207

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

Merged
merged 1 commit into from
Dec 13, 2019

Conversation

adelavega
Copy link
Collaborator

@adelavega adelavega commented Dec 13, 2019

Unfortunately, I didn't test this thoroughly enough, and the update on the FEMA input file indexing was incorrect. I reverted to a more clear/optimized version of my original logic.

Consider the following:

filtered_effects = ['/tmp/tmpe9vfsb1a/fitlins_wf/l1_model/mapflow/_l1_model0/text_effect_size.nii.gz',                                                                                                                         
 '/tmp/tmpe9vfsb1a/fitlins_wf/l1_model/mapflow/_l1_model0/rmse_effect_size.nii.gz',                                                                                                                         
 '/tmp/tmpe9vfsb1a/fitlins_wf/l1_model/mapflow/_l1_model0/speech_effect_size.nii.gz',                                                                                                                       
 '/tmp/tmpe9vfsb1a/fitlins_wf/l1_model/mapflow/_l1_model1/text_effect_size.nii.gz',                                                                                                                         
 '/tmp/tmpe9vfsb1a/fitlins_wf/l1_model/mapflow/_l1_model1/rmse_effect_size.nii.gz',                                                                                                                         
 '/tmp/tmpe9vfsb1a/fitlins_wf/l1_model/mapflow/_l1_model1/speech_effect_size.nii.gz',                                                                                                                       
 '/tmp/tmpe9vfsb1a/fitlins_wf/l1_model/mapflow/_l1_model2/text_effect_size.nii.gz',                                                                                                                         
 '/tmp/tmpe9vfsb1a/fitlins_wf/l1_model/mapflow/_l1_model2/rmse_effect_size.nii.gz',                                                                                                                         
 '/tmp/tmpe9vfsb1a/fitlins_wf/l1_model/mapflow/_l1_model2/speech_effect_size.nii.gz']  

# After running `prepare_contrasts`
contrasts = [('rmse', array([[1, 0, 0]]), 'FEMA'),                                                                                                                                                                      
 ('speech+rmse', array([[1, 0, 1]]), 'FEMA')]

and the design matrix looks like:

In [26]: mat                                                                                                                                                                                                
Out[26]:                                                                                                                                                                                                    
   rmse  speech  text                                                                                                                                                                                       
0     0       0     1                                                                                                                                                                                       
1     1       0     0                                                                                                                                                                                       
2     0       1     0                                                                                                                                                                                       
3     0       0     1                                                                                                                                                                                       
4     1       0     0                                                                                                                                                                                       
5     0       1     0                                                                                                                                                                                       
6     0       0     1                                                                                                                                                                                       
7     1       0     0                                                                                                                                                                                       
8     0       1     0  

For the first contrast [1, 0, 0] , you want the files indicated by 1s in the rmse column.

The current logic of ix = weights[0].astype(bool) yields:

Out[83]: array([ True, False, False])

which is not what we want, because it's not the correct shape for filtering filtered_effects.

I think this slipped past me because in my test analysis it just so happened that filtered_effects was of length 3, and it did not crash (although it probably filtered the wrong things).

Instead, we want to use that ix to filter mat.

con_ix = weights[0].astype(bool)
dm_ix = mat.iloc[:, con_ix].any(axis=1)
In [87]: dm_ix
Out[87]: 
0    False
1     True
2    False
3    False
4     True
5    False
6    False
7     True
8    False
dtype: bool

Now the reason that I added the any(axis=1), is because of second contrast with weights [1, 0, 1].

In this case we want to filter mat to select those two columns, and then select any rows that have a non-zero value in either columns:

In [98]: dm_ix
Out[98]: 
0     True
1     True
2    False
3     True
4     True
5    False
6     True
7     True
8    False
dtype: bool

Now, this might be a weird FEMA to specify, but it's theoretically valid.

@adelavega adelavega requested a review from effigies December 13, 2019 17:51
@adelavega
Copy link
Collaborator Author

adelavega commented Dec 13, 2019

As an aside, this is obviously means that FEMA is still broken in 0.6.1. Since I'm the only user of this, I'd be happy to just pin fitlins to this commit, and build from 0.6.1. Or we can do another hotfix release, your call.

@adelavega adelavega changed the title FIX: input index should filter on rows, not columns. FIX: FEMA input index should filter on rows, not columns. Dec 13, 2019
Copy link
Collaborator

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Looks reasonable. I appreciate the example to walk through, because thinking through these things is painful.

I'm good with going ahead and doing a 0.6.2 release.

@codecov-io
Copy link

codecov-io commented Dec 13, 2019

Codecov Report

Merging #207 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #207      +/-   ##
==========================================
+ Coverage   77.35%   77.37%   +0.02%     
==========================================
  Files          18       18              
  Lines        1042     1043       +1     
  Branches      187      187              
==========================================
+ Hits          806      807       +1     
- Misses        147      148       +1     
+ Partials       89       88       -1
Flag Coverage Δ
#ds003 77.37% <100%> (+0.02%) ⬆️
Impacted Files Coverage Δ
fitlins/interfaces/nistats.py 83% <100%> (+0.11%) ⬆️
fitlins/interfaces/bids.py 73.33% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a53f76e...86aec54. Read the comment docs.

@effigies effigies merged commit 99e518d into poldracklab:master Dec 13, 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.

3 participants