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 ...
随机推荐
- Android API Guides---Storage Access Framework
存储訪问架构 Android 4.4系统(API级别19)推出存储訪问框架(SAF).新加坡武装部队变得很easy,为用户在其全部自己喜欢的文件存储提供商的浏览和打开文档,图像和其它文件.一个标准的, ...
- iOS开发 viewWillAppear:(BOOL)animated真机调试的时候不执行了怎么办
本文转载至http://blog.sina.com.cn/s/blog_a843a8850101e0g7.html 现在需要的.h文件里面加上. 然后,在需要的.m文件按里面加上关键代码:self ...
- 玩家下线(GS部分)
玩家下线,之前一直感觉这个过程有点复杂 else if (stat == link_stat::link_disconnected || stat == link_stat::link_connect ...
- Python中属性
属性定义的两种方式: 1.num1=property(GetNum,SetNum) class Pro(): def __init__(self): self._num= def GetNum(s ...
- 九度OJ 1082:代理服务器 (DP)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1871 解决:574 题目描述: 使用代理服务器能够在一定程度上隐藏客户端信息,从而保护用户在互联网上的隐私.我们知道n个代理服务器的IP地 ...
- SAP流水号
[转]编号范围对象维护 Tcode: SNRO OYSM 1.Number Range的通用Tcode:SNRO 2.Number Range的通用读取函数:NUMBER_GET_NEXT 3 ...
- leetcode 890. Possible Bipartition
Given a set of N people (numbered 1, 2, ..., N), we would like to split everyone into two groups of ...
- leetcode 863. All Nodes Distance K in Binary Tree
We are given a binary tree (with root node root), a target node, and an integer value K. Return a li ...
- java: new Date().getTime() 与 System.currentTimeMillis() 与 System.nanoTime()
java使用new Date()和System.currentTimeMillis()获取当前时间戳 在开发过程中,通常很多人都习惯使用new Date()来获取当前时间,使用起来也比较方便,同时 ...
- DBA日记:一次reboot导致的严重失误
昨天下午,一现场要添加RAC节点,db1节点正常运行,添加db2节点:在db2上做了安装的一些配置后,需要reboot, 于是直接就reboot:糟糕,这条命令错误地执行在db1上了,导致现场数据库直 ...