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 ...
随机推荐
- NuGet管理工具安装
安装完成后VS重启即可
- python venv虚拟环境
1 目的 给python应用一个独立的运行环境,独立于其它的python应用也独立于系统的python环境. 环境升级不影响其它应用. 避免包冲突. 2 创建方式 2.1 pycharm中创建 pro ...
- Leslie Lamport
http://lamport.azurewebsites.net/pubs/pubs.html paper
- VC里OnPaint几点要注意的地方(没有invalidate,系统认为窗口没有更新的必要,于是就对发来的WM_PAINT消息不理不睬)
写在属于自己的体会,哪怕只是一点点,也是真的懂了.否则有那么多书,如果只是不过脑子的学一遍看一遍,又有谁真的掌握了这些知识呢? 这样你或许就明白了为什么不能直接用SendMessage和PostMes ...
- linux怎么设置vsftp用户访问目录权限
1.在指定的目录创建文件夹(访问的目录): mkdir picture 2.创建一个用户组(zdhgroup): groupadd zdhgroup 3.创建一个用户并指定路径和组: useradd ...
- (转)nginx-rtmp-module和ffmpeg搭建实时HLS切片
1.rtmp服务器 nginx+pcre+zlib+openssl+nginx-rtmp-module ./configure \ --prefix=/usr/local/nginx \ --sbin ...
- PAT天梯赛 L2-020. 功夫传人 【DFS】
题目链接 https://www.patest.cn/contests/gplt/L2-020 思路 从师父开始 一层一层往下搜 然后 搜到 得道者 就更新答案 AC代码 #include <c ...
- hihocoder 微软编程之美2015 初赛 第二场(暴力+字典序+图论+思维算法)
题目1 : 扑克牌 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 一副不含王的扑克牌由52张牌组成,由红桃.黑桃.梅花.方块4组牌组成,每组13张不同的面值.现在给定52 ...
- 吴恩达机器学习笔记(二) —— Logistic回归
主要内容: 一.回归与分类 二.Logistic模型即sigmoid function 三.decision boundary 决策边界 四.cost function 代价函数 五.梯度下降 六.自 ...
- 吴恩达机器学习笔记(九) —— 异常检测(Anomaly detection)
主要内容: 一.模型介绍 二.算法过程 三.算法性能评估及ε(threshold)的选择 四.Anomaly detection vs Supervised learning 五.Multivaria ...