如何修改任意 scipy.stats 分布以截断它们?

问题描述

这个问题解决了如何从已被截断的 scipy.stats 分布(在本例中为 Maxwell-Boltzmann,易于扩展)中采样 - Getting random numbers from a truncated Maxwell-Boltzmann distribution

现在我想将任意统计分布拟合到一维数据集/直方图。为了论证,让我们将截断的 M-B 分布拟合到上面的采样直方图。否则高斯就可以了。

如何在 scipy 中创建任意分布的截断或其他修改版本,或者如何修改现有分布?

一如既往的感谢

一些示例代码 -

import numpy as np
import scipy.stats as scs
import matplotlib.pyplot as plt

dist=scs.<disTRIBUTION> # dist can be any built-in scipy.stats fn - e.g. scs.rice - but I want to truncate it / modify it arbitrarily; I kNow about trunc_norm but my problem is not restricted to Gaussians

npoints=10000
data=np.random.normal(0.8,0.05,npoints)

nbins=101
bins=np.linspace(0.0,1.0,nbins)
dbin=bins[1]-bins[0]

params=dist.fit(data)
print(params)

# Calculate best-fit curve
x=bins
p = dist.pdf(x,*params)

plt.figure()
plt.plot(x,p/dbin,'k-')

# Sample from fitted distribution
r = dist.rvs(*params,size=npoints)
_=plt.hist(r,bins=bins,color='b',alpha=0.5,density=True)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)