[英]Usage of package ‘Brobdingnag’ in R language
I'm running into problems regarding the usage of the Brobdingnag package - after setting我遇到了有关使用 Brobdingnag package 的问题 - 设置后
a2 <- as.brob(0.1)^1000,
a2 = exp(-2302.6) a2 = exp(-2302.6)
a1 <- as.brob(0.1)^800,
a1 = exp(-1842.1) a1 = exp(-1842.1)
I get different results for using sum(a1,a2) and sum(a2,a1) - Each time the result equals the first argument given to the sum function.使用 sum(a1,a2) 和 sum(a2,a1) 得到不同的结果 - 每次结果等于给和 function 的第一个参数。 It seems that maybe sum is not overrided by the Brobdingang package even though its supposed to?
似乎总和没有被 Brobdingang package 覆盖,即使它应该是? Or maybe i'm doing something wrong?
或者也许我做错了什么?
I asked this question also as a reply to another question I wrote, see here我也问了这个问题作为对我写的另一个问题的答复,请参见此处
[EDIT: Answer from author of the package] [编辑:包作者的回答]
Hi Dan嗨丹
This is definitely a bug in the package;这绝对是 package 中的错误; thank you for the report, Unfortunately.
谢谢你的报告,不幸的是。 correcting it will take me some considerable time.
纠正它需要我相当长的时间。
In the meantime, please find below the usual R idiom for calculating the sum of two brobs:同时,请在下面找到用于计算两个 brobs 之和的常用 R 习语:
> a1 <- as.brob(0.1)^800
> a2 <- as.brob(0.1)^1000
> a1+a2
> a1 <- as.brob(0.1)^800
> a2 <- as.brob(0.1)^1000
> a1+a2
[1] +exp(-1842.1)
> a2+a1
[1] +exp(-1842.1)
> sum(cbrob(a1,a2))
[1] +exp(-1842.1)
> sum(cbrob(a2,a1))
[1] +exp(-1842.1)
>
I can reproduce your issue with the following code.我可以使用以下代码重现您的问题。 One answer might be to
+
instead of sum
.一个答案可能是
+
而不是sum
。 Added: Another would be to have your data in a vector before doing the sum补充:另一个是在求和之前将您的数据放在一个向量中
> library(Brobdingnag)
> (a1 <- as.brob(0.1)^800)
[1] +exp(-1842.1)
> (a2 <- as.brob(0.1)^1000)
[1] +exp(-2302.6)
>
> a1 + a2
[1] +exp(-1842.1)
> a2 + a1
[1] +exp(-1842.1)
>
> sum(a1, a2)
[1] +exp(-1842.1)
> sum(a2, a1)
[1] +exp(-2302.6)
>
> sum(as.brob(0.1)^c(1000,800))
[1] +exp(-1842.1)
> sum(as.brob(0.1)^c(800,1000))
[1] +exp(-1842.1)
It seems to be that you cannot use sum(,)
like that.似乎您不能像这样使用
sum(,)
。 Here are some similar strange results with more practical numbers这里有一些类似的奇怪结果,有更实用的数字
> as.brob(0.1) + as.brob(1) # OK, gives exp(ln(1.1))
[1] +exp(0.09531)
> as.brob(1) + as.brob(0.1) # OK, gives exp(ln(1.1))
[1] +exp(0.09531)
> sum(as.brob(c(0.1, 1))) # OK, gives exp(ln(1.1))
[1] +exp(0.09531)
> sum(as.brob(c(1, 0.1))) # OK, gives exp(ln(1.1))
[1] +exp(0.09531)
>
> sum(as.brob(0.1), as.brob(1)) # not OK, gives first term exp(ln(0.1))
[1] +exp(-2.3026)
> sum(as.brob(1), as.brob(0.1)) # not OK, gives first term exp(ln(1))
[1] +exp(0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.