Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中的不确定性包:使用给定的协方差矩阵获取数据不确定性_Python_Standard Deviation_Propagation_Uncertainty_Covariance Matrix - Fatal编程技术网

Python中的不确定性包:使用给定的协方差矩阵获取数据不确定性

Python中的不确定性包:使用给定的协方差矩阵获取数据不确定性,python,standard-deviation,propagation,uncertainty,covariance-matrix,Python,Standard Deviation,Propagation,Uncertainty,Covariance Matrix,我相信我的问题很容易理解,但我想说得很清楚,因此这篇文章的篇幅很长 我的初始情况(我在下面总结)与本文()中解释的情况类似,但具体涉及python包如何处理此类情况 情况如下: 我拥有一组数据点,对应于某些测量的标称值(标称值指未考虑任何不确定性的裸值) 每个数据点都有其不确定性,这也提供给了我。此外,由于测量中的一些系统性,不同的数据点不是独立的,而是相互关联的。因此,一个完整的协方差矩阵,非零对角元素给了我 我想做的是用我的数据进行计算,以使不确定性适当传播。最终,我希望在控制台中以

我相信我的问题很容易理解,但我想说得很清楚,因此这篇文章的篇幅很长

我的初始情况(我在下面总结)与本文()中解释的情况类似,但具体涉及python包如何处理此类情况

情况如下:

  • 我拥有一组数据点,对应于某些测量的标称值(标称值指未考虑任何不确定性的裸值)

  • 每个数据点都有其不确定性,这也提供给了我。此外,由于测量中的一些系统性,不同的数据点不是独立的,而是相互关联的。因此,一个完整的协方差矩阵,非零对角元素给了我

我想做的是用我的数据进行计算,以使不确定性适当传播。最终,我希望在控制台中以标称值+/-不确定性的形式显示值。 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)
不是半正定的,它有一个负的特征值。因此,使用它在数学上是不可行的,这是软件包没有注意到的。实际上,包在没有警告或错误消息的情况下使用了这个非法矩阵,当然,生成的输出不能被认为是有意义的,因此出现了意外的行为