[Bayes] runif: Inversion Sampling
runifum
Inversion Sampling 看样子就是个路人甲。
Ref: [Bayes] Hist & line: Reject Sampling and Importance Sampling
> func=function(n) {
+ return(-0.5+sqrt(0.25+*runif(n)))
+ }
// 反函数的x的均匀sampling值 => y 就是原函数的x,刚好作为hist的输入参数
> hist(func(),probability=T, xlab=expression(theta), ylab="Density", main="Samples from f(x)")
// 以下是真实值,用线表示
> xx=seq(, , length=)
> lines(xx, xx+0.5, col=)
func=function(n) {
u=runif(n)
return(c(0.5*log(*u[u<0.5]),-0.5*log(*(-u[u>0.5]))) )
}
hist(func(),probability=T,xlab=expression(theta),ylab="Density",main="Samples from f(x)",nclass=,ylim=c(,))
xx=seq(-,,length=)
lines(xx,exp(-sign(xx)**xx),col=)
-sign(xx) 算是一个表达技巧,将原本两个半图,合并在了一起,如下:

简化技巧
Y = −λ log(1 − U ).
Note that if U is uniformly distributed on [0, 1], then 1 − U is also uniformly distributed on [0, 1] so that we could simply compute
Y = −λ log U
[Bayes] runif: Inversion Sampling的更多相关文章
- [Bayes] What is Sampling
Ref: http://blog.csdn.net/xianlingmao/article/details/7768833 通常,我们会遇到很多问题无法用分析的方法来求得精确解,例如由于式子特别,真的 ...
- [Bayes] dchisq: Metropolis-Hastings Algorithm
dchisq gives the density, # 计算出分布下某值处的密度值 pchisq gives the distribution fun ...
- [Bayes] MCMC (Markov Chain Monte Carlo)
不错的文章:LDA-math-MCMC 和 Gibbs Sampling 可作为精进MCMC抽样方法的学习材料. 简单概率分布的模拟 Box-Muller变换原理详解 本质上来说,计算机只能生产符合均 ...
- [AI] 深度数学 - Bayes
数学似宇宙,韭菜只关心其中实用的部分. scikit-learn (sklearn) 官方文档中文版 scikit-learn Machine Learning in Python 一个新颖的onli ...
- 本人AI知识体系导航 - AI menu
Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯 徐亦达老板 Dirichlet Process 学习 ...
- [UFLDL] Generative Model
这一部分是个坑,应该对绝大多数菜鸡晕头转向的部分,因为有来自物理学界的问候. Deep learning:十九(RBM简单理解) Deep learning:十八(关于随机采样) 采样方法 [B ...
- [Bayes] Hist & line: Reject Sampling and Importance Sampling
吻合度蛮高,但不光滑. > L= > K=/ > x=runif(L) > *x*(-x)^/K)) > hist(x[ind],probability=T, + xla ...
- [Bayes] prod: M-H: Independence Sampler for Posterior Sampling
M-H是Metropolis抽样方法的扩展,扩展后可以支持不对称的提议分布. 对于M-H而言,根据候选分布g的不同选择,衍生出了集中不同的变种: (1)Metropolis抽样方法 (2)随机游动Me ...
- [Bayes] Parameter estimation by Sampling
虽然openBugs效果不错,但原理是什么呢?需要感性认识,才能得其精髓. Recall [Bayes] prod: M-H: Independence Sampler firstly. 采样法 Re ...
随机推荐
- linux sendmail 发送缓慢的问题
这个问题关键就是hosts里面对于本机host的设置有问题,你可以看下/var/log/mail.log retry 和 sleeping,再加上其他时间,用sendmail发送邮件等这么久,太累了吧 ...
- CocosCreator原生平台退出游戏,暂停和继续
原生平台退出游戏,方法为:cc.director.end();官方解释:End the life of director in the next frame暂停游戏,方法: cc.director.p ...
- 来自极客头条的 35 个 Java 代码性能优化总结
前言 代码优化,一个很重要的课题.可能有些人觉得没用,一些细小的地方有什么好修改的,改与不改对于代码的运行效率有什么影响呢?这个问题我是这么考虑的,就像大海里面的鲸鱼一样,它吃一条小虾米有用吗?没用, ...
- Java 数组元素倒序的三种方式
将数组元素反转有多种实现方式,这里介绍常见的三种. 直接数组元素对换 @Test public void testReverseSelf() throws Exception { System.out ...
- 继承之final关键字的使用
final关键字 使用final关键字坐标识具有"最终的"含义, final可以修饰类.方法.属性.和变量. final修饰类表示该类不能被继承 final修饰方法,则表示该方法不 ...
- Install LAMP Stack On Ubuntu 16.04
原文:http://www.unixmen.com/how-to-install-lamp-stack-on-ubuntu-16-04/ LAMP is a combination of operat ...
- java判断传进来的是否是图片
public static void main(String[] args) throws IOException { String filePath = "C:\\Users\\80975 ...
- 每天一个linux命令(1):pwd命令
1.命令简介 pwd(print work directory 打印当前目录)命令以绝对路径的方式显示用户当前工作目录. 2.用法 pwd [-LP] 3.选项 -L --logical 当目录为连接 ...
- 在 Swift 中调用 OC 代码
前言 在 Swift 语言中,我们可以使用 Objective-C.C 语言编写代码,我们可以导入任意用 Objective-C 写的 Cocoa 平台框架.Objective-C 框架或 C 类库. ...
- AaronYang WCF教程目录
============================原创,讲究实践===================== 1. 那天有个小孩教我WCF[一][1/3] 基本搭建 阅读 ...