如何在numpy.random.beta(alpha,beta)和scipy.stats.beta(alpha,beta,beta,loc,scale)之间关联beta分布的alpha和beta参数?

发布于 2025-02-07 05:40:08 字数 814 浏览 4 评论 0 原文

我正在使用Numpy分布来生成Montecarlo模拟的随机数,并且用于将分布拟合到结果的拟合库。问题在于,拟合参数将作为4个参数(a,b,loc,scale)相应地返回到Scipy库,我需要找到Numpy(a,b)的等效参数。

如果我安装了scipy.stats.beta(a,b,loc = 0,比例= 1)(蓝线)(蓝线)等于numpy.random.beta(a,b)(bars)

我尝试将它们与scify.stats.beta.fit(x,floc = 0,fscale = 1)

适应>数据。 “ beta”的最大似然估计需要0< (x -loc)/scale< 1对于 data 中的每个x。

如果我不将Floc设置为0,而FSCALE则将1返回结果: [147.1,147.06,-23.56,137.13]是a,b,loc,比例。

如何将它们转换为AA,B,LOC = 0,比例= 1?

我的问题是,我正在创建一个软件,在该软件中,用户在概率分布之后创建输入变量,执行蒙特卡洛模拟并获取输出变量的结果。我正在对这些变量进行分配的拟合,并需要以相同格式将拟合参数返回最初输入它们。如果用户使用alpha和beta参数在beta分布之后创建变量,则我无法将它们返回4个参数来模拟beta分布。 我已经能够使用所需的其他分布来完成它,但是我与Beta堆在一起

I'm using numpy distributions for generating random numbers for montecarlo simulations and Fitter library for fitting distributions to results. The problem is that the fitted parameters are returned accordingly to scipy library as 4 parameters (a, b, loc, scale) and I need to find the equivalent parameters for numpy (a,b).

If I fit a scipy.stats.beta(a,b,loc=0, scale=1)(blue line) it is equal to a numpy.random.beta(a,b)(bars)

I've tried to fit them with scify.stats.beta.fit(x, floc=0, fscale=1) and I get the following error:

scipy.stats._continuous_distns.FitDataError: Invalid values in data. Maximum likelihood estimation with 'beta' requires that 0 < (x - loc)/scale < 1 for each x in data.

If I don't set floc to 0 and fscale to 1 it returns results like:
[147.1,147.06,-23.56,137.13] which are a,b, loc, scale.

How can I transform them to a a,b,loc=0, scale=1?

My problem is that I'm creating a software in which users create input variables following probability distributions, performs Monte Carlo simulations and get the results of the output variables. I’m performing the fitting to distributions to those variables and need to return the parameters of the fitting to the user in the same format the initially enter them. If user uses alpha and beta parameters to create variables following beta distributions, I cannot return them 4 parameters to simulate a Beta distribution.
I’ve been able to accomplish it with the other distributions I need, but I’m stack with Beta

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流殇 2025-02-14 05:40:08

如果您有参数 a b loc scale> scale for beta分布,则需要使用numpy要生成 n 从发行版中随机示例,您可以写入

sample = loc + scale*np.random.beta(a, b, size=n)  # Legacy random API

或使用较新的(和推荐)API

rng = np.random.default_rng()
sample = loc + scale*rng.beta(a, b, size=n)

,也可以使用 rvs() 的方法scipy.stats.beta

sample = scipy.stats.beta.rvs(a, b, loc=loc, scale=scale, size=n)

If you have the parameters a, b, loc and scale for the beta distribution, and you want to use NumPy to generate n random samples from the distribution, you can write

sample = loc + scale*np.random.beta(a, b, size=n)  # Legacy random API

or, using the newer (and recommended) API

rng = np.random.default_rng()
sample = loc + scale*rng.beta(a, b, size=n)

You could also use the rvs() method of scipy.stats.beta:

sample = scipy.stats.beta.rvs(a, b, loc=loc, scale=scale, size=n)
若言繁花未落 2025-02-14 05:40:08

我有一个概念性问题。将LOC和比例强制为0和1,就像Numpy中一样:

betafun = scipy.stats.beta.fit(values,floc = 0,fscale = 1)

那里的问题是,一系列数字无法调整这样,如果有大于1或小于0的值,因为我精确地将这些限制设置为LOC和比例值,并且代码将返回错误。
如果我需要调整一系列不在0到1范围内的数字,则LOC和比例值不能为0和1。

I was having a conceptual problem. To force loc and scale to be 0 and 1 as in numpy you can do:

betafun = scipy.stats.beta.fit(values, floc=0, fscale=1)

The problem there, is that a series of numbers cannot be adjusted in this way if there are values greater than 1 or less than 0, because I am precisely setting those limits with loc and scale values and the code is going to return an error.
If I need to adjust a series of numbers that are not in the range 0 to 1, the values of loc and scale cannot to be 0 and 1.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文