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 <module>()</div><div> 121 print 'run finished without errors.'</div>
<div> 122 except: print 'run finished with some errors. Re-run?'</div><div>--> 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 'running %s' % T['out']</div><div> 1079 set_trace()</div><div>-> 1080 sl_map = sl(ds)</div><div> 1081 # 1-(1/nconds) - error</div><div> 1082 sl_map_r = [(1.-(1./len(T['conds']))) - 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>--> 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>--> 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>--> 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>--> 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>-> 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>-> 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>--> 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>-> 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>--> 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>--> 402</div><div> 403</div>
<div> 404</div><div><br></div><div>TypeError: object of type 'numpy.float64' has no len()</div><div>WARNING: Failure executing file: <B01_MVPA.py></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['clf']+'()') # CSVMC</div><div> if T['FS']:</div><div> clfcmd = FeatureSelectionClassifier(clfcmd,</div>
<div> SensitivityBasedFeatureSelection(</div><div> clfcmd.getSensitivityAnalyzer(transformer=abs),</div><div> FixedNElementTailSelector(T['FS_limit'], mode='select',tail='upper'))) # select 50 features</div>
<div><br></div><div> cv = CrossValidatedTransferError(TransferError(clfcmd),</div><div> NFoldSplitter(), #OddEvenSplitter(),</div><div> enable_states = ['results'])</div><div><br></div><div>
sl = Searchlight(cv,radius=T['radius']) # 10 mm</div><div><br></div><div># Rescore labels</div><div> new_labels = []</div><div> for l in T['labels']:</div><div> if not l in T['conds']: 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['sub4D'],</div><div> labels=new_labels,</div><div> chunks=T['chunks'],</div>
<div> mask=T['submask'])</div><div><br></div><div># Remove irrelevant labels</div><div> zerocheck = array([v != 0.5 for v in new_labels],dtype='bool')</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 'running %s' % T['out']</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]: <Dataset / float32 8 x 21583 uniq: 4 chunks 2 labels></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'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 & 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>