计算高斯误差传播的助手。

SecondaryValue的Python项目详细描述


二次值

Coverage StatusBuild Status

这是一个实用程序,用于简化值及其 使用sympynumpy从符号公式得出的不确定性。

安装

只要一个快速的pip install SecondaryValue就行了。

示例

(很快就会有文件。现在:看看docstrings!)

基本用法

fromSecondaryValueimportSecondaryValue# create a secondary value# the argument can be either a string or a sympy expressionx=SecondaryValue("a*b/sqrt(c)")# Calculate a result value by substi3tuting the keyword arguments# where a keyword agument may consist of (value, error_1, error_2, ...)# and (...) stands for any iterable.result=x(a=(1,20),b=(2,30),c=2)# The calculation returns a numpy array with the length of the longest# keyword argument above: [value, error_1, error_2]# For each error_n the uncertainties error_n of the keyword args above are# used if present. This may be useful to calculate statistical and systemic# errors in one go.print(result)# >> (1.41421356, 35.35533906)# As a goodie, you can print out the gaussian error distribution in# symbolic form. (Works best in Jupyter Notebooks)x.pretty_gauss_propagation('a','b','c')

默认值

为了减少样板文件,可以设置符号的默认替换(有错误)。 这对常数特别有用。

fromSecondaryValueimportSecondaryValue# create a secondary value with default argumentsx=SecondaryValue("a + b",defaults=dict(b=1/2))# this works because `b` is substituted from the defaultsresult=x(b=1/2)print(result)# >> 1.0# As a goodie, you can print out the gaussian error distribution in# symbolic form. (Works best in Jupyter Notebooks)x.pretty_gauss_propagation('a','b','c')

矢量化输入

SecondaryValue支持矢量化输入。作为重击的规则:放置 可以放置标量的iterable(list,np.array)。

只要所有的错误和值都是 标量或具有相同长度。

fromSecondaryValueimportSecondaryValuex=SecondaryValue('a**2+b')x(a=[[1,2,3]],b=1)# >> array([ 2.,  5., 10.])x(a=([1,2,3],1),b=1)# >> (array([ 2.,  5., 10.]), array([2., 4., 6.]))x(a=([1,2,3],[1,2,3]),b=1)# >> (array([ 2.,  5., 10.]), array([ 2.,  8., 18.]))x(a=([1,2,3],[1,2,3]),b=([1,2,3],1))# >> (array([ 2.,  6., 12.]), array([ 2.23606798,  8.06225775, 18.02775638]))# THAT DOES NOT WORK:x(a=([1,2,3],[1,2,3]),b=([1,2],1))

如果元组中返回的所有数组都具有相同的形状,则可以 轻松地将元组转换为numpy数组: np.array(x(a=([1,2,3], [1,2,3]), b=([1,2,3], 1)))

依赖性

为了简化复杂值的计算,可以定义 依赖于aSecondaryValue

fromSecondaryValueimportSecondaryValuedep=SecondaryValue('u')x=SecondaryValue("a + b",dependencies=dict(a=dep))# x will now accept u as an additional kwarg and calculate d==dep on the fly# and return a dictionary containing it as a second return value if you# specify `retdeps=True`.print(x(b=1,u=(1,2),retdeps=True))# >> ((2.0, 2.0), {'a': ((1.0, 2.0), {})})# To make the output predictable, the dependencies aren't returned by deafult.print(x(b=1,u=(1,2)))# >> (2.0, 2.0)# you can overwrite the dependency calculationprint(x(b=1/2,a=1/2))# >> 1.0

如果没有依赖项值,则当 retdeps=True已指定。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaPax考试:从非标准Maven存储库解析Karaf特性存储库(XML文件)   java Spring启动Bean创建异常   java中将ArrayList转换为数组的方法   Android Studio的java Unity插件。   java在CheckStyle中从方法计数中排除getter和setter   HibernateJava。sql。SQLSyntaxErrorException:表/视图“序列”不存在   与命令行程序Java vs C通信   java WebView膨胀异常   java在O(n)java8流中寻找两个列表的交集   java使用Gradle运行单元测试时,最大堆大小在哪里设置?   ssl加载java应用程序(CXF)内的jks文件   CI:Jenkins Git:Simple Java项目:希望在特定时间在脚本上发送消息   java根据位置更改数字   java按数值排序字符串数组   macos java版本“1.6.0_65”是否与java 6模棱两可?   Cassandra中的java时间戳