[英]how to calculate errors in a derived quantity in Python
I have two quantities x
and y
and their covariance matrix cov(x,y)
, and I want to calculate the error in a derived quantity z=1/(xy)
.我有两个量
x
和y
以及它们的协方差矩阵cov(x,y)
,我想计算导出量z=1/(xy)
的误差。 Is there is a package to calculate mean value of z
and sigma(xz)
and sigma(zy)
?是否有一个包来计算
z
和sigma(xz)
和sigma(zy)
平均值?
thank you very much in advance非常感谢你提前
The derived quantity will generally not follow a normal distribution, given that y
and x
does.假定
y
和x
服从正态分布,导出的数量通常不服从正态分布。 You can estimate the error distribution numerically:您可以用数字方式估计误差分布:
import scipy.stats
import numpy as np
import matplotlib.pyplot as plt
# sample from multivariate normal
x = scipy.stats.multivariate_normal(mean=[0,1], cov=[[1,0.5],[0.5,2]]).rvs(10000)
z = 1 / (x[0] - x[1])
print(z.mean())
print(z.var())
# Create kde of the distribution
kde = scipy.stats.gaussian_kde(z)
grid = np.linspace(z.min(), z.max(), 1000)
plt.plot(grid, kde.evaluate(grid))
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.