def estimate_cov(self, samples, mean):
"""
Estimate the empirical covariance of the weight vectors, possibly
with regularization.
"""
d = mean.shape[0]
# Accumulate statistics
Sigma = np.zeros((d, d))
for t in range(len(samples)):
zm = samples[t] - mean
Sigma = Sigma + zm.dot(zm.T)
# Normalize factor of estimate
if self._norm_style == 'ML':
norm = 1.0/(len(samples)-1)
elif self._norm_style == 'Trace':
norm = 1.0/np.trace(Sigma)
else:
raise ValueError('Norm style {} not known'.format(self._norm_style))
Sigma = norm*Sigma
# Add diagonal loading term
self.diag_eps = 0.1*np.mean(np.abs(np.linalg.eig(Sigma)[0])) # TODO
return Sigma + self.diag_eps*self._id
评论列表
文章目录