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. map和string的使用方法

    这个是别人写的map使用方法比較好能够看一下 http://www.cnblogs.com/anywei/archive/2011/10/27/2226830.html 怎样向数组中插入内容 http ...

  2. PHP 获取网络接口文件流

    获取网络接口里面的文件流 php开发调用各种接口在所难免,有时须要传递非常多參数. 在传递參数过程中 '&' 有时会被 解析成 '&'导致请求失败 经过查找资料和比較,发现php提供了 ...

  3. 更精炼更专注的RTMPClient客户端EasyRTMPClient,满足直播、转发、分析等各种需求

    现状 EasyRTMPClient,熟悉的朋友就会联想到EasyRTSPClient项目(https://github.com/EasyDSS/EasyRTSPClient),EasyRTSPClie ...

  4. android菜鸟学习笔记12----Android控件(一) 几个常用的简单控件

    主要参考<第一行代码> 1.TextView: 功能与传统的桌面应用开发中的Label控件相似,用于显示文本信息 如: <TextView android:layout_width= ...

  5. wepy/packages/wepy-web/src/helper/device.js

    wepy/packages/wepy-web/src/helper/device.js https://github.com/Tencent/wepy/blob/bd0003dca2bfb958113 ...

  6. 1、找出url汇总页,过滤出满足条件的详情页url;2、去详情页采集信息

    1.找出url汇总页,过滤出满足条件的详情页url:2.去详情页采集信息 package main import ( "fmt" "github.com/gocolly/ ...

  7. mybatis 执行查询时报错 【Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: 】

    org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLE ...

  8. OpenCV改变像素颜色

    Mat src=imread("image/color.jpg"); imshow("a",src); int i,j; int cPointR,cPointG ...

  9. ABAP 设置单元格颜色

    http://blog.163.com/ronanchen@126/blog/static/172254750201161811040488/ http://blog.csdn.net/lhx20/a ...

  10. Unity中几种简单的相机跟随

    #unity中相机追随 固定相机跟随,这种相机有一个参考对象,它会保持与该参考对象固定的位置,跟随改参考对象发生移动 using UnityEngine; using System.Collectio ...