Skip to content

Instantly share code, notes, and snippets.

View kingjr's full-sized avatar

Jean-Rémi KING kingjr

View GitHub Profile
from Levenshtein import editops
def match_list(A, B, on_replace="delete"):
"""Match two lists of different sizes and return corresponding indice
Parameters
----------
A: list | array, shape (n,)
The values of the first list
B: list | array: shape (m, )
@kingjr
kingjr / banded_ridge.py
Created July 30, 2021 08:06
banded_ridge.py
import numpy as np
from numpy.linalg import multi_dot
from scipy.linalg import svd
from sklearn.linear_model import RidgeCV
from sklearn.model_selection import KFold
def get_from_indices(X, indices):
out = np.zeros_like(X[0])
for idx in np.unique(indices):
@kingjr
kingjr / get_citations.py
Last active July 28, 2021 09:12
get_citations.py
import os
import urllib.request
import subprocess
import pandas as pd # pip install pandas
import betterbib # pip install betterbib
import bibtexparser # pip install bibtexparser
from bibtexparser.bparser import BibTexParser
def fix_duplicated_entries(lines):
@kingjr
kingjr / 2v2_gpu.py
Last active March 31, 2021 09:38
2v2 gpu
class Time2v2():
def __init__(self, metric='cosine', scale=True, to=None):
self.metric = metric
self.to = to
self.scale = scale
def __call__(self, y_true, y_pred):
from torch.nn import CosineSimilarity
from numpy.random import permutation
@kingjr
kingjr / 2v2.py
Last active March 24, 2021 15:08
2v2
import numpy as np
from sklearn.metrics import pairwise_distances
from numpy.random import permutation
from time import time
def cc_2v2(true, pred, metric="cosine"):
assert len(true) == len(pred)
ns = len(true)
first = permutation(ns) # first group of TR
from pathlib import Path
import numpy as np
import mne
import nibabel as nib
import matplotlib.pyplot as plt
def split_parc(xyz, label, n, axis='y'):
axes = dict(x=0, y=1, z=2)
@kingjr
kingjr / revisiting_ding_etal.ipynb
Last active January 28, 2021 15:25
# Cortical tracking of hierarchical linguistic structures in connected speech ... or not?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kingjr
kingjr / hypotheses.py
Created January 27, 2021 14:08
juliette hypotheses
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
fig, axes = plt.subplots(6, 1, sharex=True, sharey=True, figsize=[4, 6])
np.random.seed(1)
hypotheses = (
('No Similarity', np.random.randn(5)/1e1),
@kingjr
kingjr / mask_array.py
Created December 28, 2020 16:51
Fast CPU AUC with regular masked array
import numpy as np
from numba import jit
@jit
def fast_auc(ytrue_sorted):
nfalse = np.zeros(ytrue_sorted.shape[1:])
auc = np.zeros(ytrue_sorted.shape[1:])
n = len(ytrue_sorted)
@kingjr
kingjr / ice_fire.py
Last active June 7, 2021 14:23
ice_fire cmap
from matplotlib.colors import ListedColormap
import colorcet
import numpy as np
ice_fire = np.vstack([
colorcet.cm.fire(np.linspace(1, 0, 127))[:, [2, 1, 0, 3]],
colorcet.cm.fire(np.linspace(0, 1, 127))
])
ice_fire = ListedColormap(ice_fire)
fire = colorcet.cm.fire(np.linspace(0, 1, 127))