PSTAT 115 Homework4 课业解析

题意:

蒙特卡洛采样之拒绝采样

解析:

给定一个概率分布p(z)=p~(z)/Zp,p~(z)已知,Zp为归一化常数,为未知数。对该分布进行拒绝采样,我们引入一个简单地参考分布,记作q(x),q(x)分布的采样是易于实现的,比如均匀分布。再引入一个常数k,满足kq(z)>p~(z)。每次采样中首先从q(z)采样一个数值z0,然后在区间[0,kq(z0)]进行均匀采样,得到u0。如果u0<p~(z0),则保留该采样值,否则丢弃该采样值。最后得到的数据就是一个对该分布的近似采样。为了提高接受效率,防止舍弃过多的采样值而导致采样效率低下,k值应该满足在kq(z)>p~(z)的基础上尽可能小。

涉及知识点:

拒绝采样

更多可+薇❤讨论:Rainbow890722

pdf

Homework 4

PSTAT 115, Fall 2019

Due on November 3, 2019 at 11:59 pm

Note: If you are working with a partner, please submit only one homework per group with both names

and whether you are taking the course for graduate credit or not. Submit your Rmarkdown (.Rmd) and the

compiled pdf on Gauchospace.

1. Rejection Sampling the Beta distribution. Assume we did not have access to the rbeta function for

sampling from a Beta, but we were able to evaluate the density, dbeta. This is a very common setting

in Bayesian statistics, since we can always evaluate the (proportional) posterior density p(θ | y) ∝ p(y |

θ)p(θ) but we don’t have immediate access to a method for sampling from this distribution.

(a) Let p(x) be a Beta(3, 9) density, q1(x) a Uniform(0, 1) density, and q2(x) a Normal(µ = 0.25, σ =

0.15) density.

(b) Use rejection sampling to sample from p(x) by proposing samples from q1(x). To do so, first find

M1 = max

x

p(x)/q1(x) using the optimize function and set lower=0, upper=1, and maximum =

TRUE (since we are maximizing not minimizing, the default). M will be the value in the objective

argument returned by optimize (maximum tells us where the maximum occurs, but not what height

it achieves). Propose 10000 samples and keep only the accepted samples.

(c) Use rejection sampling to sample from p(x) by proposing samples from q2(x). To do this you

need to find M2 = max

x

p(x)/q2(x) as above. Propose 10000 samples and keep only the accepted

samples.

(d) Plot the p(x), M1q1(x) and M2q2(x) all on the same plot and verify visually that the scaled

proposal densities “envelope” the target, p(x). Set the xlimits of the plot from 0 to 1. Use different

color lines for the various densities so are clearly distinguishable.

(e) Which rejection sampler had the higher rejection rate? Why does this make sense given the plot

from the previous part? This means when proposing 10000 samples from each proposal, the Monte

Carlo error of our approximation will be higher when proposing from ____ (choose q1 or q2).

(f) Report the variance of Beta(3, 9) distribution by computing the variance of the beta samples. How

does this compare to the theoretical variance (refer to the probability cheatsheet).

2. Interval estimation with rejection sampling.

(a) Use rejection sampling to sample from the following density:

p(x) = 1

4

|sin(x)| × I{x ∈ [0, 2π]}

Use a proposal density which is uniform from 0 to 2π and generate at least 1000 true samples from

p(x). Compute and report the Monte Carlo estimate of the upper and lower bound for the 50%

quantile interval using the quantile function on your samples. Compare this to the 50% HPD

region calculated on the samples. What are the bounds on the HPD region? Report the length of

the quantile interval and the total length of the HPD region. What explains the difference? Hint:

to compute the HPD use the hdi function from the HDInterval package. As the first argument

pass in density(samples), where samples is the name of your vector of true samples from the

density. Set the allowSplit argument to true and use the credMass argument to set the total

probability mass in the HPD region to 50%.

(b) Plot p(x) using the curve function (base plotting) or stat_function (ggplot). Add lines corresponding to the intervals / probability regions computed in the previous part to your plot using

1

them segments function (base plotting) or geom_segements (ggplot). To ensure that the lines

don’t overlap visually, for the HPD region set the y-value of the segment to 0 and for the quantile

interval set the y-value to to 0.01. Make the segments for HPD region and the segment for quantile

interval different colors. Report the length of the quantile interval and the total length of the HPD

region, verifying that indeed the HPD region is smaller.

PSTAT 115 Homework4 课业解析的更多相关文章

  1. android中使用DisplayMetrics获取屏幕参数

    --关于Density int android.graphics.Bitmap.getDensity(),返回bitmap-density(密度).默认的density就是当前display-dens ...

  2. 【算法】(查找你附近的人) GeoHash核心原理解析及代码实现

    本文地址 原文地址 分享提纲: 0. 引子 1. 感性认识GeoHash 2. GeoHash算法的步骤 3. GeoHash Base32编码长度与精度 4. GeoHash算法 5. 使用注意点( ...

  3. CSharpGL(9)解析OBJ文件并用CSharpGL渲染

    CSharpGL(9)解析OBJ文件并用CSharpGL渲染 2016-08-13 由于CSharpGL一直在更新,现在这个教程已经不适用最新的代码了.CSharpGL源码中包含10多个独立的Demo ...

  4. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q112-Q115)

    Question  112 You are designing a public-facing SharePoint 2010 Web site for an elementary school th ...

  5. 【Jsoup网页解析】

    下载链接:http://jsoup.org/download 一.普通的请求方式(不带有cookie) 使用举例: 第一步: Connection conn=Jsoup.connect(url); 第 ...

  6. Java集合---Array类源码解析

    Java集合---Array类源码解析              ---转自:牛奶.不加糖 一.Arrays.sort()数组排序 Java Arrays中提供了对所有类型的排序.其中主要分为Prim ...

  7. 书籍推荐《以C语言解析电脑》

    这本书要想买到,在大陆看起来比较难,理出个目录,看个大概: 另外在这个地方可以预览前20页:http://openebook.hyread.com.tw/ebookservice/hyviewer/o ...

  8. 深度解析SDN——利益、战略、技术、实践(实战派专家力作,业内众多专家推荐)

    深度解析SDN——利益.战略.技术.实践(实战派专家力作,业内众多专家推荐) 张卫峰 编   ISBN 978-7-121-21821-7 2013年11月出版 定价:59.00元 232页 16开 ...

  9. 115个Java面试题和答案——终极列表(下)

    第一篇讨论了面向对象编程和它的特点,关于Java和它的功能的常见问题,Java的集合类,垃圾收集器,本章主要讨论异常处理,Java小应用程序,Swing,JDBC,远程方法调用(RMI),Servle ...

随机推荐

  1. 安装vue开发环境

    每次搜索vue开发环境安装时,总是有很多种版本,虽然都能安装完成,但还是整理下自己觉得比较好的版本吧 1.首先安装nodeJs以及也把git安装好(反正开发也是需要git),安装完成后执行 node ...

  2. vscode中如何自动保存

    是的,vscode是个不错的编辑器,它的扩展功能能支持很多的语言,然后在实践过程中,我们发现每写好一次就得手动按CTRL+S,未免有点手酸,这时候我们就可以开启我们的自动保存功能,方式也很简单,在 文 ...

  3. ELK7.3实战安装配置文档

    整体架构   一:环境准备 1.环境规划准备 192.168.43.16 jdk,elasticsearch-master ,logstash,kibana 192.168.43.17 jdk,ela ...

  4. spring cache常用注解使用

    1.@CacheConfig 主要用于配置该类中会用到的一些共用的缓存配置.示例: @CacheConfig(cacheNames = "users") public interf ...

  5. 阿里云服务器ecs配置之安装tomcat

    1.下载链接:https://tomcat.apache.org/download-70.cgi,选择需要的版本下载(.tar.gz文件后缀) 2.通过Xshell.Xftp上传至CentosX的 某 ...

  6. FastDfs之StorageServer的详细配置介绍

    #这个配置文件是否失效 disabled=false #false为有效 true为无效 # 本storage server所属的group名 group_name=group1 # 可以版定一个ip ...

  7. [数学基础]奇异值分解SVD

    之前看到过很多次奇异值分解这个概念,但我确实没有学过.大学线性代数课教的就是坨屎,我也没怎么去上课,后来查了点资料算是搞清楚了,现在写点东西总结一下. 奇异值分解,就是把一个矩阵拆成一组矩阵之和.在数 ...

  8. .Net Core 商城微服务项目系列(三):Ocelot网关接入Grafana监控

    使用网关之后我们面临的一个问题就是监控,我们需要知道网关的实时状态,比如当前的请求吞吐量.请求耗费的时间.请求峰值甚至需要知道具体哪个服务的哪个方法花费了多少时间.网关作为请求的中转点是监控品牌的要塞 ...

  9. Hbase入门(四)——表结构设计-RowKey

    Hbase的表结构设计与关系型数据库有很多不同,主要是Hbase有Rowkey和列族.timestamp这几个全新的概念,如何设计表结构就非常的重要. 创建 Hbase就是通过 表 Rowkey 列族 ...

  10. ES6入门之Promise对象

    1. Promise 的含义 Promise 是异步编程的一种解决方案,比传统的解决方案--回调函数和事件更合理.更强大. 1.1 什么是Promise 简单来说就是一个容器,里面保存着某个未来才会结 ...