Skip to content

Instantly share code, notes, and snippets.

View kingjr's full-sized avatar

Jean-Rémi KING kingjr

View GitHub Profile
@kingjr
kingjr / loop.py
Created January 17, 2018 22:11
embarassingly parallel loop across numpy arrays
def loop(X, func, n_jobs=-1, *args, **kwargs):
""""will apply func(x, *args) for x in X in parallel"""
from joblib import Parallel, delayed, cpu_count
max_jobs = cpu_count()
n_jobs = max_jobs if n_jobs==-1 else n_jobs
n_jobs = max_jobs if n_jobs>max_jobs else n_jobs
n_jobs = min(n_jobs, len(X))
parallel = Parallel(n_jobs=n_jobs)
p_func = delayed(_loop)
@kingjr
kingjr / ipyvolume_topo.ipynb
Created January 17, 2018 04:14
ipyvolume_topo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kingjr
kingjr / plot_source_helmet.py
Created November 16, 2017 03:33
failed attempt: fields removes sources
from mayavi import mlab
import numpy as np
import mne
from mne.datasets import sample
from mne.minimum_norm import make_inverse_operator, apply_inverse
mne.set_log_level(False)
data_path = sample.data_path()
subjects_dir = data_path + '/subjects'
raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
raw = mne.io.read_raw_fif(raw_fname) # already has an average reference
@kingjr
kingjr / background.ipynb
Last active September 21, 2017 16:29
Background notions in linear algebra and shallow machine learning applied to electrophysiology
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kingjr
kingjr / for_claire_std.py
Created September 20, 2017 17:31
example generalization std single trial
import mne
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import StratifiedKFold
from mne.decoding import SlidingEstimator
# Generate random, fake MEG data
@kingjr
kingjr / sources_3d.ipynb
Last active January 17, 2018 14:31
Example continuing on Chris' p3volume example to plot source estimates
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kingjr
kingjr / example_single_trial.py
Last active September 12, 2017 14:44
for_claire
%matplotlib inline
import mne
import matplotlib.pyplot as plt # library for plotting
import numpy as np # library for matrix operations
# Generate random, fake MEG data
n_trials, n_channels, n_times, sfreq = 100, 32, 50, 500.
conditions = np.random.randint(0, 2, n_trials)
info = mne.create_info(n_channels, sfreq)
data = np.random.randn(n_trials, n_channels, n_times)
@kingjr
kingjr / poeppel_training_3.ipynb
Created July 24, 2017 21:29
poeppel training 3: fitting our first decoding analysis
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.