The closed-form analytical solution for the entropy of a variable X that follows the t-distribution, derived here, is
Seeing that python has functions scipy.special.digamma
and scipy.special.beta
, how can the above formula be implemented in code?
What confuses me is that the functions just mentioned do not take the degrees of freedom parameter nu (v) as an input according to the documentation. A running example would help
You can also use the differential entropy of multivariate student t-distribution, where, dim is dimensional, dof is degree of freedom and cmtx is covariance.
import numpy as np
import scipy.special as sc
def compute_true_entropy(dim=1, dof=3, std=False):
cmtx = np.identity(dim)
B0 = 0.5*np.log(np.linalg.det(cmtx))
B1 = sc.gamma((dim+dof)/2)/((sc.gamma(dof/2))*((np.pi*dof)**(dim/2)))
B2 = ((dof+dim)/2)*(sc.digamma((dof+dim)/2) - sc.digamma((dof)/2))
entropy = B0 - np.log(B1) + B2
return entropy