Skip to content

Instantly share code, notes, and snippets.

View JesseLivezey's full-sized avatar

Jesse Livezey JesseLivezey

View GitHub Profile
@JesseLivezey
JesseLivezey / plot
Created June 9, 2021 20:18
population plot
import numpy as np
import matplotlib.pyplot as plt
pops = np.array([39538223,
29145505,
21538187,
20201249,
13011844,
12812508,
11799448,
@JesseLivezey
JesseLivezey / figure.py
Created May 26, 2018 17:38
Example figure creation
# All sizes are in fraction of the figure size
figsize = (6, 7.5)
f = plt.figure(figsize=figsize)
# borders
top_edge = .03
bot_edge = .055
l_edge = .15
r_edge = .01
import numpy as np
import theano
import theano.tensor as T
def numpy_version(prob, cases):
return np.matmul(prob.transpose(2,0,1), cases.T).T
last_dim = 50
dot_dim = 1000
other_dim = 1000
@JesseLivezey
JesseLivezey / fft_comparison.py
Created September 28, 2016 19:58
FFT timing comparison
import numpy as np
from numpy.fft import fft as nfft, ifft as nifft
from accelerate.mkl.fftpack import fft as mfft, ifft as mifft
from pyfftw.interfaces.numpy_fft import fft as wfft, ifft as wifft
import matplotlib.pyplot as plt
import time
start = 3
end = 5
diff = 4*(end-start)+1
@JesseLivezey
JesseLivezey / conv_timing.py
Last active June 13, 2016 20:22
CorrMM OMP and BLAS timings script
#!/usr/bin/env python
import argparse, time, os, subprocess
import numpy as np
import theano
from theano.tensor.nnet.corr import (CorrMM, CorrMM_gradInputs,
CorrMM_gradWeights)
from theano.compat.python2x import OrderedDict
@JesseLivezey
JesseLivezey / constraint4.py
Last active March 31, 2016 16:20
constraint 4 idea
#this is the constraint that makes Pyhy[i,i] > Pyhy[i,j]
def con4(inputArray):
Pyhy_i = inputArray.reshape(n,n)
# get diagonal vector (Pyhy[i,i])
Pyhy_diag = np.diag(Pyhy_i)
# get max of each row
Pyhy_max = Pyhy.max(axis=1)
# we want the difference to be positive or zero
diff = Pyhy_diag - Pyhy_max
# we want all of the differences to be positive, so we can just return the most negative one
@JesseLivezey
JesseLivezey / corrcoef.py
Created March 10, 2016 01:14
Calculate 1xn corrcoef
def corrcoef(X, Y):
"""
Return Pearson correlation coefficients between 1 and n variables.
Parameters
----------
X : (1 x dim) matrix, single voxel
Y : (n x dim) matrix, other voxels
"""
X_no_mean = X - X.mean(keepdims=True)
@JesseLivezey
JesseLivezey / utils.py
Created February 2, 2016 16:59
Masked array change for loglikelihood in pykalman/utils.py
def log_multivariate_normal_density(X, means, covars, min_covar=1.e-7):
"""Log probability for full covariance matrices. """
if hasattr(linalg, 'solve_triangular'):
# only in scipy since 0.9
solve_triangular = linalg.solve_triangular
else:
# slower, but works
solve_triangular = linalg.solve
n_samples, n_dim = X.shape
nmix = len(means)