我有以下scipy.stats.rv_continuous
的子类:
from scipy.stats import rv_continuous
import math
class Distribution(rv_continuous):
def _cdf(self, x, a, b, mu):
return (
math.erf(x/(math.sqrt(2)*a)) + \
math.erf((x - mu)/(math.sqrt(2)*b)) \
) / 2 + math.erf(mu/(math.sqrt(2)*b)) / 2
distribution = Distribution(a = 0, b = float('inf'))
据我所知,一切都设置正确(我已经检查了数学,这也是正确的)。但是,出于某种原因,它只想生成0
和mu
之间的值,而不是明确指定的预期的0
和inf
。例如,以下是使用distribution.rvs(3, 1.6, 10)
生成的50个点(以及PDF):
这是distribution.rvs(0.6, 0.4, 4.85)
的一个例子:
为什么我的发行版“限制”在mu
?我设置了我的rv_continuous
子类错了吗?
您对CDF的实施不正确。考虑:
In [188]: distribution.cdf(25, 3, 16., 10)
Out[188]: 1.059763759070757
In [189]: distribution.cdf(40, 3, 16., 10)
Out[189]: 1.203618109186038
这些值不正确。 CDF(您使用_cdf
方法实现)不得超过1.0。