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 | |
from sklearn.preprocessing import RobustScaler | |
from sklearn.base import TransformerMixin | |
class TanhScaler(TransformerMixin): | |
def __init__(self, | |
factor=2., | |
decim=1, | |
n_max=None, | |
shuffle=False, |
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
class TimeGenScorer: | |
def __init__(self, n_times, train=None, cuda=False): | |
self.test_times = range(n_times) | |
if train is None: | |
train = slice(None, None, 1) | |
self.train_times = self.test_times[train] | |
self.cuda = cuda | |
def __call__(self, Y_true, Y_pred): |
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 stats(X, n_jobs=-1, seed=0, **kwargs): | |
from mne.stats import spatio_temporal_cluster_1samp_test | |
X = np.asarray(X) | |
if X.ndim==2: | |
X = X[:, :, None] | |
_, clusters, c_pv, _ = spatio_temporal_cluster_1samp_test( | |
X, n_jobs=n_jobs, seed=seed, out_type='mask', **kwargs | |
) | |
p_vals = [(mask*p + (mask==0)) for mask, p in zip(clusters, c_pv) | |
if p < .05] |
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 scale(X): | |
m = X.mean(0, keepdims=True) | |
s = X.std(0, keepdims=True) | |
s[s == 0] = 1 # avoid nan | |
X -= m | |
X /= s | |
return X | |
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 mne | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import scipy | |
import torch | |
from itertools import product | |
import pandas as pd | |
import seaborn as sns | |
def cart_to_pol(x, y): |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import matplotlib.pyplot as plt\n", |
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
from sklearn.linear_model import RidgeCV | |
import numpy as np | |
from scipy import linalg | |
class BlockRidgeCV(RidgeCV): | |
def __init__(self, alphas, blocks, fit_intercept=False, **kwargs): | |
super().__init__(**kwargs) | |
self.fit_intercept = False | |
self.alphas = alphas |
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 | |
import numpy as np | |
from sklearn.linear_model import LinearRegression | |
from sklearn.cross_decomposition import PLSRegression | |
from sklearn.model_selection import cross_val_score | |
from scipy.stats import pearsonr | |
ols = LinearRegression() | |
pls = PLSRegression() |
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
%matplotlib inline | |
import matplotlib.pyplot as plt | |
import numpy as np | |
n_layers = 4 | |
n_steps = 4 | |
fig, axes = plt.subplots(1, 3, sharex=True, sharey=True, figsize=[10, 3]) |