def gaussian_function(y, dimension, ?, cov, log=False, standard=False):
"""??????????? y???(???) ??????(?????) cov??????,log????????,standard??????"""
x = y - ?
if standard:
x = np.dot(x, np.linalg.inv(cov) ** 0.5)
cov_ = np.eye(dimension)
else:
cov_ = cov
np.seterr(all='ignore') # ??????
if log:
func = - (dimension / 2) * np.log(2 * math.pi) - 0.5 * np.log(np.linalg.det(cov_))
exp = -0.5 * np.dot(np.dot(x, np.linalg.inv(cov_)), x.T)
return func + exp
else:
sigma = (2 * math.pi) ** (dimension / 2) * np.linalg.det(cov_) ** 0.5
func = 1. / sigma
exp = np.exp(-0.5 * np.dot(np.dot(x, np.linalg.inv(cov_)), x.T))
return func * exp
评论列表
文章目录