我很难将多元高斯分布拟合到我的数据集,更具体地说,找到一个平均向量(或多个平均向量)。我的数据集是一个nx8矩阵,目前我正在使用以下代码:
muVector = np.mean(Xtrain, axis=0)
其中Xtrain是我的训练数据集。在
对于协方差,我使用任意方差值(.5)构建它,并执行以下操作:
covariance = np.dot(.5, np.eye(N,N)
其中N是观察数。在
但当我构造φ矩阵时,我得到的都是零。这是我的代码:
muVector = np.mean(Xtrain, axis=0)
# get covariance matrix from Xtrain
cov = np.dot(var, np.eye(N,N))
cov = np.linalg.inv(cov)
# build Xtrain Phi
Phi = np.ones((N,M))
for row in range(N):
temp = Xtrain[row,:] - muVector
temp.shape = (1,M)
temp = np.dot((-.5), temp)
temp = np.dot(temp, cov)
temp = np.dot(temp, (Xtrain[row,:] - muVector))
Phi[row,:] = np.exp(temp)
感谢任何帮助。我想我得用np.随机.多元正态分布()? 但我不知道在这种情况下如何使用它。在
我相信“Phi”是指你想要估计的概率密度函数(pdf)。在这种情况下,协方差矩阵应为MxM,输出功率因数为Nx1:
或者,您可以使用
^{pr2}$scipy.stats.multivariate_normal
中的pdf
方法:Phi
和{相关问题 更多 >
编程相关推荐