本文介绍了例如算法正态分布生成随机值数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想产生一些随机的数字与简单的非均匀概率来模拟逼真的数据用于测试目的。我在寻找接受mu和sigma作为参数,并返回x的可能x是在一定范围内,其中按照一个标准的钟形曲线,或大约一个功能。它不必是超级precise甚至高效。由此产生的数据集不必与准确mu和sigma是我设置的。我只是在寻找一个相对简单的非均匀分布的随机数生成器。限制一组可能的返回值整数就可以了。我见过很多建议在那里,但没有一个似乎适合这个简单的例子。

I'm trying to generate some random numbers with simple non-uniform probability to mimic lifelike data for testing purposes. I'm looking for a function that accepts mu and sigma as parameters and returns x where the probably of x being within certain ranges follows a standard bell curve, or thereabouts. It needn't be super precise or even efficient. The resulting dataset needn't match the exact mu and sigma that I set. I'm just looking for a relatively simple non-uniform random number generator. Limiting the set of possible return values to ints would be fine. I've seen many suggestions out there, but none that seem to fit this simple case.

推荐答案

箱穆勒变换简而言之:

首先,获得两个独立的,统一的随机数从区间(0,1],称他们为U和V。

First, get two independent, uniform random numbers from the interval (0, 1], call them U and V.

然后你就可以得到两个独立的单元正态分布随机数的公式

Then you can get two independent, unit-normal distributed random numbers from the formulae

X = sqrt(-2 * log(U)) * cos(2 * pi * V);
Y = sqrt(-2 * log(U)) * sin(2 * pi * V);

这让你IID随机数亩= 0,标准差= 1;设置标准差= S,用S乘以你的随机数;设置亩= M,加米的随机数。

This gives you iid random numbers for mu = 0, sigma = 1; to set sigma = s, multiply your random numbers by s; to set mu = m, add m to your random numbers.

这篇关于例如算法正态分布生成随机值数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!