Python 如何改变NumPy物流功能的基础?
对于Elo评级系统模拟,我需要从基本sqrt(10)中的物流分布中抽取样本 在NumPy文档中,我发现: 这使用基数“e”中的概率密度: 我需要使用基本sqrt(10)中的概率密度。Python 如何改变NumPy物流功能的基础?,python,python-3.x,numpy,statistics,Python,Python 3.x,Numpy,Statistics,对于Elo评级系统模拟,我需要从基本sqrt(10)中的物流分布中抽取样本 在NumPy文档中,我发现: 这使用基数“e”中的概率密度: 我需要使用基本sqrt(10)中的概率密度。 你知道我该怎么做吗?在检查了一点之后,我确信这在数学上是正确的: def logistic_sample(n, loc = 0, scale = 1, base = np.exp(1)): p = np.random.rand(n) return loc + scale * np.log(p / (
你知道我该怎么做吗?在检查了一点之后,我确信这在数学上是正确的:
def logistic_sample(n, loc = 0, scale = 1, base = np.exp(1)):
p = np.random.rand(n)
return loc + scale * np.log(p / (1 - p)) / np.log(base)
另一种可能性是创建一个新的scipy.stats.rv_continuous
类,如果您确实需要深入研究该分布:
class logistic_base_gen(scipy.stats.rv_continuous):
def _pdf(self, x, loc, scale, base):
return base ** ((loc - x) / scale) / (s * (1 + base ** ((loc - x) / scale)) ** 2)
logistic_base = logistic_base_gen(0)
logistic_base.rvs(loc, scale, np.sqrt(10), size = n)
需要更精通统计学的人来检查,但我想你最好把
ln
改为basesqrt(10)
,然后把p
改为np.random.rand
。
class logistic_base_gen(scipy.stats.rv_continuous):
def _pdf(self, x, loc, scale, base):
return base ** ((loc - x) / scale) / (s * (1 + base ** ((loc - x) / scale)) ** 2)
logistic_base = logistic_base_gen(0)
logistic_base.rvs(loc, scale, np.sqrt(10), size = n)