简体   繁体   English

如何在 Python 中计算导出量的误差

[英]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) .我有两个量xy以及它们的协方差矩阵cov(x,y) ,我想计算导出量z=1/(xy)的误差。 Is there is a package to calculate mean value of z and sigma(xz) and sigma(zy) ?是否有一个包来计算zsigma(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.假定yx服从正态分布,导出的数量通常不服从正态分布。 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.

相关问题 Python Pandas:根据价格和数量计算收入 - Python pandas: calculate revenue from price and quantity 如何从子产品数量计算集合产品数量? - How to calculate set product quantity from subproduct quantity? 如何为每个地区的每一年做一个堆积条形图来计算 Quantity_Sold 的总和(或平均值)? Python - How to do a Stacked Barplot for each Year per Region to calculate the sum(or average) of Quantity_Sold? Python 自定义派生数量的 KeyError - KeyError with custom derived quantity 如何基于python pandas中的日期计算年龄? 数据类型错误 - How to calculate age based on date in python pandas? Data types errors 如何在此LSTM示例代码中将可训练参数数量计算为335872? - How to calculate the trainable param quantity to be 335872 in this LSTM sample code? 如何使用 Pandas 计算两个日期之间的工作日数 - How to calculate the quantity of business days between two dates using Pandas 如何打印 Python 列表中相同元素的数量? - How to print quantity of identical elements in a list in Python? Python-如何在Pinax Stripe订阅中传递数量? - Python - How to pass quantity in Pinax Stripe subscription? 如何找到python方法所需的参数数量 - how to find required arguments quantity for python method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM