伯努利分布在数据结构中
伯努利分布是一种离散分布,有两个可能的结果,分别标记为 x = 0 和 x = 1。其中 x = 1 表示成功,x = 0 表示失败。成功的概率为 p,失败的概率为 q(q = 1 – p)。因此
$$P\left( x\right)=\begin{cases}1-p\:for & x = 0\p\:for & x = 0\end{cases}$$
还可以写成 −
$$P\left( x\right)=p^{n}\left(1-p\right)^{1-n}$$
示例
#include <iostream>
#include <random>
using namespace std;
int main(){
const int nrolls=10000;
default_random_engine generator;
bernoulli_distribution distribution(0.7);
int count=0; // count number of trues
for (int i=0; i<nrolls; ++i)
if (distribution(generator))
count++;
cout << "bernoulli_distribution (0.7) x 10000:" << endl;
cout << "true: " << count << endl;
cout << "false: " << nrolls-count << endl;
}输出
bernoulli_distribution (0.7) x 10000: true:7024 false: 2976
广告
数据结构
网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP