[Bayes] openBUGS: this is not the annoying bugs in programming
Bayesian inference Using Gibbs Sampling
允许用户指定复杂的多层模型,并可使用MCMC算法来估计模型中的未知参数。
We use DAGs to specify models.
这里只涉及简单的贝叶斯网络,具体学习可见:
Carnegie Mellon University course 10-708, Spring 2017, Probabilistic Graphical Models
Ref: http://www.cnblogs.com/Dzhouqi/p/3204481.html
例子一
X and Y 不独立,但
X and Y 在Z情况下 条件独立。
表示:X ⊥ Y |Z
f (X, Y |Z) = f (X|Z) f (Y |Z).

知道了C 反而条件独立了? 如此理解:
a 孩子的血型是AB,其实“反作用”于c双亲不可能是O型血。然后,这个推断也影响了b孩子的血型可能性,即:也不可能是O型血。
知道了c,比如c父母只有A and B血型因子,那么a and b孩子变为了在c已知的条件下的独立。
例子二

此例同上。
例子三

已知c,能得出a and b条件独立? 不能。
在Gibbs的一点用处
If we want to sample from p(A, B, C, D, F ) with a Gibbs sampler we define each marginal full conditional distribution using the conditional independence pattern of the DAG.


手头有这样的数据,如下:

建立一个模型吧:

简化模型:

指定”似然函数“和”先验分布”:

Deterministic functions can be removed/restructured, so that:

Bayesian inference Using Gibbs Sampling
Download:
http://www.openbugs.net/w/Downloads
Install:
To install this, unpack by typing
tar zxvf OpenBUGS-3.2.3.tar.gz
cd OpenBUGS-3.2.3
then compile and install by typing
./configure
make
sudo make install
Run:
lolo@lolo-UX303UB$ OpenBUGS
OpenBUGS version 3.2. rev
type 'modelQuit()' to quit
OpenBUGS>
Use:
https://www.youtube.com/watch?v=UhYAz6d5_qg
打开三类文件:model, data, init。
Model --> Specification 依次加载各个文件。

Inference --> Samples 其实就是监视Init里的四个参数。

Model --> Update 迭代操作一次(Here 每次1000下)

Prior Sensitivity Analysis
The choice of prior(s) distribution must be determined with care, particularly, when the likelihood doesn't dominate the posterior.
If the likelihood dominates the posterior, the posterior distribution will essentially be invariant over a wide range of priors.
When the number of studies is large, the prior distribution will be less important. 数据量越大,先验的选择越不重要。
The non-informative prior distribution will be very useful in the situation when prior information, expectations and beliefs are minimal or not available.

Figure, 先验概率,后验概率 和 似然函数的关系
贝叶斯后验均值估计的最基本特性是伸缩性(shrinkage)。
- 当似然函数的精度h0较大时, 后验均值主要受样本均值支配; 相反,
- 当先验精度h1较大时, 后验均值主要受先验均值支配。
这就是为什么贝叶斯估计通常取先验精度较低的原因(方差给得较大),
也可以看出贝叶斯估计在调整先验精度下可以达到经典估计的效果,从某种意义上说经典估计是贝叶斯估计的特殊形式。
通过两种精度的调整达到对后验均值的估计叫做伸缩性估计特性, 所有贝叶斯估计的均值都具有伸缩性估计这个特性。
最后,推荐一篇至少题目看上去很牛的文章:

