Skip to content

Instantly share code, notes, and snippets.

Alex Williams ahwillia

Block or report user

Report or block ahwillia

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View cca.py
import numpy as np
from sklearn.utils.extmath import randomized_svd
def partial_whiten(X, alpha, eigval_tol=1e-7):
"""
Return regularized whitening transform for a matrix X.
Parameters
----------
@ahwillia
ahwillia / circ_regression.py
Last active Jan 16, 2020
Linear Regression with a circular dependent variable
View circ_regression.py
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats
normcdf = scipy.stats.norm.cdf
normpdf = scipy.stats.norm.pdf
from scipy.linalg import cho_factor, cho_solve
from sklearn.base import BaseEstimator
@ahwillia
ahwillia / kron_vec_product.py
Last active Nov 6, 2019
Efficient computation of a Kronecker - vector product (with multiple matrices).
View kron_vec_product.py
import numpy as np
import numpy.random as npr
from functools import reduce
# Goal
# ----
# Compute (As[0] kron As[1] kron ... As[-1]) @ v
# ==== HELPER FUNCTIONS ==== #
@ahwillia
ahwillia / kronshuff.py
Last active Oct 21, 2019
Kronecker vector product via Shuffle algorithm
View kronshuff.py
"""
References:
- B. Plateau, On the stochastic structure of parallelism and synchronization models for distributed algorithms.
Perform. Eval. Rev., 13 (1985), pp. 147–154.
- Dayar, T., & Orhan, M. C. (2015). On vector-Kronecker product multiplication with rectangular factors.
SIAM Journal on Scientific Computing, 37(5), S526-S543.
"""
@ahwillia
ahwillia / rojo.py
Last active Aug 29, 2019
Fast solver for a symmetric tridiagonal circulant linear system in Python.
View rojo.py
import numpy as np
from scipy.linalg import solve_circulant, circulant
from numpy.testing import assert_array_almost_equal
import numba
@numba.jit(nopython=True, cache=True)
def rojo_method(c, a, f, x, z):
"""
Solves symmetric, tridiagonal circulant system, assuming diagonal
@ahwillia
ahwillia / bandpass.py
Created Feb 20, 2019
Bandpass filter in python... (I have no idea why scipy does not provide this)
View bandpass.py
def bandpass(x, lowcut, highcut, fs, order=5, axis=-1, kind='butter'):
"""
Parameters
----------
x : ndarray
1d time series data
lowcut : float
Defines lower frequency cutoff (e.g. in Hz)
highcut : float
Defines upper frequency cutoff (e.g. in Hz)
@ahwillia
ahwillia / poiss_tf.py
Created Sep 26, 2018
Computing hessian-vector products in tensorflow
View poiss_tf.py
"""
Computing hessian-vector products in tensorflow.
For simplicity, we demonstrate the idea on a Poisson regression model.
"""
import tensorflow as tf
import numpy as np
from scipy.optimize import minimize
@ahwillia
ahwillia / poiss_reg.py
Last active Sep 26, 2018
Poisson Regression via scipy.optimize
View poiss_reg.py
"""
A simple implementation of Poisson regression.
"""
import numpy as np
from scipy.optimize import minimize
n = 1000 # number of datapoints
p = 5 # number of features
View copy_task.py
# coding: utf-8
# In[1]:
import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as sci
# In[2]:
@ahwillia
ahwillia / bcd_cnmf.py
Created Apr 10, 2018
Convolutive NMF by block coordinate descent
View bcd_cnmf.py
import numpy as np
from tqdm import trange
import matplotlib.pyplot as plt
# TODO: subclass np.ndarray?
class ShiftMatrix(object):
"""
Thin wrapper around a numpy matrix to support shifting along the second
axis and padding with zeros.
You can’t perform that action at this time.