This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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))] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%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. | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |