def BIC(self,x,y,tau=None):
'''
Computes the Bayesian Information Criterion of the model
'''
## Get information from the data
C,d = self.mean.shape
n = x.shape[0]
## Initialization
if tau is None:
TAU=self.tau
else:
TAU=tau
## Penalization
P = C*(d*(d+3)/2) + (C-1)
P *= sp.log(n)
## Compute the log-likelihood
L = 0
for c in range(C):
j = sp.where(y==(c+1))[0]
xi = x[j,:]
invCov,logdet = self.compute_inverse_logdet(c,TAU)
cst = logdet - 2*sp.log(self.prop[c]) # Pre compute the constant
xi -= self.mean[c,:]
temp = sp.dot(invCov,xi.T).T
K = sp.sum(xi*temp,axis=1)+cst
L +=sp.sum(K)
del K,xi
return L + P
评论列表
文章目录