Hi guys,<div><br></div><div>I keep getting a strange crash with my searchlight analysis. This only seems to happen for certain subjects out of a large sample, and only happens when I combine the searchlight with sensitivity-based feature selection. The searchlight starts to run, and then crashes with:</div>
<div><br></div><div><div>TypeError                                 Traceback (most recent call last)</div><div><br></div><div>/imaging/jc01/Becky01/MVPA/B01_MVPA.py in &lt;module&gt;()</div><div>    121                         print &#39;run finished without errors.&#39;</div>
<div>    122                 except: print &#39;run finished with some errors. Re-run?&#39;</div><div>--&gt; 123         else: map(sl_run,tasklist)</div><div>    124</div><div>    125</div><div><br></div><div>/imaging/jc01/UtilityScripts/Python/JohansMVPA.py in sl_run(T)</div>
<div>   1078         print &#39;running %s&#39; % T[&#39;out&#39;]</div><div>   1079         set_trace()</div><div>-&gt; 1080         sl_map = sl(ds)</div><div>   1081 # 1-(1/nconds) - error</div><div>   1082         sl_map_r = [(1.-(1./len(T[&#39;conds&#39;]))) - i for i in sl_map] # chance = 0</div>
<div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/measures/base.pyc in __call__(self, dataset)</div><div>    103</div><div>    104</div><div>--&gt; 105</div><div>    106</div><div>    107</div>
<div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/measures/searchlight.pyc in _call(self, dataset)</div><div>    106</div><div>    107</div><div>--&gt; 108</div><div>    109</div><div>    110</div>
<div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/measures/base.pyc in __call__(self, dataset)</div><div>    103</div><div>    104</div><div>--&gt; 105</div><div>    106</div><div>    107</div>
<div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/algorithms/cvtranserror.pyc in _call(self, dataset)</div><div>    171</div><div>    172</div><div>--&gt; 173</div><div>    174</div><div>    175</div>
<div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/clfs/transerror.pyc in __call__(self, testdataset, trainingdataset)</div><div>   1281</div><div>   1282</div><div>-&gt; 1283</div><div>   1284</div>
<div>   1285</div><div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/clfs/transerror.pyc in _precall(self, testdataset, trainingdataset)</div><div>   1237</div><div>   1238</div><div>-&gt; 1239</div>
<div>   1240</div><div>   1241</div><div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/clfs/base.pyc in train(self, dataset)    352</div><div>    353</div><div>--&gt; 354</div><div>    355</div>
<div>    356</div><div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/clfs/meta.pyc in _train(self, dataset)</div><div>   1056</div><div>   1057</div><div>-&gt; 1058</div><div>   1059</div><div>
   1060</div><div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/featsel/base.pyc in __call__(self, dataset, testdataset)</div><div>    106</div><div>    107</div><div>--&gt; 108</div><div>    109</div>
<div>    110</div><div><br></div><div>/imaging/jc01/PythonInstall/lib/python2.5/site-packages/mvpa/featsel/helpers.pyc in __call__(self, seq)</div><div>    400</div><div>    401</div><div>--&gt; 402</div><div>    403</div>
<div>    404</div><div><br></div><div>TypeError: object of type &#39;numpy.float64&#39; has no len()</div><div>WARNING: Failure executing file: &lt;B01_MVPA.py&gt;</div><div><br></div><div>----</div><div><br></div><div>These empty code snippets are a bit hard to decipher. :) Relevant bits of code:</div>
<div><br></div><div><div># Configure classifier, crossvalidation, searchlight</div><div>    clfcmd = eval(T[&#39;clf&#39;]+&#39;()&#39;) # CSVMC</div><div>    if T[&#39;FS&#39;]:</div><div>        clfcmd = FeatureSelectionClassifier(clfcmd,</div>
<div>            SensitivityBasedFeatureSelection(</div><div>                clfcmd.getSensitivityAnalyzer(transformer=abs),</div><div>                FixedNElementTailSelector(T[&#39;FS_limit&#39;], mode=&#39;select&#39;,tail=&#39;upper&#39;))) # select 50 features</div>
<div><br></div><div>    cv = CrossValidatedTransferError(TransferError(clfcmd),</div><div>             NFoldSplitter(), #OddEvenSplitter(),</div><div>             enable_states = [&#39;results&#39;])</div><div><br></div><div>
    sl = Searchlight(cv,radius=T[&#39;radius&#39;]) # 10 mm</div><div><br></div><div># Rescore labels</div><div>    new_labels = []</div><div>    for l in T[&#39;labels&#39;]:</div><div>        if not l in T[&#39;conds&#39;]: new_labels.append(0.5)</div>
<div>        else: new_labels.append(l)</div><div><br></div><div># Load data</div><div>    ds = NiftiDataset(samples=T[&#39;sub4D&#39;],</div><div>        labels=new_labels,</div><div>        chunks=T[&#39;chunks&#39;],</div>
<div>        mask=T[&#39;submask&#39;])</div><div><br></div><div># Remove irrelevant labels</div><div>    zerocheck = array([v != 0.5 for v in new_labels],dtype=&#39;bool&#39;)</div><div>    ds = ds.selectSamples(zerocheck)</div>
<div><br></div><div># Preprocessing</div><div>    ds = removeInvariantFeatures(ds)</div><div>    zscore(ds,perchunk=False)</div><div><br></div><div># Run, rescale, and save</div><div>    print &#39;running %s&#39; % T[&#39;out&#39;]</div>
<div>    #set_trace()</div><div>    sl_map = sl(ds)</div><div><br></div></div><div>--------</div><div><br></div><div>For the analysis that crashes, the dataset looks like this:</div><div><br></div><div><div> ds</div><div>
Out[87]: &lt;Dataset / float32 8 x 21583 uniq: 4 chunks 2 labels&gt;</div><div>(Pdb) ds.C</div><div>Out[87]: array([ 1.,  2.,  3.,  4.,  1.,  2.,  3.,  4.])</div><div>(Pdb) ds.L</div><div>Out[87]: array([  60.,   60.,   60.,   60.,  300.,  300.,  300.,  300.])</div>
<div>(Pdb) shape(ds.S)</div><div>Out[87]: (8, 21583)</div><div><br></div><div>-------</div><div><br></div><div>Once again, the exact same classification problem works fine for all other subjects. I assume the problem comes in with feature selection because a previous run without it finished with no errors.</div>
<div><br></div><div>I&#39;m a bit stumped by this. Let me know if anyone has any ideas!</div><div><br></div><div>Johan</div><div><br></div><div><br></div></div><div><br></div><br>-- <br>Johan Carlin<br>Graduate Student<br>
MRC Cognition &amp; Brain Sciences Unit<br>15 Chaucer Road<br>Cambridge CB2 7EF<br>UK<br><br><a href="mailto:johan.carlin@mrc-cbu.cam.ac.uk">johan.carlin@mrc-cbu.cam.ac.uk</a><br>+44 (0)1223 355294 ext 593<br>
</div>