gpt4 book ai didi

python - 值错误: Domain error in arguments scipy rv_continuous

转载 作者:太空宇宙 更新时间:2023-11-03 16:09:24 25 4
gpt4 key购买 nike

我试图使用 scipy.stats.rv_continuous 对给定概率密度函数(pdf)的随机变量进行采样:

class Distribution(stats.rv_continuous):
def _pdf(self,x, _a, _c):
return first_hitting_time(x, _a, _c)

函数first_hitting_time在哪里

#pdf of first hitting time of W_t + c*t on a. 
def first_hitting_time(_t, _a, _c=0.0):
return _a/_t*np.exp(-0.5/_t*(_a-_c*_t)**2)/np.sqrt(2.0*np.pi*_t)

然后我继续

myrv= Distribution(name='hittingtime', a=0.002,b=30.0)
data3= myrv.rvs(size=10000, _a=1.0, _c=0.0)

口译员开始提示-

Traceback (most recent call last):

File "<ipython-input-246-71f67047462b>", line 1, in <module>
data3= myrv.rvs(size=10000, _a=1.0, _c=0.0)

File "C:\Users\ME\AppData\Local\Continuum\Anaconda2\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 856, in rvs
raise ValueError("Domain error in arguments.")

ValueError: Domain error in arguments.

看来,如果我将 _c 设置为大于 0.0 的某个数字,它就可以正常工作,但对于小于 0 的 _c 则不行。

我对此有点困惑。任何帮助,将不胜感激。

最佳答案

来自the documentation :

Subclassing

New random variables can be defined by subclassing the rv_continuous class and re-defining at least the _pdf or the _cdf method (normalized to location 0 and scale 1).

If positive argument checking is not correct for your RV then you will also need to re-define the _argcheck method.

从你的函数中我不清楚 _a_c 代表什么,但看起来你想让它们为负数。

查看默认实现in the source of _distn_infrastructure

关于python - 值错误: Domain error in arguments scipy rv_continuous,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39420430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com