官方:http://www.openbugs.net/Manuals/InferenceMenu.html
民间1:http://www.biostat.jhsph.edu/~fdominic/teaching/bio656/labs/labs08/Lab8.IntroWinBUGS.pdf
民间2:http://www.stats.ox.ac.uk/~cholmes/Courses/BDA/Winbugs/winbugs-help.pdf
民间的更好,详细,良心作品。
收敛性检验:
• For models with many parameters, it is inpractical to check convergence for every parameter, so just chose a random selection of relevant parameters to monitor
一个一个地检查。
– For example, rather than checking convergence for every element of a vector of random effects, just chose a random subset (say, the first 5 or 10).
• Examine trace plots of the sample values versus iteration to look for evidence of when the simulation appears to have stabilised: (查看是否有稳定的迹象)
– To obtain ’live’ trace plots for a parameter:
∗ Select Samples from the Inference menu.
∗ Type the name of the parameter in the white box marked node.
∗ Click once with the LMB on the box marked trace: an empty graphics window will appear on screen.
∗ Repeat for each parameter required.
∗ Once you start running the simulations (using the Update Tool, trace plots for these parameters will appear ’live’ in the graphics windows.
– To obtain a trace plot showing the full history of the samples for any parameter for which you have previously set a sample monitor and carried out some updates:
∗ Select Samples from the Inference menu.
∗ Type the name of the parameter in the white box marked node (or select name from pull down list).
∗ Click once with the LMB on the box marked history: a graphics window showing the sample trace will appear.
∗ Repeat for each parameter required.
uniform时,将初始值调高,看明显看出收敛的速度。毕竟在实践当中,我们并不会知道,甚至无法估计参数的大概范围。

以下是model中变量的假设分布换为gaussian分布,收敛快了许多。

[Bayes] openBUGS: this is not the annoying bugs in programming的更多相关文章
- [Math] Hidden Markov Model
链接:https://www.zhihu.com/question/20962240/answer/33438846 霍金曾经说过,你多写一个公式,就会少一半的读者. 还是用最经典的例子,掷骰子. ...
- 本人AI知识体系导航 - AI menu
Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯 徐亦达老板 Dirichlet Process 学习 ...
- [PGM] What is Probabalistic Graphical Models
学术潜规则: 概率图模型提出的意义在于将过去看似零散的topic/model以一种统一的方式串联了起来,它便于从整体上看待这些问题,而非具体解决了某个细节. 举个例子:梯度下降,并非解决神经网络收敛问 ...
- [Scikit-learn] Dynamic Bayesian Network - Kalman Filter
看上去不错的网站:http://iacs-courses.seas.harvard.edu/courses/am207/blog/lecture-18.html SciPy Cookbook:http ...
- 科学计算软件——Octave安装
Octave是一个旨在提供与Matlab语法兼容的开放源代码科学计算及数值分析的工具,是Matlab商业软件的一个强有力的竞争产品. 参考:[ML:Octave Installation] Gener ...
- [Django] Setting up Django Development Environment in Ubuntu 14.04
1. Python Of course you will need Python. Still Python 2.7 is preferred, however if you would like t ...
- Core Java Volume I — 3.5. Operators
3.5. OperatorsThe usual arithmetic operators +, -, *, / are used in Java for addition, subtraction, ...
- 转:PHP – Best Practises
原文来自于:http://thisinterestsme.com/php-best-practises/ There are a number of good practises that you s ...
- Delphi资源大全
A curated list of awesome Delphi frameworks, libraries, resources, and shiny things. Inspired by awe ...
随机推荐
- Linux中ls -l(ll)返回结果中的文件访问权限-rw-r--rw-
linux文件访问权限(像rw-r--rw-是什么意思) Linux的文件访问权限分为 读.写.执行三种 r:可读(4) w:可写(2)对目录来说则可新建文件 x:可执行(1)对目录来说则可进入该 ...
- lua去掉字符串中的UTF-8的BOM三个字节
废话不多说,还是先说点吧,项目中lua读取的text文件如果有BOM,客户端解析就会报错,所以我看了看,任务编辑器swGameTaskEditor 在写入文件的时候,也不知道为什么有的文件就是UTF- ...
- 【Zookeeper】源码分析之网络通信(三)之NettyServerCnxn
一.前言 前面已经学习了NIOServerCnxn,接着继续学习NettyServerCnxn. 二.NettyServerCnxn源码分析 2.1 类的继承关系 public class Netty ...
- SQL与MySQL基本
一:概念辨析 数据库(database):是一种保存有组织的数据的容器. 数据库软件(DBMS):使用DBMS操作数据库.访问数据库. SQL:结构化查询语言,专门用来与数据库通信的语言.几乎所有DB ...
- Shell脚本编程基础笔记一
转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/8176137.html 一:脚本文件的创建.格式.运行 1:创建shell脚本 首先,要创建一个文件 touch ...
- IDEA使用笔记(八)——自动生成 serialVersionUID 的设置
这个设置比较简单,也有一些博文已经写到了,为什么我还要写哪?(潜台词:因为我想凑一篇博文)我觉得学习,特别是编程学习是需要重复造轮子的,另外,就是加深自己的印象方便自己的查找.还有就是关键点,有些博客 ...
- 有关Linux下request.getRealPath("/")获取路径的问题
request.getRealPath("/") 在window获取的是服务器的根目录,结尾包含分隔符, 如E:\apache-tomcat-6.0.29-bak\apache-t ...
- mvc4 强大的导出和不需要上传文件的批量导入EXCEL--SNF快速开发平台3.1
数据的导入导出,在很多系统里面都比较常见,这个导入导出的操作,在Winform里面比较容易实现,但在Web上我们应该如何实现呢?本文主要介绍利用MVC4+EasyUI的特点,并结合文件上传控件,实现文 ...
- 模仿CyclicBarrier,自定义自己屏障类
简介 在这里模仿CyclicBarrier,自定义一个自己多线程屏障类,里面有个计时器count,count为0时,才唤醒线程,否则就await挂起,(没错就是用的object类的挂起和唤醒全部线程方 ...
- 利用堆实现堆排序&优先队列
数据结构之(二叉)堆一文在末尾提到"利用堆能够实现:堆排序.优先队列.".本文代码实现之. 1.堆排序 如果要实现非递减排序.则须要用要大顶堆. 此处设计到三个大顶堆的操作:(1) ...