使用 MathNet 在 C# 中计算给定指数的幂律分布

发布于 2024-08-27 23:34:40 字数 209 浏览 3 评论 0原文

我目前正在开发一个项目,我需要生成多个值(最好是浮点数或双精度数),这些值遵循给定指数的幂律分布!

有人建议我使用 MathNet.Iridium 库来帮助我。我遇到的问题是文档并不像应该的那样明确(如果有的话)!

我看到多个分布符合幂律分布的一般概念,但我无法确定一个好的分布以某个指数作为参数使用。

有没有人在这方面有更多经验并可以给我一些提示或建议?

I am currently working on a project where I need to generate multiple values (floats or doubles preferably) that follow a power law distribution with a given exponent!

I was advised to use the MathNet.Iridium library to help me. The problem I have is that the documentation is not as explicit as it should be if there is any!

I see multiple distributions that fit the general idea of the power law distribution but I cannot pinpoint a good distribution to use with a certain exponent as a parameter.

Does anybody have more experience in that matter and could give me some hints or advice?

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

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

发布评论

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

评论(1

南风起 2024-09-03 23:34:40

要生成您选择的分布值,您可以使用逆累积分布函数,如 维基百科

一步一步,这看起来像:

  1. 选择您喜欢的分布函数。
  2. 使用笔和纸计算逆累积分布函数。
  3. 根据单位间隔上的均匀分布生成一个值。 Random 在这里会做得很好。
  4. 将值输入到您的 ICDF 中。

结果是使用您选择的分布函数随机选择的值。

如果您在第 2 步中遇到问题,也许 https://mathoverflow.net/ 的人员可以帮助您。

编辑:如果您只需要具有指数伽马的幂律分布,这将生成一个值:

double r = 1.0 / Math.Pow(1-new Random().NextDouble(), 1.0/(gamma+1));

To generate values of a distribution of your choice, you could use the inverse cumulative distribution function, as mentioned in the wikipedia.

Step by step, this would look like:

  1. Choose a distribution function that you like.
  2. Calculate the inverse cumulative distribution function using pen and paper.
  3. Generate a value based on a uniform distribution on the unit interval. Random will do nicely here.
  4. Input the value into your ICDF.

The result is a value chosen at random using your chosen distribution function.

If you run into problems with step 2, maybe the folks at https://mathoverflow.net/ can help you.

Edit: If you just need any power law distribution with exponent gamma, this will generate one value:

double r = 1.0 / Math.Pow(1-new Random().NextDouble(), 1.0/(gamma+1));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文