We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
如果您不能/不想使用库:
在这种情况下,最简单的方法是计算 CDF(对照 Wikipedia),即函数 F : x -> P(X<x)。然后,使用您最喜欢的生成器在 [0,1] 上绘制均匀随机数 y,并求解 y = F(x)。这样的 x 的序列是同分布的并且遵循幂律分布。
编辑:答案就在那里
If you can't/don't want to use a library:
In this case, the easiest way to go is to work out the CDF (check it against Wikipedia), that is the function F : x -> P(X < x). Then you draw uniform random numbers y on [0,1] with your favorite generator, and you solve y = F(x). The sequence of such x are identically distributed and follow a Power Law Distribution.
Edit: the answer is there
也许 Colt java 库可以提供帮助。它根据许多分布生成随机数。
Maybe the Colt java library can help. It generates random numbers according to many distributions.
Apache Commons Math lib 在我的系统上非常慢(也许我错过了一些东西......)。这个独立的类 PowerLaw.java 对我有用。
Apache Commons Math lib was quite slow on my system (maybe I missed something...). This standalone class PowerLaw.java worked for me.
这个库: https://github.com/pbloem/powerlaws 包含一个幂律生成器,使用如下:
这会根据幂律分布生成 1000 个点,最小值为 3.14,指数为 2.5。它还具有离散分布和离散分布的连续近似。所有这些分布也可以适合现有数据。
(免责声明:我写了这个库)。
This library: https://github.com/pbloem/powerlaws contains a power law generator, used as follows:
This generates 1000 points from a power law distribution with 3.14 as minimal value and 2.5 as exponent. It also has a discrete distribution and a Continuous approximation of a discrete distribution. All these distribution can also be fit to existing data.
(Disclaimer: I wrote this library).