我们已经讨论了集合1中的生成器。我们还讨论了集合2中的三个分布。在本文中,将讨论更多的分布。
IV。基于比率的分布:
poisson_distribution | Poisson Distribution |
exponential_distribution | Exponential Distribution |
gamma_distribution | Gamma Distribution |
weibull_distribution | Weibull Distribution |
extreme_value_distribution | Extreme Value Distribution |
1. poisson_distribution:它是根据泊松分布产生整数的分布,泊松分布由以下概率质量函数:
// Illustrating the use of operator() in
// poisson_distribution
#include
#include
#include
using namespace std;
// Driver Program
int main()
{
// construct a trivial random generator
// engine from a time-based seed:
unsigned seed =
chrono::system_clock::now().time_since_epoch().count();
default_random_engine generator (seed);
poisson_distribution distribution (7.1);
cout << "Poisson-distribution(mean=5.0): ";
for (int i=0; i<10; ++i)
// use of operator()
cout << distribution(generator) << " ";
cout << endl;
return 0;
}
输出:
Poisson-distribution(mean=5.0): 11 5 5 9 10 6 15 3 6 5
2. exponential_distribution :这是一个随机数分布,根据指数分布产生浮点值,由以下公式给出:
// Illustrating the use of operator() in
// exponential_distribution
#include
#include
#include
#include
using namespace std;
// Driver program
int main()
{
// It constructs a trivial random
// generator engine from a time-based seed
int seed =
chrono::system_clock::now().time_since_epoch().count();
default_random_engine generator (seed);
exponential_distribution distribution (1.0);
cout << "Hi's separated by 2 seconds, on average: \n";
for (int i=0; i<5; ++i)
{
// use of operator()
double number = distribution(generator);
chrono::duration period (number);
// It makes the thread sleep
// for the time period(i.e. number)
this_thread::sleep_for( period );
cout << "Hi,Geeks!!" << endl;
}
return 0;
}
输出:
Hi's separated by 2 seconds, on average:
Hi,Geeks!!
Hi,Geeks!!
3. gamma_distribution :这是一个随机数分布,根据gamma分布产生浮点值,由以下公式给出:
// Illustrating the use of reset in gamma_distribution
#include
#include
using namespace std;
// Driver program
int main()
{
// Random number generator
default_random_engine generator;
gamma_distribution distribution(1.0,2.0);
// prints first random number
cout << distribution(generator) << endl;
// use of reset
distribution.reset();
// prints the second random number
// independent of first
cout << distribution(generator) << endl;
return 0;
}
输出:
1.14392
2.23359
4. weibull_distribution :这是一个随机数分布,根据2参数的Weibull分布产生浮点值,给定:
// Illustrating the use of min and max
// in weibull_distribution
#include
#include
#include
using namespace std;
// Driver program
int main ()
{
// It constructs a trivial random
// generator engine from a time-based seed
unsigned seed =
chrono::system_clock::now().time_since_epoch().count();
default_random_engine generator (seed);
weibull_distribution distribution (2.0,1.0);
cout << distribution(generator)
<< " is a random number between ";
// use of min and max
cout << generator.min() << " and " << generator.max();
return 0;
}
输出:
1.54229 is a random number between 1 and 2147483646
5. extreme_value_distribution :这是一个随机数分布,根据I类极端值分布产生浮点值,给定:
// Illustrating the use of param in
// extreme_value_distribution
#include
#include
using namespace std;
// Driver program
int main()
{
default_random_engine generator;
extreme_value_distribution d1(2.0,4.0);
extreme_value_distribution d2(d1.param());
// prints the first value
cout << d1(generator) << endl;
// prints the second independent value
cout << d2(generator) << endl;
return 0;
}
输出:
9.8351
3.95306
五,与正态分布有关
normal_distribution | Normal Distribution |
lognormal_distribution | Lognormal Distribution |
chi_squared_distribution | Chi-squared Distribution |
cauchy_distribution | Cauchy Distribution |
fisher_f_distribution | Fisher F-Distribution |
student_t_distribution | Student T-Distribution |
1. normal_distribution :这是一个随机数分布,根据正态分布产生浮点值,由下式给出:
where:
(µ) :mean
sigma :standard deviation
// Illustrating the use of operator()
// in normal_distribution
#include
#include
#include
using namespace std;
// Driver program
int main()
{
// It constructs a trivial random
// generator engine from a time-based seed
unsigned seed =
chrono::system_clock::now().time_since_epoch().count();
default_random_engine generator (seed);
// Initializes the normal distribution
normal_distribution distribution (1.0,2.0);
cout << "Normal-distribution(1.0,2.0):" << endl;
for (int i=0; i<5; i++)
// Use of operator()
cout << distribution(generator) << endl;
return 0;
}
输出:
Normal-distribution(1.0,2.0):
1.59499
-0.458303
1.34411
0.138838
3.03433
2. lognormal_distribution :这是一个随机数分布,根据对数正态分布产生浮点值,由下式给出:
// Illustrating the use of reset in
// lognormal_distribution
#include
#include
using namespace std;
// Driver program
int main()
{
// the random number generator
default_random_engine generator;
lognormal_distribution distribution(1.0,2.0);
// prints first value:
cout << distribution(generator) << endl;
// Use of reset
distribution.reset();
// prints second value independent of first
cout << distribution(generator) << endl;
return 0;
}
输出:
2.12989
10.6822
3. chi_squared_distribution :这是一个随机数分布,根据卡方分布产生浮点值,给定:
where,
n : degrees of freedom and n>0,
n/2 : shape parameter
// Illustrating the use of operator() in
// chi_squared_distribution
#include
#include
#include
using namespace std;
// Driver program
int main()
{
// It constructs a trivial random
// generator engine from a time-based seed
unsigned seed =
chrono::system_clock::now().time_since_epoch().count();
default_random_engine generator (seed);
chi_squared_distribution distribution (4.0);
cout << "chi-squared-distribution(4.0):" << endl;
for (int i=0; i<5; i++)
// use of operator()
cout << distribution(generator) << endl;
return 0;
}
输出:
chi-squared-distribution(4.0):
2.18701
6.86953
1.77983
9.79626
5.04758
4. cauchy_distribution :这是一个随机数分布,根据Cauchy分布产生浮点值,由下式给出:
where,
a and b are distribution parameters
// Illustrating the use of param
// in cauchy_distribution
#include
#include
using namespace std;
// Driver program
int main()
{
default_random_engine generator;
cauchy_distribution d1(0.0,1.0);
cauchy_distribution d2(d1.param());
// prints the first value
cout << d1(generator) << endl;
// prints the second value
cout << d2(generator) << endl;
return 0;
}
输出:
0.438486
7.65462
5. fisher_f_distribution :这是一个随机数分布,根据Fisher F分布产生浮点值,由下式给出:
它通过划分m和n自由度的两个独立的卡方分布来产生随机数。
// Illustrating the use of
// operator() in fisher_f_distribution
#include
#include
#include
using namespace std;
// Driver program
int main()
{
// It constructs a trivial random generator engine
// from a time-based seed
unsigned seed =
chrono::system_clock::now().time_since_epoch().count();
default_random_engine generator (seed);
fisher_f_distribution distribution (1.0,2.0);
cout << "fisher-f-distribution(1.0,2.0):" << endl;
for (int i=0; i<5; i++)
// use of operator()
cout << distribution(generator) << endl;
return 0;
}
输出:
fisher-f-distribution(1.0,2.0):
0.208066
2.76882
0.0305701
0.96243
0.444256
6. student_t_distribution :这是一个随机数分布,根据Student T分布产生浮点值,由下式给出:
where,
n is the distribution parameter
// Illustrating the use of min and max
// in student_t_distribution
#include
#include
#include
using namespace std;
// Driver program
int main ()
{
// It constructs a trivial random
// generator engine from a time-based seed
unsigned seed =
chrono::system_clock::now().time_since_epoch().count();
default_random_engine generator (seed);
student_t_distribution distribution (8.0);
cout << distribution(generator)
<< " is a random number between ";
// use of min and max
cout << generator.min() << " and " << generator.max();
return 0;
}
输出:
0.00906058 is a random number between 1 and 2147483646