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:

  1. sample y from G;
  2. sample u from U[0,1];
  3. if u <= f(y)/c*g(y), then accept y; reject otherwise

Inverse Transform Sampling for distributions where CDF is known

  1. input 1: CDF of some distribution; for example, exponential distribution, F(x)=1-exp{\left(1-\lambda x\right)}
  2. input 2: a uniform distribution U[0,1]; for example, u=0.387;
  3. 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)
  4. 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

  1. only used for generating Normal Distribution
  2. input: uniform distribution U[0,1]
  3. output: 2 independent standard normal distribution numbers
  4. Suppose U1 and U2 are independent random variables from U[0,1]
  5. let and , then Z0 and Z1 are both N(0,1) random variables

example

有一个数组,类似于:{{'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(), 看这个区间坐落在哪里。

  1. target distribution is a discrete distribution, p(x='Canada')=3/13, p(x='USA')=5/13 etc.
  2. fit it into the Inverse Transform Sampling algorithm
  3. 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的更多相关文章

  1. ICCV 2017论文分析(文本分析)标题词频分析 这算不算大数据 第一步:数据清洗(删除作者和无用的页码)

    IEEE International Conference on Computer Vision, ICCV 2017, Venice, Italy, October 22-29, 2017. IEE ...

  2. CSharpGL(54)用基于图像的光照(IBL)来计算PBR的Specular部分

    CSharpGL(54)用基于图像的光照(IBL)来计算PBR的Specular部分 接下来本系列将通过翻译(https://learnopengl.com)这个网站上关于PBR的内容来学习PBR(P ...

  3. Python标准库3.4.3-random

    9.6. random — Generate pseudo-random numbers Source code: Lib/random.py  翻译:Z.F. This module impleme ...

  4. 【初学python】使用python调用monkey测试

    目前公司主要开发安卓平台的APP,平时测试经常需要使用monkey测试,所以尝试了下用python调用monkey,代码如下: import os apk = {'j': 'com.***.test1 ...

  5. OFDM学习之旅

    前言: 这些日子开始准备搞OFDM之类的,未动先行matlab仿真,这里我会慢慢更新,基本上是自己学习感悟吧<未完待续> 一.PRBS PRBS 是 Pseudo Random Binar ...

  6. GPS开发之知识储备(NMEA0183)

    GPS是英文Global Positioning System(全球定位系统)的简称. NMEA0183(http://files.cnblogs.com/files/libra13179/NMEA0 ...

  7. 15天玩转redis —— 第五篇 集合对象类型

    这篇我们来看看Redis五大类型中的第四大类型:“集合类型”,集合类型还是蛮有意思的,第一个是因为它算是只使用key的Dictionary简易版, 这样说来的话,它就比Dictionary节省很多内存 ...

  8. Locality Sensitive Hash 局部敏感哈希

    Locality Sensitive Hash是一种常见的用于处理高维向量的索引办法.与其它基于Tree的数据结构,诸如KD-Tree.SR-Tree相比,它较好地克服了Curse of Dimens ...

  9. mod_cluster启用https协议的步骤

    1.生成SSL证书与私钥 Generate Private Key on the Server Running Apache + mod_ssl First, generate a private k ...

随机推荐

  1. python 基础 5.3 类的重写

    一. 类的重写 只需要重新定义类的属性(变量),就是累的重写了 示例:重新定义类grandson的 name属性   #/usr/bin/python #coding=utf-8 #@Time :20 ...

  2. String代码示例

    package lianxi; public class lianxi0112 { public static void main(String[] args) { // TODO 自动生成的方法存根 ...

  3. 再看python多线程------threading模块

    现在把关于多线程的能想到的需要注意的点记录一下: 关于threading模块: 1.关于 传参问题 如果调用的子线程函数需要传参,要在参数后面加一个“,”否则会抛参数异常的错误. 如下: for i ...

  4. 九度OJ 1053:互换最大最小数 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6613 解决:2676 题目描述: 输入一个数n,然后输入n个数值各不相同,调换数组中最大和最小的两个数,然后输出. 输入: 测试数据有多组 ...

  5. c++对象内存的分配

    1 关于c++的对象 只要是用了class或者struct定义的,都是对象,不管有没有方法.不过,一般情况下,没有方法的对象用struct关键字来定义. 2 不用new关键字定义对象 要看这样的对象在 ...

  6. Qt — tableWidget插入复选框

    之前不太了解Qt中的相关控件,一直尝试直接在tableview上增加复选框. 但相对来说,在tableview增加复选框的工作量与麻烦程度远超tableWidget. 接下来是如何在Qt的tableW ...

  7. curl下载安装

    curl下载地址 https://curl.haxx.se/download.html 选择windows generic 下的 下载安装 安装完后解压配置系统环境变量 CURL_HOME      ...

  8. (C)程序控制块(TCB)

    程序控制块 1. 程序控制块 从代码上看,程序控制块就是一个结构体.例如: typedef struct tcb{ char * tast_name; //任务名字 int p; //任务重要级别 i ...

  9. java高级特性增强

    第4天 java高级特性增强 今天内容安排: 1.掌握多线程 2.掌握并发包下的队列 3.了解JMS 4.掌握JVM技术 5.掌握反射和动态代理 java多线程增强 .1. java多线程基本知识 . ...

  10. z+f profiler 9012

    角度分辨率/角度精度 0.0088°/0.02°RMS