This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def circular_linear_correlation(alpha, x): | |
# Authors: Jean-Remi King <[email protected]> | |
# Niccolo Pescetelli <[email protected]> | |
# | |
# Licence : BSD-simplified | |
""" | |
Parameters | |
---------- | |
alpha : numpy.array, shape (n_angles, n_dims) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ad hoc: Scaled Logistic Regression with probabilistic output | |
class force_predict(object): | |
def __init__(self, clf, mode='predict_proba', axis=0): | |
self._mode = mode | |
self._axis = axis | |
self._clf = clf | |
def fit(self, X, y, **kwargs): | |
self._clf.fit(X, y, **kwargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from mne.stats import spatio_temporal_cluster_1samp_test | |
# Gather all scores | |
scores = np.array([gat.scores_ for gat in gat_list]) | |
gat_mean = copy.deepcopy(gat_list[0]) | |
gat_mean.scores_ = np.mean(scores, axis=0) | |
# STATS | |
chance = 0.5 # chance level; if it's an AUC, it has to be .5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
============================================================= | |
Decoding source space data with ROI - sliding window approach | |
============================================================= | |
Decoding, a.k.a MVPA or supervised machine learning applied to MEG | |
data in source space on the left cortical surface. Here f-test feature | |
selection is employed to confine the classification to the potentially | |
relevant features. The classifier then is trained to selected features of | |
epochs in source space. A different classifier is trained i) in each |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
====================================================== | |
Example for Chris: Decoding source space data with ROI | |
====================================================== | |
""" | |
# Author: Jean-Remi King <[email protected] | |
# | |
# License: BSD-Simplified |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import mne | |
from mne import io | |
from mne.datasets import sample | |
data_path = sample.data_path() | |
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif' | |
event_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif' | |
raw = io.Raw(raw_fname, preload=True) | |
raw.filter(1, 20, method='iir') | |
events = mne.read_events(event_fname) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from sklearn.metrics import roc_auc_score, roc_curve | |
def roc(n=1e4, bit=1.): | |
X = np.random.randn(n) | |
y = np.zeros(n) | |
y[:n/2] = 1 | |
X[y==1] += bit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pairwise(X, Y, func, n_jobs=-1): | |
from mne.parallel import parallel_func | |
if X.shape != Y.shape: | |
raise ValueError('X and Y must have identical shapes') | |
parallel, p_pairwise, n_jobs = parallel_func(_pairwise, n_jobs) | |
dims = X.shape | |
X = np.reshape(X, [dims[0], np.prod(dims[1:])]) | |
Y = np.reshape(Y, [dims[0], np.prod(dims[1:])]) | |
n_cols = X.shape[1] | |
n_chunks = min(n_cols, n_jobs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import mne | |
from mne.decoding import GeneralizationAcrossTime as GAT | |
from sklearn.metrics import roc_auc_score | |
from sklearn.preprocessing import StandardScaler | |
from sklearn.svm import SVC | |
from sklearn.pipeline import make_pipeline | |
from sklearn.cross_validation import StratifiedKFold | |
from meeg_preprocessing.utils import setup_provenance |