Python中的不确定性包:使用给定的协方差矩阵获取数据不确定性
我相信我的问题很容易理解,但我想说得很清楚,因此这篇文章的篇幅很长 我的初始情况(我在下面总结)与本文()中解释的情况类似,但具体涉及python包如何处理此类情况 情况如下:Python中的不确定性包:使用给定的协方差矩阵获取数据不确定性,python,standard-deviation,propagation,uncertainty,covariance-matrix,Python,Standard Deviation,Propagation,Uncertainty,Covariance Matrix,我相信我的问题很容易理解,但我想说得很清楚,因此这篇文章的篇幅很长 我的初始情况(我在下面总结)与本文()中解释的情况类似,但具体涉及python包如何处理此类情况 情况如下: 我拥有一组数据点,对应于某些测量的标称值(标称值指未考虑任何不确定性的裸值) 每个数据点都有其不确定性,这也提供给了我。此外,由于测量中的一些系统性,不同的数据点不是独立的,而是相互关联的。因此,一个完整的协方差矩阵,非零对角元素给了我 我想做的是用我的数据进行计算,以使不确定性适当传播。最终,我希望在控制台中以
- 我拥有一组数据点,对应于某些测量的标称值(标称值指未考虑任何不确定性的裸值)
- 每个数据点都有其不确定性,这也提供给了我。此外,由于测量中的一些系统性,不同的数据点不是独立的,而是相互关联的。因此,一个完整的协方差矩阵,非零对角元素给了我
import uncertainties
import numpy as np
# To settle ideas, here are two different covariance matrices with same diagonals
# -> I expect them to lead to the same std deviations below, but this is not the case:
Cov_matrix1 = np.array([[0.00, 0.0, 0.0], [0.0, 1, 0], [0.0, 0, 4]], np.float64)
Cov_matrix2 = np.array([[0.00, 0.5, 3], [0.5, 1, 0.2], [3, 0.2, 4]], np.float64)
# here are some initial nominal values:
data_nominal = np.array([1, 2, 3], np.float64)
print(" The nominal values of data, whithout covariance matrix is ", data_nominal)
# I impose correlations in my data, using the above covariance matrices
correlated_data1 = np.asarray(uncertainties.correlated_values(data_nominal, Cov_matrix1))
correlated_data2 = np.asarray(uncertainties.correlated_values(data_nominal, Cov_matrix2))
# I print my data in the console, and see that data points have different uncertainties in both cases,
# even though the two covariance matrices have the same diagonals ... What is happening ?
print("\n First covariance matrix is ")
print(Cov_matrix1)
print("\n Data values are ", correlated_data1)
print("\n 2nd covariance matrix is ")
print(Cov_matrix2)
print("\n Data values are now ", correlated_data2)
我认为问题在于其中一个协方差矩阵是“非法的”,从这个意义上说
Cov_matrix2 = np.array([[0.00, 0.5, 3], [0.5, 1, 0.2], [3, 0.2, 4]], np.float64)
不是半正定的,它有一个负的特征值。因此,使用它在数学上是不可行的,这是软件包没有注意到的。实际上,包在没有警告或错误消息的情况下使用了这个非法矩阵,当然,生成的输出不能被认为是有意义的,因此出现了意外的行为