2017-10-13 53 views
0

注意:这个问题实际上发生在tensorflow内部,并且导致样本不完全来自真正的pdf。然而,原则是相同的,我的目标是理解下面的警告。从python中的多元规范采样时的正半定误差?

也就是说,我试图从python中的多元正态分布进行采样。那就是

np.random.multivariate_normal(mean = some_mean_vector, cov = some_cov_matrix) 

当然,任何有效的协方差矩阵都必须是正半定的。然而,用于取样(即通过每个测试为阳性半定性)一些协方差矩阵,得到以下警告

/usr/local/lib/python3.6/site-packages/ipykernel/__main__.py:1: RuntimeWarning: covariance is not positive-semidefinite. 

一种这样的基质

A = array([[ 1.00000359e-01, -3.66802835e+00],[ -3.66802859e+00, 1.34643845e+02]], dtype=float32) 

为此,我可以找到两个乔列斯基分解和特征值没有警告(最小特征值是7.42144039e-05)。

任何人都可以帮助并告诉我为什么会发生这种情况吗? (在tensorflow中,我只是提供上述矩阵的cholesky分解,并接收不精确的样本,这混淆了我试图做的所有事情)。

回答

1

对此pull request的讨论具有关于触发此警告的一些信息。据the source

# Also check that cov is positive-semidefinite. If so, the u.T and v 
    # matrices should be equal up to roundoff error if cov is 
    # symmetrical and the singular value of the corresponding row is 
    # not zero. We continue to use the SVD rather than Cholesky in 
    # order to preserve current outputs. Note that symmetry has not 
    # been checked. 

看来,你的情况根据SVD和乔莱斯基测试得出不同的结果。