使用 Python 生成指数威布尔分布的随机样本

发布于 2025-01-19 08:14:55 字数 323 浏览 0 评论 0原文

对于运行此 scipy 函数 的分布来检测指数威布尔分布的最佳拟合,并且该函数输出 4 个参数值。但是如何生成遵循这种分布的大小为 n 的数据示例列表列表。

我不想重写函数。任何执行此操作的 python 包都会有所帮助。

输入图片此处描述

For a distribution for running this scipy function to detect the best fit as Exponentiated Weibull distribution and the function outputs 4 parameter values. But how to generate a sample list of data of size n that honours this kind of distribution.

I don't want to re-write function. Any python package which does this, would be helpful.

enter image description here

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

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

发布评论

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

评论(1

攀登最高峰 2025-01-26 08:14:55

通常,您将使用ppf从Rando种子生成。

对于一个简单的完全假的示例,假设我们将一个统一的随机变量(值从0到15)拟合到Weibull分布。然后,创建一个种子随机变量(从0到1,因为它是您将获得的分位数的值),然后将其放入ppf函数中。

import scipy.stats as st
import numpy as np
# fitting part
samples = np.random.rand(10000)*15
dist = st.exponweib.fit(samples)
# generation part
sample_seed = np.random.rand(10000)
random_exponweib_samples = st.exponweib.ppf(sample_seed, *dist)
# plotting
import matplotlib.pyplot as plt
plt.hist(samples, label="uniform", alpha=.5)
plt.hist(random_exponweib_samples, label="exponweib", alpha=.5)
plt.legend()
plt.show()

您将拥有类似以下内容。

请小心,并检查有关Weibull Distrubiton的ppf的文档。在我的函数st.exponweib.ppf中它的形式可能是不正确的。

Usually you will use a ppf to generate from a rando seed.

For a simple completely fake example, let's say we fit a uniform random variable (with values from 0 to 15) to a Weibull distribution. Then, create a seed random variable (from 0 to 1 because it's the value of the quantiles that you will get) and put it in the ppf function.

import scipy.stats as st
import numpy as np
# fitting part
samples = np.random.rand(10000)*15
dist = st.exponweib.fit(samples)
# generation part
sample_seed = np.random.rand(10000)
random_exponweib_samples = st.exponweib.ppf(sample_seed, *dist)
# plotting
import matplotlib.pyplot as plt
plt.hist(samples, label="uniform", alpha=.5)
plt.hist(random_exponweib_samples, label="exponweib", alpha=.5)
plt.legend()
plt.show()

You'll have something like the following.
enter image description here

Please be careful and check for the documentation of the ppf concerning the weibull distrubiton. In my function st.exponweib.ppf(sample_seed, *dist) I just use *dist but it might be the case that the parameters should be sent differently, you can see it with the form of the orange plot which might not be correct.

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