def _run(epochs, events, analysis): """Runs temporal generalization for a given subject and analysis""" print(subject, analysis['name']) # subselect the trials (e.g. exclude absent trials) with a # dataframe query defined in conditions.py query, condition = analysis['query'], analysis['condition'] sel = range(len(events)) if query is None \ else events.query(query).index sel = [ii for ii in sel if ~np.isnan(events[condition][sel][ii])] # The to-be-predicted value, for each trial: y = np.array(events[condition], dtype=np.float32) print analysis['name'], np.unique(y[sel]), len(sel) # Abort if there is no trial if len(sel) == 0: return # Apply analysis gat = GeneralizationAcrossTime(clf=analysis['clf'], cv=analysis['cv'], scorer=analysis['scorer'], n_jobs=-1) print(subject, analysis['name'], 'fit') gat.fit(epochs[sel], y=y[sel]) print(subject, analysis['name'], 'score') score = gat.score(epochs[sel], y=y[sel]) print(subject, analysis['name'], 'save') # save space if analysis['name'] not in ['probe_phase', 'target_circAngle']: # we'll need the estimator trained on the probe_phase and to generalize # to the target phase and prove that there is a significant signal. gat.estimators_ = None if analysis['name'] not in [ 'target_present', 'target_circAngle', 'probe_circAngle' ]: # We need these individual prediction to control for the correlation # between target and probe angle. gat.y_pred_ = None # Save analysis save([gat, analysis, sel, events], 'decod', subject=subject, analysis=analysis['name'], overwrite=True, upload=True) save([score, epochs.times], 'score', subject=subject, analysis=analysis['name'], overwrite=True, upload=True) return
def _decod(subject, analysis): from mne.decoding import GeneralizationAcrossTime # if already computed let's just load it from disk fname_kwargs = dict(subject=subject, analysis=analysis['name'] + '_vhp') score_fname = paths('score', **fname_kwargs) if op.exists(score_fname): return load('score', **fname_kwargs) epochs = _get_epochs(subject) events = load('behavior', subject=subject) # Let's not recompute everything, this is just a control analysis print(subject, analysis['name']) epochs._data = epochs.get_data() epochs.preload = True epochs.crop(0., .900) epochs.decimate(2) query, condition = analysis['query'], analysis['condition'] sel = range(len(events)) if query is None else events.query(query).index sel = [ii for ii in sel if ~np.isnan(events[condition][sel][ii])] y = np.array(events[condition], dtype=np.float32) print analysis['name'], np.unique(y[sel]), len(sel) if len(sel) == 0: return # Apply analysis gat = GeneralizationAcrossTime(clf=analysis['clf'], cv=analysis['cv'], scorer=analysis['scorer'], n_jobs=-1) print(subject, analysis['name'], 'fit') gat.fit(epochs[sel], y=y[sel]) print(subject, analysis['name'], 'score') score = gat.score(epochs[sel], y=y[sel]) print(subject, analysis['name'], 'save') # save space gat.estimators_ = None gat.y_pred_ = None # Save analysis save([score, epochs.times], 'score', overwrite=True, upload=True, **fname_kwargs) return score, epochs.times
def _run(epochs, events, analysis): """Runs temporal generalization for a given subject and analysis""" print(subject, analysis['name']) # subselect the trials (e.g. exclude absent trials) with a # dataframe query defined in conditions.py query, condition = analysis['query'], analysis['condition'] sel = range(len(events)) if query is None \ else events.query(query).index sel = [ii for ii in sel if ~np.isnan(events[condition][sel][ii])] # The to-be-predicted value, for each trial: y = np.array(events[condition], dtype=np.float32) print analysis['name'], np.unique(y[sel]), len(sel) # Abort if there is no trial if len(sel) == 0: return # Apply analysis gat = GeneralizationAcrossTime(clf=analysis['clf'], cv=analysis['cv'], scorer=analysis['scorer'], n_jobs=-1) print(subject, analysis['name'], 'fit') gat.fit(epochs[sel], y=y[sel]) print(subject, analysis['name'], 'score') score = gat.score(epochs[sel], y=y[sel]) print(subject, analysis['name'], 'save') # save space if analysis['name'] not in ['probe_phase', 'target_circAngle']: # we'll need the estimator trained on the probe_phase and to generalize # to the target phase and prove that there is a significant signal. gat.estimators_ = None if analysis['name'] not in ['target_present', 'target_circAngle', 'probe_circAngle']: # We need these individual prediction to control for the correlation # between target and probe angle. gat.y_pred_ = None # Save analysis save([gat, analysis, sel, events], 'decod', subject=subject, analysis=analysis['name'], overwrite=True, upload=True) save([score, epochs.times], 'score', subject=subject, analysis=analysis['name'], overwrite=True, upload=True) return