Skip to content

Instantly share code, notes, and snippets.

View mattjj's full-sized avatar

Matthew Johnson mattjj

View GitHub Profile
{
"worksheets": [
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Setting MNIW Priors #\n\nFor an autoregressive model with $k$ lags and parameters $(A,\\Sigma)$, for each time $t$ if we write the vector of lagged observations as $\\tilde{y} \\triangleq (y_{t-1}, y_{t-2}, \\ldots, y_{t-k})$ then we can write the generative model as\n$y | \\tilde{y},A,\\Sigma \\sim \\mathcal{N}(A \\tilde{y}, \\Sigma)$\nso that the likelihood is\n\n$$ p(y|\\tilde{y},A,\\Sigma) \\propto \\exp \\left\\{ -\\frac{1}{2}(y-A\\tilde{y})^T \\Sigma^{-1} (y-A\\tilde{y}) \\right\\}. $$\n\nThe natural conjugate prior over $(A,\\Sigma)$ is the Matrix-Normal-Inverse-Wishart (MNIW) with hyperparameters $(\\nu_0,S_0,M_0,K_0)$, where $(\\Sigma,A) \\sim \\text{MNIW}(\\nu_0,S_0,M_0,K_0)$ if\n\n$$ \\Sigma \\sim \\text{InvWishart}(\\nu_0,S_0) $$\n$$ A | \\Sigma \\sim \\text{MN}(M_0,\\Sigma,K_0). $$\n\nTherefore to set a prior over $(\\Sigma,A)$ we must choose the hyperparameters $(\\nu_0,S_0,M_0,K_0)$.
@mattjj
mattjj / timesince.py
Created February 9, 2014 15:58
timesince
#!/usr/bin/env python
from __future__ import division
import sys
from dateutil.parser import parse
from dateutil.relativedelta import relativedelta
from datetime import datetime
from collections import OrderedDict
# from https://en.wikipedia.org/wiki/Year
@mattjj
mattjj / plots.py
Created March 11, 2014 16:18
milk study plots
from __future__ import division
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import rc, rcParams
np.random.seed(0)
rc('font',**{'family':'sans-serif','sans-serif':['Arial'],'size':16})
def myboxplot(boxdata,pointdata):
@mattjj
mattjj / hmm.py
Last active August 29, 2015 13:57
test separate state sequences
from __future__ import division
import numpy as np
from matplotlib import pyplot as plt
import pyhsmm
from pyhsmm.util.text import progprint_xrange
obs_hypparams = dict(mu_0=np.zeros(2),sigma_0=np.eye(2),kappa_0=0.05,nu_0=4)
### generate data
@mattjj
mattjj / bar.c
Last active August 29, 2015 13:57
#include "bar.h"
void blah(int sz, double *x) {
for (int i=0; i<sz; i++) {
x[i] = (double) 2*i;
}
}
from __future__ import division
from sympy import MatrixSymbol, Matrix, latex, simplify
import baker
def SymmetricMatrix(name,n):
J = Matrix(MatrixSymbol(name,n,n))
for i in range(n):
for j in range(i):
J[i,j] = J[j,i]
return J
from __future__ import division
import baker
from pylab import *
def rand_psd(n):
a = randn(n,n)
return a.dot(a.T)
def ssor_split(J):
# NOTE: J = L + D + U
function A = grid(n,m)
if ~exist('m','var'), m=n; end
A = kron(eye(n),path(m)) + kron(path(n),eye(m));
end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.