Bernoulli分布(Bernoulli distribution):是单个二值随机变量的分布。它由单个参数ø∈[0,1],ø给出了随机变量等于1的概率。它具有如下的一些性质:

P(x=1)= ø

P(x=0)=1-ø

P(x=x)= øx(1-ø)1-x

Ex[x]= ø

Varx(x)= ø(1-ø)

伯努力分布(Bernoulli distribution,又名两点分布或者0-1分布)是一个离散型概率分布,为纪念瑞士科学家雅各布·伯努利而命名。若伯努利试验成功,则伯努利随机变量取值为1。若伯努利试验失败,则伯努利随机变量取值为0。记其成功概率为p(0≤p≤1),失败概率为q=1-p。则:

其概率质量函数为:

其期望值为:

其方差为:

Multinoulli分布(multionoulli distribution)或者范畴分布(categorical distribution):是指在具有k个不同状态的单个离

散型随机变量上的分布,其中k是一个有限值。Multinoulli分布由向量p∈[0,1]k-1参数化,其中每一个分量pi表示第i个状

态的概率。最后的k个状态的概率可以通过1-lTp给出。注意必须限制lTp≤1。Multinoulli分布经常用来表示对象分类的分

布,所以很少假设状态1具有数值1之类的。因此,我们通常不需要去计算Multinoulli分布的随机变量的期望和方差.

Bernoulli分布和Multinoulli分布足够用来描述在它们领域内的任意分布。它们能够描述这些分布,不是因为它们

特别强大,而是因为它们的领域很简单;它们可以对那些能够将所有的状态进行枚举的离散型随机变量进行建模。

当处理的是连续型随机变量时,会有不可数无限多的状态,所以任何通过少量参数描述的概率分布都必须在分布上加以

严格的控制。

“multinoulli”这个术语是最近被Gustavo Lacerdo发明,被Murphy(2012)推广的。Multinoulli分布是多项式分

布(multinomial distribution)的一个特例。多项式分布是{0,…,n}k中的向量的分布,用于表示当对Multinoulli分布采

样n次时k个类中的每一个被访问的次数。多项式分布(multinomial distribution)是二项式分布的推广。二项分布的

典型例子是扔硬币,硬币正面朝上概率为p,重复扔n次硬币,k次为正面的概率即为一个二项式分布概率。把二

项分布推广至多个(大于2)互斥事件的发生次数,就得到了多项式分布。比如扔骰子,不同于扔硬币,骰子有6个

面对应6个不同的点数,这样单次每个点数朝上的概率都是1/6.

In probability theory and statistics, a categorical distribution(分类分布)(also called a generalized Bernoulli

distribution(广义伯努利分布), multinoull distribution or, less precisely, a discrete distribution) is a probabilit

distribution that describes the possible results of a random event that can take on one of K possible outcomes,

with the probability of each outcom separately specified. There is not necessarily an underlying ordering of thes

outcomes, but numerical labels are often attached for convenience in describing the distribution. On the other

hand, the categorical distribution is a special case of the multinomial distribution.

以上内容摘自:《深度学习中文版》和 维基百科

以下是对C++11中伯努利分布std::bernoulli_distribution类介绍:

C++11在头文件<random>中提供了伯努利概率分布类std::Bernoulli_distribution。伯努利分布(Bernoulli distribution)是判断某件事情发生或者未发生的概率,产生随机bool值。它是一个单次试验只有0(失败)和1(成功)两个结果的离散分布。

std::bernoulli_distribution:Bernoulli distribution, Random number distribution that produces bool values according to a Bernoulli distribution.

#include "bernoulli_distribution.hpp"
#include <iostream>
#include <random>
#include <string>
#include <iomanip>
#include <map>/
// reference: http://www.cplusplus.com/reference/random/bernoulli_distribution/
int test_bernoulli_distribution_1()
{
{const int nrolls = 10000;std::default_random_engine generator;std::bernoulli_distribution distribution(0.5);int count = 0;  // count number of truesfor (int i = 0; i<nrolls; ++i) if (distribution(generator)) ++count;std::cout << "bernoulli_distribution (0.5) x 10000:" << std::endl;std::cout << "true:  " << count << std::endl;std::cout << "false: " << nrolls - count << std::endl;
}{ // (1)、bernoulli_distribution::bernoulli_distribution: Constructs a bernoulli_distribution object
//   with a probability of p (or with the probability specified by object parm)
//   (2)、bernoulli_distribution::operator(): Generate random number
//   Returns a new random value with the probability associated to the object (version 1) or
//   with the probability specified by parm (version 2)
//   (3)、bernoulli_distribution::p: Probability of true
//   Returns the parameter p associated with the bernoulli_distribution.
//   This parameter represents the probabily that member function operator() returns true.
//   (4)、bernoulli_distribution::max:Maximum value, Returns the least upper bound of the range of
//   values potentially returned by member operator(), which for bernoulli_distribution is true.
//   (5)、bernoulli_distribution::min: Minimum value, Returns the greatest lower bound of the range of
//   values potentially returned by member operator(), which for bernoulli_distribution is false.std::cout << "Please, enter a yes/no question (I will answer it):" << std::endl;std::string text;getline(std::cin, text);std::seed_seq seed(text.begin(), text.end());  // seed using questionstd::default_random_engine generator(seed);std::bernoulli_distribution distribution(0.91);bool result = distribution(generator);std::cout << (result ? "yes" : "no") << std::endl;std::cout << "p: " << distribution.p() << std::endl;std::cout << "max: " << distribution.max() << std::endl;std::cout << "min: " << distribution.min() << std::endl;
}{ // bernoulli_distribution::param: Distribution parameters
//   A bernoulli_distribution is defined by a single parameter: its probability (p) of true results.
//   An object of type param_type carries this information, but it is meant to be used only to construct
//   or specify the parameters for a bernoulli_distribution object, not to inspect the individual parameter.std::default_random_engine generator;std::bernoulli_distribution d1(0.7);std::bernoulli_distribution d2(d1.param());// print two independent values:std::cout << std::boolalpha;std::cout << d1(generator) << std::endl;std::cout << d2(generator) << std::endl;
}{ // bernoulli_distribution::reset: Resets the distribution,
//   so that subsequent uses of the object do not depend on values already produced by it.std::default_random_engine generator;std::bernoulli_distribution distribution;// print two independent values:std::cout << std::boolalpha;std::cout << distribution(generator) << std::endl;distribution.reset();std::cout << distribution(generator) << std::endl;
}return 0;
}/
// reference: http://en.cppreference.com/w/cpp/numeric/random/bernoulli_distribution
int test_bernoulli_distribution_2()
{std::random_device rd;std::mt19937 gen(rd());// give "true" 1/4 of the time// give "false" 3/4 of the timestd::bernoulli_distribution d(0.25);std::map<bool, int> hist;for (int n = 0; n<10000; ++n) {++hist[d(gen)];}for (auto p : hist) {std::cout << std::boolalpha << std::setw(5) << p.first<< ' ' << std::string(p.second / 500, '*') << '\n';}return 0;
}/
int test_bernoulli_distribution_3()
{std::random_device rd; std::mt19937 gen(rd()); // 每次产生不固定的不同的值//std::default_random_engine gen; // 每次产生固定的不同的值std::bernoulli_distribution d(0.5);for (int i = 0; i < 10; ++i)std::cout << d(gen);std::cout << std::endl;return 0;
}

GitHub: https://github.com/fengbingchun/Messy_Test

