Pseudo Random Nubmer Sampling
Pseudo Random Nubmer Sampling
https://en.wikipedia.org/wiki/Inverse\_transform\_sampling
given a distribution's cumulative distribution function (CDF), generate sample numbers for this distribution.
typically based on uniform distribution variable X (or several of them), then somehow manipulate it, and get random variable Y which has the required distribution
Rejection Sampling if density function is known
one type of Monte-Carlo Method
see some notes
target: sample from F=f(x)
idea: find an alternative G=g(x) which we already know, and that f(x)/g(x) <= c where c is a constant (ideally close to 1)
algorithm:
- sample y from G;
- sample u from U[0,1];
- if u <= f(y)/c*g(y), then accept y; reject otherwise
Inverse Transform Sampling for distributions where CDF is known
- input 1: CDF of some distribution; for example, exponential distribution, F(x)=1-exp{\left(1-\lambda x\right)}
- input 2: a uniform distribution U[0,1]; for example, u=0.387;
- F(x) = y => x = F^{-1}\left(y\right) = -\frac{1}{\lambda}\ln{\left(1-y\right)} => x = -\frac{1}{\lambda}\ln\left(y\right)
- draw a value from U[0,1], and use it as CDF() value, then solve for the corresponding x value
Box-Muller Transform for Normal Distribution
- only used for generating Normal Distribution
- input: uniform distribution U[0,1]
- output: 2 independent standard normal distribution numbers
- Suppose U1 and U2 are independent random variables from U[0,1]
- let
and
, then Z0 and Z1 are both N(0,1) random variables
有一个数组,类似于:{{'Canada', 3}, {'USA', 5}, {'UK', 2}, {'Brasil', 3}}, 数组的类型是Country, 有两个变量, Country.name, Country.weight. 每个国家都有一个权重,然后给一个output()函数,每次调用这个函数的时候就输出一个国家的名字,要使每个国家被输出的概率相等。我用的方法是平摊weight: {Canada, Canada, USA, USA, USA, USA, UK, UK, Brasil, Brasil, Brasil}, 然后用Random 函数输出。Follow up : 如果这个权重的值很大很大,比如billio级别,应该怎么办。我的方法是类似于线段树,然后再用sum * Random(), 看这个区间坐落在哪里。
- target distribution is a discrete distribution, p(x='Canada')=3/13, p(x='USA')=5/13 etc.
- fit it into the Inverse Transform Sampling algorithm
- sample an integer from [1,13], {1,2,3} => Canada, {4,5,6,7,8} => USA, {9,10} => UK, {11,12,13} => Brasil
Pseudo Random Nubmer Sampling的更多相关文章
- ICCV 2017论文分析(文本分析)标题词频分析 这算不算大数据 第一步:数据清洗(删除作者和无用的页码)
IEEE International Conference on Computer Vision, ICCV 2017, Venice, Italy, October 22-29, 2017. IEE ...
- CSharpGL(54)用基于图像的光照(IBL)来计算PBR的Specular部分
CSharpGL(54)用基于图像的光照(IBL)来计算PBR的Specular部分 接下来本系列将通过翻译(https://learnopengl.com)这个网站上关于PBR的内容来学习PBR(P ...
- Python标准库3.4.3-random
9.6. random — Generate pseudo-random numbers Source code: Lib/random.py 翻译:Z.F. This module impleme ...
- 【初学python】使用python调用monkey测试
目前公司主要开发安卓平台的APP,平时测试经常需要使用monkey测试,所以尝试了下用python调用monkey,代码如下: import os apk = {'j': 'com.***.test1 ...
- OFDM学习之旅
前言: 这些日子开始准备搞OFDM之类的,未动先行matlab仿真,这里我会慢慢更新,基本上是自己学习感悟吧<未完待续> 一.PRBS PRBS 是 Pseudo Random Binar ...
- GPS开发之知识储备(NMEA0183)
GPS是英文Global Positioning System(全球定位系统)的简称. NMEA0183(http://files.cnblogs.com/files/libra13179/NMEA0 ...
- 15天玩转redis —— 第五篇 集合对象类型
这篇我们来看看Redis五大类型中的第四大类型:“集合类型”,集合类型还是蛮有意思的,第一个是因为它算是只使用key的Dictionary简易版, 这样说来的话,它就比Dictionary节省很多内存 ...
- Locality Sensitive Hash 局部敏感哈希
Locality Sensitive Hash是一种常见的用于处理高维向量的索引办法.与其它基于Tree的数据结构,诸如KD-Tree.SR-Tree相比,它较好地克服了Curse of Dimens ...
- mod_cluster启用https协议的步骤
1.生成SSL证书与私钥 Generate Private Key on the Server Running Apache + mod_ssl First, generate a private k ...
随机推荐
- 用户对变量或寄存器进行位操作 、“|=”和“&=~”操作
给定一个整型变量a,写两段代码,第一个设置a的bit 3,第二个清除a的bit 3.在以上两个操作中,要保持其他位不变. 答案: ----------------------------------- ...
- 洛谷 3275 [SCOI2011]糖果
题目戳这里 N句话题意 有N个人,k个限制,有五种限制 如果X=1, 表示第A个小朋友的糖果必须和第B个小朋友的糖果一样多: 如果X=2, 表示第A个小朋友的糖果必须少于第B个小朋友的糖果: 如果X= ...
- django 设置静态文件,static
django 设置静态文件,static 一.搜集静态文件 1.1 命令行查看 collectstatic guoguos-MacBook-Pro:mysite guoguo$ python mana ...
- Linux下Mysql数据库忘记root
系统环境:Red Hat Enterprise Linux Server 6 1.停止mysqld服务 [root@Server huage]# service mysqld stop 2.以跳过授权 ...
- android MVP模式思考
在软件开发设计中,有多种软件设计模式,如web开发中经典的MVC, 将后台分为三层:Model层,View层和Controller层,其中,Model主要是数据处理,如数据库,文件,或网络数据等:Vi ...
- web 全栈 学习 1 工程师成长思路图
第一部分: 技术的三个阶段 实现 ---> 借鉴 ---> 优化 实现:为了实现功能,不考虑可读性.借鉴:阅读开源代码,开源程序,学到编程思想.优化:可读性,可执行. 阶段一:实现多做事, ...
- Python环境问题
http://installion.co.uk/ubuntu/precise/main/p/python3.2/uninstall/index.html
- 深入浅出理解linux inode结构【转】
本文转载自:https://blog.csdn.net/fantasyhujian/article/details/9151615 一.inode是什么? 参考文档:http://tech.diann ...
- jQuery Validate 插件为表单提供了强大的验证功能
之前项目开发中,表单校验用的jQuery Validate 插件,这个插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的 ...
- C语言中的指针(一)
指针也是一种数据类型,占用内存空间,内存中存储的只能是变量的地址. *p是操作内存的意思,在声明成为指针变量的时候使用*,在使用指针的时候,*表示操作内存. *p放在等号的左边,相当于是从内存中取值, ...