Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 如何产生一系列接通时间服从二项式分布的脉冲?_Algorithm_Binomial Cdf - Fatal编程技术网

Algorithm 如何产生一系列接通时间服从二项式分布的脉冲?

Algorithm 如何产生一系列接通时间服从二项式分布的脉冲?,algorithm,binomial-cdf,Algorithm,Binomial Cdf,我有一个简单的问题: 我试图模拟一系列数字脉冲(最大值=1,最小值=0)。接通时间的分布应遵循二项分布。我该怎么做?我正在使用VisualStudio 2012。这是一个非常琐碎的问题,我并不想浪费任何人的时间,但由于某种原因,当我思考这个问题时,我的大脑不工作。我需要生成一个非常大的数据集(300Mb) 谢谢 如果visual studio的本机RNG生成0到M-1之间的整数,请计算K=p*M。生成任意数量的随机数,并在K处设置阈值,以获得二进制随机脉冲 另一种方式是: 对于每个可能的字节(总

我有一个简单的问题:

我试图模拟一系列数字脉冲(最大值=1,最小值=0)。接通时间的分布应遵循二项分布。我该怎么做?我正在使用VisualStudio 2012。这是一个非常琐碎的问题,我并不想浪费任何人的时间,但由于某种原因,当我思考这个问题时,我的大脑不工作。我需要生成一个非常大的数据集(300Mb)


谢谢

如果visual studio的本机RNG生成0到M-1之间的整数,请计算K=p*M。生成任意数量的随机数,并在K处设置阈值,以获得二进制随机脉冲

另一种方式是:

对于每个可能的字节(总共256个字节),计算1的数量。创建两组字节A和B(可能大小不等),使p=0.5*一(A)的概率+0.5*一(B)的概率。现在,随时随机选择一个集合(a或B),然后从集合中随机选择一个元素。这样,每产生一个随机数,就有8个脉冲


注:p是1s的预期概率。

这显示了如何生成紧跟在a之后的数字

我编辑了微软的例子,试图给变量更好的命名,使其更易于阅读

我对概率和统计学的理解正在减弱,因为我已经很久没有使用它了,所以我希望这是正确的

#include <random> //include the random number library
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{ 
    mt19937 rng; //create an instance of the Mersenne Twister PRNG
    binomial_distribution<int, double> binomDistribution(2, 0.6); //create distribution using t=2 and p= 0.6
    auto randomNumber = rng(); //get a random number from the RNG
    auto binDistValue = binomDistribution(rng); //get a binomial distributed number from the RNG

    std::cout << "p == " << binomDistribution.p() << std::endl; 
    std::cout << "t == " << binomDistribution.t() << std::endl; 

    binomDistribution.reset(); // discard any cached values 

    const auto valuesToPrint = 100;
    cout << "First " << valuesToPrint << " values of the binomial distribution are:" << endl;
    for(int i=0; i<valuesToPrint; ++i)
    {
        auto aSampledValue = binomDistribution(rng);
        cout << aSampledValue << endl;
    }    

    return (0); 
}
#包含//包含随机数库
#包括
使用名称空间std;
int main(int argc,char*argv[])
{ 
mt19937 rng;//创建Mersenne Twister PRNG的实例
二项式分布二项式分布(2,0.6);//使用t=2和p=0.6创建分布
auto randomNumber=rng();//从rng获取一个随机数
auto binDistValue=binomDistribution(rng);//从rng中获取一个二项式分布数

STD:谢谢。我用C++。你使用的类文件有详细的文档吗?微软的文档不是NoOB友好的。@ AudilLaMax可以澄清吗?你是统计NOOB,C++ NoOB,还是其他NoOB的味道?个人来说,我是统计NOOB,因为我使用PROB和STATS已经很久了。我将编辑SOM。将评论输入到Microsoft示例中。谢谢。我正在尝试解析您所说的内容。(这里是Noob)。@antillamaximus我对第二部分不太清楚。请随时询问更多信息。