Skip to content

Instantly share code, notes, and snippets.

View jcheong0428's full-sized avatar
🥕

Jin Hyun Cheong jcheong0428

🥕
View GitHub Profile
@jcheong0428
jcheong0428 / synchrony04.py
Last active November 9, 2023 14:56
Windowed time lagged cross correlations
# Windowed time lagged cross correlation
seconds = 5
fps = 30
no_splits = 20
samples_per_split = df.shape[0]/no_splits
rss=[]
for t in range(0, no_splits):
d1 = df['S1_Joy'].loc[(t)*samples_per_split:(t+1)*samples_per_split]
d2 = df['S2_Joy'].loc[(t)*samples_per_split:(t+1)*samples_per_split]
rs = [crosscorr(d1,d2, lag) for lag in range(-int(seconds*fps),int(seconds*fps+1))]
@jcheong0428
jcheong0428 / synchrony05.py
Last active November 25, 2021 16:14
Dynamic Time Warping example
from dtw import dtw,accelerated_dtw
d1 = df['S1_Joy'].interpolate().values
d2 = df['S2_Joy'].interpolate().values
d, cost_matrix, acc_cost_matrix, path = accelerated_dtw(d1,d2, dist='euclidean')
plt.imshow(acc_cost_matrix.T, origin='lower', cmap='gray', interpolation='nearest')
plt.plot(path[0], path[1], 'w')
plt.xlabel('Subject1')
plt.ylabel('Subject2')
@jcheong0428
jcheong0428 / synchrony06
Created May 13, 2019 06:53
Instantaneous phase synchrony
from scipy.signal import hilbert, butter, filtfilt
from scipy.fftpack import fft,fftfreq,rfft,irfft,ifft
import numpy as np
import seaborn as sns
import pandas as pd
import scipy.stats as stats
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
@jcheong0428
jcheong0428 / synchrony_tutorial.ipynb
Last active October 18, 2024 16:32
Synchrony tutorial notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jcheong0428
jcheong0428 / synchrony_sample.csv
Created May 13, 2019 13:53
Sample Data for Synchrony Tutorial
S1_Joy S2_Joy
1.662181 0.6112171999999999
1.584762 0.6978757
1.413029 1.19836
1.99548 0.9504414
1.981835 0.6698406
2.159827 -0.0786763
1.727152 -0.0233572
1.90065 0.4239428
1.627397 0.7201727
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jcheong0428
jcheong0428 / hungarian1.py
Created July 14, 2019 05:46
First gist for Hungarian post.
# First gist for Hungarian post.
# Brute force estimation of optimal assignment for given preference.
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context('talk')
sns.set_style('white')
import itertools
import numpy as np
@jcheong0428
jcheong0428 / hungarian2.py
Created July 14, 2019 05:53
Estimates the time needed for brute force optimal assignment for group size 10.
%%timeit
# Second gist for Hungarian post.
# Estimates the time needed for brute force optimal assignment for group size 10.
# Takes about 3 minutes.
maxsums, colixs = [], []
group_size = 10
np.random.seed(0)
preferences = np.random.rand(group_size,group_size)
rowix = list(range(group_size)) # rows don't need to be permuted
@jcheong0428
jcheong0428 / hungarian3.py
Created July 14, 2019 06:06
Hungarian algorithm for preference maximization
%%timeit
# Third gist for Hungarian post.
# Estimates the time needed for Hungarian algorithm optimal assignment for group size 10.
# Hungarian algorithm below is adopted from Scipy: https://github.com/scipy/scipy/blob/v0.18.1/scipy/optimize/_hungarian.py
###########
# Hungarian algorithm (Kuhn-Munkres) for solving the linear sum assignment
# problem. Taken from scikit-learn. Based on original code by Brian Clapper,
# adapted to NumPy by Gael Varoquaux.
# Further improvements by Ben Root, Vlad Niculae, and Lars Buitinck.
#
require(MASS)
# Generage fake data for male
data_male <- data.frame(mvrnorm(n=1000,mu=c(2,0),Sigma=rbind(c(1,.8),c(.8,1)),empirical=TRUE ) )
colnames(data_male)<-c('Income','Age')
data_male$Gender = 'Male'
# Generate fake data for female
data_female <- data.frame(mvrnorm(n=1000,mu=c(3,0),Sigma=rbind(c(1,.3),c(.3,1)),empirical=TRUE ))
colnames(data_female) <- c('Income','Age')
data_female$Gender = 'Female'
# Combine data