Skip to content

Instantly share code, notes, and snippets.

View raphaelvallat's full-sized avatar

Raphael Vallat raphaelvallat

View GitHub Profile
@raphaelvallat
raphaelvallat / anova_mixed.r
Last active March 20, 2018 18:37
Mixed within-between ANOVA in R
library(ez)
library(lsmeans)
library(effsize)
# Load the file
df <- read.csv(file="", head=TRUE, sep=",")
# Choose dependant variable (e.g. reaction time)
df$dv <- df$RT
@raphaelvallat
raphaelvallat / closest_divisor.py
Last active March 10, 2018 02:14
Find the divisor of a number closest to another number
import numpy as np
def find_closest_divisor(n, m):
"""Find the divisor of n closest to m
"""
divisors = np.array([ i for i in range(1, int(np.sqrt(n)+1)) if n % i == 0 ])
divisions = n / divisors
return divisions[np.argmin(np.abs(m - divisions))]
number, divisor = 1024, 100
@raphaelvallat
raphaelvallat / hrf.py
Created March 13, 2018 22:52
Hemodynamic Response Function
# Thanks to http://www.jarrodmillman.com/rcsds/lectures/convolution_background.html
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gamma
def hrf(x):
""" Return values for HRF at given times """
# Gamma pdf for the peak
peak_values = gamma.pdf(x, 6)
# Gamma pdf for the undershoot
@raphaelvallat
raphaelvallat / bruteforce.py
Last active April 22, 2024 20:54
Password brute-force in Python
"""
Password brute-force algorithm.
List of most probable passwords and english names can be found, respectively, at:
- https://github.com/danielmiessler/SecLists/blob/master/Passwords/probable-v2-top12000.txt
- https://github.com/dominictarr/random-name/blob/master/middle-names.txt
Author: Raphael Vallat
Date: May 2018
Python 3
@raphaelvallat
raphaelvallat / useful_pandas_snippets.py
Created September 2, 2018 03:12 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
# Convert Series datatype to numeric, changing non-numeric values to NaN
# h/t @makmanalp for the updated syntax!
@raphaelvallat
raphaelvallat / ecg_derived_respiration.ipynb
Last active December 5, 2023 13:45
Extract respiration signal and respiratory rate from ECG using R-R interval.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raphaelvallat
raphaelvallat / spindles_detect.py
Last active September 23, 2018 00:54
A simple and efficient wavelet-based spindles detector
import numpy as np
def spindles_detect(x, sf, perc_threshold=90, wlt_params={'n_cycles': 7, 'central_freq': 'auto'}):
"""Simple spindles detector based on Morlet wavelet.
Parameters
----------
x : 1D-array
EEG signal
sf : float
@raphaelvallat
raphaelvallat / plot_number_publications.ipynb
Last active April 2, 2024 20:13
Plot the number of PubMed publications on a specific topic given a range of years
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@raphaelvallat
raphaelvallat / mutual_info.py
Created February 14, 2019 18:55 — forked from GaelVaroquaux/mutual_info.py
Estimating entropy and mutual information with scikit-learn
'''
Non-parametric computation of entropy and mutual-information
Adapted by G Varoquaux for code created by R Brette, itself
from several papers (see in the code).
These computations rely on nearest-neighbor statistics
'''
import numpy as np
@raphaelvallat
raphaelvallat / distcorr.py
Last active December 12, 2023 06:50 — forked from wladston/distcorr.py
Distance correlation with permutation test
import numpy as np
import multiprocessing
from joblib import Parallel, delayed
from scipy.spatial.distance import pdist, squareform
def _dcorr(y, n2, A, dcov2_xx):
"""Helper function for distance correlation bootstrapping.
"""
# Pairwise Euclidean distances
b = squareform(pdist(y, metric='euclidean'))