To generate samples with multivariate t-distribution I use this function:
def multivariatet(mu,Sigma,N,M):
'''
Output:
Produce M samples of d-dimensional multivariate t distribution
Input:
mu = mean (d dimensional numpy array or scalar)
Sigma = scale matrix (dxd numpy array)
N = degrees of freedom
M = # of samples to produce
'''
d = len(Sigma)
g = np.tile(np.random.gamma(N/2.,2./N,M),(d,1)).T
Z = np.random.multivariate_normal(np.zeros(d),Sigma,M)
return mu + Z/np.sqrt(g)
but what I am looking for now is the multivariate student t-distribution it self so I can calculate the density of elements where dimension > 1
.
That will be something like stats.t.pdf(x, df, loc, scale)
of the package scipy but in multi-dimensional space.
I coded the density by myself:
I tried the above answers and got different results from each, but I'm not sure why/what might be wrong. The following, which I based on the scikit-learn code for Gaussian mixtures, I think works (for arbitrary sized input numpy arrays X, and c t-distributions with parameters in lists means and covars):
This evaluates the log pdf of the multivariate student-T distribution for n by d data matrix X:
I generalized @farhawa's code to allow for multiple entries in
x
(i found that i wanted to query multiple points at once).