根据指数分布生成数据



我想生成一个由30个条目组成的数据集,例如在(50-5000(的范围内,使其遵循一条递增曲线(对数曲线(,即在开始时递增,然后在结束时停滞。

我遇到了from scipy.stats import expon,但我不确定如何在我的场景中使用该包。

有人能帮忙吗。

一个可能的输出看起来像[300, 1000, 1500, 1800, 1900, ...]

首先需要生成30个随机x值(统一(。然后得到log(x)。理想情况下,log(x)应该在[50, 5000)的范围内。但是,在这种情况下,您将需要e^50 <= x <= e^5000(溢出!!(。一种可能的解决方案是在[min_x, max_x)中生成随机x值,得到对数值,然后将其缩放到所需的范围[50, 5000)

import numpy as np
min_y = 50
max_y = 5000
min_x = 1
# any number max_x can be chosen
# this number controls the shape of the logarithm, therefore the final distribution
max_x = 10
# generate (uniformly) and sort 30 random float x in [min_x, max_x)
x = np.sort(np.random.uniform(min_x, max_x, 30))
# get log(x), i.e. values in [log(min_x), log(max_x))
log_x = np.log(x)
# scale log(x) to the new range [min_y, max_y)
y = (max_y - min_y) * ((log_x - np.log(min_x)) / (np.log(max_x) - np.log(min_x))) + min_y

最新更新