概率论中伯努利分布(bernoulli distribution)介绍及C++11中std::bernoulli_distribution的使用相关推荐

  1. 【概率论】伯努利分布 Bernoulli Distribution

    Bernoulli distribution 是最简单的单个二值随机变量的分布. 它由单个参数 ϕ∈[0,1]ϕ∈[0,1]\phi \in [0,1] 控制, 其中参数 ϕϕ\phi 给出了随机变量 ...

  2. 概率论中指数分布介绍及C++11中std::exponential_distribution的使用

    指数分布:在深度学习中,我们经常会需要一个在x=0点处取得边界点(sharp point)的分布.为了实现这一目的,我们可以使用指数分布(exponential distribution): p(x; ...

  3. matlab怎么伯努利分布,伯努利分布 Bernoulli distribution

    伯努利分布 是一种离散分布,有两种可能的结果.1表示成功,出现的概率为p(其中0 概率分布有两种类型:离散(discrete)概率分布和连续(continuous)概率分布. 离散概率分布也称为概率质 ...

  4. 概率论中高斯分布(正态分布)介绍及C++11中std::normal_distribution的使用

    高斯分布:最常用的分布是正态分布(normal distribution),也称为高斯分布(Gaussian distribution): 正态分布N(x;μ,σ2)呈现经典的"钟形曲线&q ...

  5. c语言画伯努利分布图像,C++ - 随机生成器 伯努利分布(bernoulli distribution) 的 详解 及 代码...

    随机生成器 伯努利分布(bernoulli distribution) 的 详解 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/deta ...

  6. MATLAB生成伯努利图分布,C++ - 随机生成器 伯努利分布(bernoulli distribution) 的 详解 及 代码...

    随机生成器 伯努利分布(bernoulli distribution) 的 详解 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/deta ...

  7. C++ - 随机生成器 伯努利分布(bernoulli distribution) 的 详解 及 代码

    随机生成器 伯努利分布(bernoulli distribution) 的 详解 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/deta ...

  8. 伯努利分布(Bernoulli distribution)

    伯努利分布 是一种离散分布,有两种可能的结果.1表示成功,出现的概率为p(其中0<p<1).0表示失败,出现的概率为q=1-p.这种分布在人工智能里很有用,比如你问机器今天某飞机是否起飞了 ...

  9. html中scale布局,详细介绍css3的transform中scale缩放

    css即层叠样式表.在网页制作时采用层叠样式表技术,可以有效地对页面的布局.字体.颜色.背景和其它效果实现更加精确的控制.今天小编要给大家分享一篇教程,那就是:详细介绍css3的transform中s ...

最新文章

  1. 宁波网络推广介绍几点容易被优化人员忽略的图片优化技巧!
  2. 今日头条安卓_今日头条加入“常用”小程序窗口,小游戏或将再次崛起?
  3. 不等双十一,ChemDraw降价活动已经打开!
  4. vue实现时间选择器,精确到秒
  5. Consumer group理解深入
  6. swift5 实现购物App
  7. .net core DI 注册 Lazy 类型
  8. 2 MyWarCraftStudio v0.6版
  9. CSDN编程挑战(交换字符)
  10. docker 部署_Nginx K8s + Docker 部署 ,虚拟机部署教程。
  11. 索要 2.3 亿元赎金!富士康遭遇黑客攻击
  12. 超长干货 | Kubernetes命名空间详解
  13. SQL Server Update:使用 TOP 限制更新的数据
  14. Vs2010中水晶报表引用及打包
  15. 计算机组成原理 唐朔飞笔记,计算机组成原理笔记(唐朔飞版)
  16. 参考文献标引方式_参考文献的正确标注方法
  17. 最新版华美淘客商城淘宝客程序源码
  18. Windows下JPBC库的使用
  19. rm ,rm -rf , rm -f 以及rm 命令的其他参数命令
  20. Iterator是什么,有什么作用?

热门文章

  1. 基于RFID的防伪系统设计
  2. 深入理解 wpa_supplicant(三)
  3. matlab中调用java代码_Matlab中调用第三方Java代码
  4. python 爬取svg数据_python处理svg数据
  5. Learn OpenGL (七):摄像机
  6. 异步预热在线视频实现
  7. leetcode-21 合并两个有序链表
  8. BZOJ 1801 [Ahoi2009]中国象棋(线性动规)(洛谷P2051)
  9. 第一周Access课总结
  10. Unity协程截图,WWWForm、WWW配合上传