添加两个泊松计算在sympy上是如此慢
我试图在Sympy上添加两个泊松随机变量。 但是我的计算没有任何回应。
有什么可以算出答案吗?
import sympy as sp
import sympy.stats as ss
x= ss.Poisson("x", 3)
y = ss.Poisson("y", 6)
mixed = x+y
d = ss.density(mixed)
print(sp.N(d(0)))
I tried to add two poisson random variables on sympy.
But my calculation didn't response anything.
Is there anything to calc the answer?
import sympy as sp
import sympy.stats as ss
x= ss.Poisson("x", 3)
y = ss.Poisson("y", 6)
mixed = x+y
d = ss.density(mixed)
print(sp.N(d(0)))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两件事正在减慢评估:
这就是我的方式:用符号替换Infinity,用
lambdify
生成函数并进行评估。如果您选择
n
太大,则会得到以下错误(由于阶乘),例如:There are two things that are slowing down the evaluation:
This is how I would proceed: replace infinity with a symbol, generate a function with
lambdify
and evaluate it.If you choose
n
too large you will get the following error (because of factorial), for example:在这种特殊情况下,您有一个无限的总和,但只有第一项是非零的:
理想情况下,Sympy只能计算出来,但似乎没有明确的处理程序来对这样的零件进行总结。
因此,我们只需要评估第一项:
这等同于要求X和Y都为零的概率:
In this particular case you have an infinite sum but only the first term is nonzero:
Ideally SymPy would just be able to compute that but it does not seem to have explicit handlers for a summation over a Piecewise like this.
We therefore just need to evaluate the first term:
This is equivalent to asking for the probability that x and y are both zero: