Skip to content

Instantly share code, notes, and snippets.

Jean-Rémi KING kingjr

View GitHub Profile
View cluster_api.py
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]
@kingjr
kingjr / utils.py
Created Feb 18, 2020
scale correlate
View utils.py
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
View extract_2d.py
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):
View plot_arch.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View gist:334fe4d7968b931eb18f6af5b003c397
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
@kingjr
kingjr / block_ridge.py
Last active Dec 20, 2019
block ridge: WIP
View block_ridge.py
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
View for_danilo.py
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()
@kingjr
kingjr / arch_plots.py
Last active Dec 6, 2019
architecture_plot
View arch_plots.py
%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])
View example_text_generation.py
import sys
import os
import os
import numpy as np
import torch
import matplotlib.pyplot as plt
sys.path.append(os.path.abspath('./sentence_embedding'))
from utils import load_model, build_XLM_dictionary # noqa
@kingjr
kingjr / linear_or_categorical.py
Last active Feb 22, 2019
linear_or_categorical.py
View linear_or_categorical.py
"""Fit sigmoid with parallel seeds to find global minimum.
"""
import matplotlib.pyplot as plt
import numpy as np
import torch
import torch.nn as nn
from scipy.stats import pearsonr, wilcoxon
from sklearn.base import BaseEstimator
from sklearn.model_selection import StratifiedKFold
from sklearn.linear_model import LinearRegression
You can’t perform that action at this time.