生成非均匀随机数 [英] Generating non-uniform random numbers

查看:114
本文介绍了生成非均匀随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能告诉我任何生成非均匀随机数的方法吗?
我正在使用Java,但是代码示例可以随心所欲.

Can you tell me any ways to generate non-uniform random numbers?
I am using Java but the code examples can be in whatever you want.

一种方法是通过将两个统一的随机数加在一起(即滚动2个骰子)来创建歪斜分布.

One way is to create a skewed distribution by adding two uniform random numbers together (i.e. rolling 2 dice).

推荐答案

您想要什么分布的偏斜?

What distribution of deviates do you want?

这是一种始终有效的技术,但并不总是最有效的.累积扰动函数P(x)给出值低于x的时间的分数.因此,在x的最小可能值处P(x)= 0,在x的最大可能值处P(x)= 1.每个分布都有一个唯一的CDF,该CDF以P(x)从0上升到1的方式编码扰动的所有属性.如果y在间隔[0,1]上均匀偏离,则x满足P(x )= y将根据您的分布情况进行分配.为了使这项工作变得有益,您只需要一种方法即可计算出分布的P(x)的倒数.

Here is a technique which always works, but isn't always the most efficient. The cumulative distrubtion function P(x) gives the fraction of the time that values fall below x. Thus P(x)=0 at the lowest possible value of x and P(x)=1 at the highest possible value of x. Every distribution has a unique CDF, which encodes all the properties of the distrubtion in the way that P(x) rises from 0 to 1. If y is a uniform deviate on the interval [0,1], then x satisfying P(x)=y will be disributed according to your distribution. To make this work comuptationally, you just need a way computing the inverse of P(x) for your distribution.

Meta.Numerics 库定义了大量常用的离散量(例如,正常,对数正态,指数,卡方等),并具有计算每个CDF和CDF逆CDF的功能.

The Meta.Numerics library defines a large number of commonly used distrubtions (e.g. normal, lognormal, exponential, chi squared, etc.) and has functions for computing the CDF (Distribution.LeftProbability) and the inverse CDF (Distribution.InverseLeftProbability) of each.

适用于快速处理特定干扰的专门技术,例如用于正态分布的Box-Muller技术存在偏差,请参见《数值接收》一书.

For specialized techniques that are fast for particular distrubtions, e.g. the Box-Muller technique for normaly distributed deviates, see the book Numerical Recipies.

这篇关于生成非均匀随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