贝叶斯网络(Bayesian Network)

贝叶斯网络

贝叶斯网络(Bayesian Networks)也被称为信念网络(Belif Networks)或者因果网络(Causal Networks),是描述数据变量之间依赖关系的一种图形模式,是一种用来进行推理的模型。贝叶斯网络为人们提供了一种方便的框架结构来表示因果关系,这使得不确定性推理变得在逻辑上更为清晰、可理解性强。

对于贝叶斯网络,我们可以用两种方法来看待它:首先贝叶斯网表达了各个节点间的条件独立关系,我们可以直观的从贝叶斯网当中得出属性间的条件独立以及依赖关系;另外可以认为贝叶斯网用另一种形式表示出了事件的联合概率分布,根据贝叶斯网的网络结构以及条件概率表(CPT)我们可以快速得到每个基本事件(所有属性值的一个组合)的概率。贝叶斯学习理论利用先验知识和样本数据来获得对未知样本的估计,而概率(包括联合概率和条件概率)是先验信息和样本数据信息在贝叶斯学习理论当中的表现形式。

注: 在概率论中,联合概率是指在多元的概率分布中多个随机变量分别满足各自条件的概率。举例说明:假设X和Y都服从正态分布,那么P{X<4,Y<0}就是一个联合概率,表示X<4,Y<0两个条件同时成立的概率。 联合概率:表示两个事件共同发生的概率。A与B的联合概率表示为 P(AB) 或者P(A,B),或者P(A∩B)

贝叶斯网络由以下两部分组成:

一 贝叶斯网络结构

贝叶斯网的网络结构是一个有向无环图(Directed Acyclic Graph),其中每个结点代表一个属性或者数据变量,结点间的弧代表属性(数据变量) 间的概率依赖关系。一条弧由一个属性(数据变量)A指向另外一个属性(数据变量)B说明属性A的取值可以对属性B的取值产生影响,由于是有向无环图,A、B间不会出现有向回路。在贝叶斯网当中,直接的原因结点(弧尾)A叫做其结果结点(弧头)B的双亲结点(parents),B叫做A的孩子结点(children)。如果从一个结点X有一条有向通路指向Y,则称结点X为结点Y的祖先(ancestor),同时称结点Y为结点X的后代(descendent)。
我们用下面的例子来具体说明贝叶斯网的结构:

这里写图片描述
图1 简单的贝叶斯网模型

图1 中共有五个结点和五条弧。下雪A1是一个原因结点,它会导致堵车A2和摔跤A3。而我们知道堵车A2和摔跤A3都可能最终导致上班迟到A4。另外如果在路上摔跤严重的话还可能导致骨折A5。这是一个简单的贝叶斯网络的例子。在贝叶斯网中像A1这样没有输入的结点被称作根结点(root),其他结点被统称为非根结点。

贝叶斯网络当中的弧表达了结点间的依赖关系,如果两个结点间有弧连接说明两者之间有因果联系,反之如果两者之间没有直接的弧连接或者是间接的有向联通路径,则说明两者之间没有依赖关系,即是相互独立的。结点间的相互独立关系是贝叶斯网络当中很重要的一个属性,可以大大减少建网过程当中的计算量,同时根据独立关系来学习贝叶斯网络也是一个重要的方法,这在本文后面会着重介绍。使用贝叶斯网络结构可以使人清晰的得出属性结点间的关系,进而也使得使用贝叶斯网进行推理和预测变得相对容易实现。

从上图中我们可以看出,节点间的有向路径可以不只一条,一个祖先结点可以通过不同的途径来影响它的后代结点。如我们说下雪可能会导致迟到,而导致迟到的直接原因可能是堵车,也可能是在雪天滑倒了、摔了一跤。这里每当我们说一个原因结点的出现会导致某个结果的产生时,都是一个概率的表述,而不是必然的,这样就需要为每个结点添加一个条件概率。一个节点在其双亲节点(直接的原因接点)的不同取值组合条件下取不同属性值的概率,就构成了该结点的条件概率表。

二. 条件概率表

在上一节当中已经介绍了条件概率的概念,贝叶斯网络中的条件概率表是结点的条件概率的集合。当使用贝叶斯网络进行推理时,实际上是使用条件概率表当中的先验概率和已知的证据结点来计算所查询的目标结点的后验概率的过程。

条件概率可以由某方面的专家总结以往的经验给出(但这是非常困难的,只适合某些特殊领域),另外一种方法就是通过条件概率公式 在大样本数据当中统计求得,学习条件概率表的算法将在下一节中详细介绍。在这里我们先根据上图的贝叶斯网给出其中的一些条件概率表,使大家对条件概率表有一个感性的认识。
如果将结点A1下雪当作证据结点,那么发生A2堵车的概率如何呢?下表给出了相应的条件概率:
这里写图片描述

上表是最简单的情况,如果有不只一个双亲结点的话,那么情况会变得更为复杂一些,见表2.2:
由表中可以看出,当堵车A2和摔跤A3取不同的属性值时,导致迟到A4的概率是不同的。贝叶斯网条件概率表中的每个条件概率的都是以当前结点的双亲结点做为条件集的。如果一个结点有n个父节点,在最简单的情况下(即每个结点都是二值结点,只有两个可能的属性值:True或者False),那么它的条件概率表有 2 n 2^n 2n行;如果每个属性结点有k个属性值,则有 k n k^n kn行记录,其中每行有k-1项(因为k项概率的总和为1,所以只需知道其中的k-1项,最后一项可以用减法求得),这样该条件概率表将一共有 ( k − 1 ) k n (k-1) k^n (k1)kn项记录。
根据条件概率和贝叶斯网络结构,我们不仅可以由祖先接点推出后代的结果,还可以通过后代当中的证据结点来向前推出祖先取各种状态的概率。
贝叶斯网可以处理不完整和带有噪声的数据集,因此被日益广泛的应用于各种推理程序当中。同时由于可以方便的结合已有的先验知识,将已有的经验与数据集的潜在知识相结合,可以弥补相互的片面性与缺点,因此越来越受到研究者的喜欢。

贝叶斯网络分类:
1。静态贝叶斯网络
2。动态贝叶斯网络

三 动态贝叶斯网络

在我 们 这 里所讲的DBN,它的动态,并不是说网络结构随着时间的变化而发生变化,而是样本数据,或者说观测数据,随着时间的变化而变化。其中对网络结构随时间变化的情况主要出现在这么一个问题中:对一个未知对象集进行跟踪。随着时间的变化,无法知道哪些对象产生了,而哪些对象又消失了。在A工界,这类问题被称为,'First Order",也被称为”Propositional"模型,相关讨论可以看文献〔35]0
一般 的 DBN有两个特点。网络 的 拓扑结构在每个时间片(time slice,快照) 内是相同的,而片与片之间通过类似的弧进行连接。

一个BN可以定义为: B N = ( G , θ ) BN=(G,\theta) BN=Gθ,其中 G G G X X X上联合概率分布的有向非循环图, θ \theta θ表示网络的参数。其中, X X X上的联合概率分布定义为:
P ( X 1 , X 2 , . . . , X n ) = ∏ i = i n P ( X i ∣ P a ( X i ) ) P(X_1,X_2,...,X_n)=\prod_{i=i}^nP(X_i | Pa(X_i)) P(X1,X2,...,Xn)=i=inP(XiPa(Xi))
DBN模型则将这种表述扩展到模型化含时间因素的随机过程。为了用BN表述随机过程,需要得到随机变量 X [ 1 ] , X [ 2 ] , . . . , X [ n ] X[1],X[2],...,X[n] X[1]X[2]...,X[n]上的一个概率分布,但这样一个分布是十分复杂的。因此,为了能够对复杂系统进行研究并建立相应的模型,需要做一些假设和简化条件处理。
假设条件:
1 假设在一个有限时间内条件概率变化过程对所以 t t t是一致平稳
2 假设动态概率过程是马氏的,即满足:
P ( X [ t + 1 ] ∣ X [ 1 ] , X [ 2 ] , . . . , X [ t ] ) = P ( X [ t + 1 ] ∣ X [ t ] ) P(X[t+1] | X[1],X[2],...,X[t])=P(X[t+1] | X[t]) P(X[t+1]X[1],X[2],...,X[t])=P(X[t+1]X[t])
也就是说未来时刻的概率只与当前时刻有关而与过去时刻无关
3 假设相邻时间的条件概率过程是平稳的,即 P ( X [ t + 1 ] ∣ X [ t ] ) P(X[t+1] | X[t]) P(X[t+1]X[t])与时间 t t t无关,可以容易地得到不同时间的转移概率 P ( X [ t + 1 ] ∣ X [ t ] ) P(X[t+1] | X[t]) P(X[t+1]X[t])

基于上述假设,建立在随机过程时间轨迹上的联合概率分布的DBN就由两部分组成:一个先验网 B 0 B_0 B0,定义在初始状态 X [ 1 ] X[1] X[1]上的联合概率分布;一个转移网 B → B_\to B,定义在变量 X [ 1 ] X[1] X[1] X [ 2 ] X[2] X[2]上的转移概率 P ( X [ t + 1 ] ∣ X [ t ] ) P(X[t+1] | X[t]) P(X[t+1]X[t])(对所有的 t t t都成立)
因此,若给定一个DBN模型,则在 X [ 1 ] , X [ 2 ] , . . . , X [ T ] X[1],X[2],...,X[T] X[1]X[2]...,X[T]上的联合概率分布为:
P ( X [ 1 ] , X [ 2 ] , . . . , X [ T ] ) = P B 0 ( X [ 1 ] ) ∏ t = i T P B → ( X [ t + 1 ] ∣ X [ t ] ) P(X[1],X[2],...,X[T])=P_{B_0}(X[1])\prod_{t=i}^TP_{B_\to}(X[t+1] | X[t]) P(X[1],X[2],...,X[T])=PB0(X[1])t=iTPB(X[t+1]X[t])
给出DBN定义:一个DBN可以定义为 ( B 0 , B → ) (B_0,B_\to) (B0,B)。其中 B 0 B_0 B0表示最开始的BN,从图中可以得到任一节点的先验概率 P ( X 0 ) P(X_0) P(X0) B → B_\to B表示有两个以上时间片段的BN组成的图形。

这里写图片描述

  • 35
    点赞
  • 154
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
用python写的一段贝叶斯网络的程序 This file describes a Bayes Net Toolkit that we will refer to now as BNT. This version is 0.1. Let's consider this code an "alpha" version that contains some useful functionality, but is not complete, and is not a ready-to-use "application". The purpose of the toolkit is to facilitate creating experimental Bayes nets that analyze sequences of events. The toolkit provides code to help with the following: (a) creating Bayes nets. There are three classes of nodes defined, and to construct a Bayes net, you can write code that calls the constructors of these classes, and then you can create links among them. (b) displaying Bayes nets. There is code to create new windows and to draw Bayes nets in them. This includes drawing the nodes, the arcs, the labels, and various properties of nodes. (c) propagating a-posteriori probabilities. When one node's probability changes, the posterior probabilities of nodes downstream from it may need to change, too, depending on firing thresholds, etc. There is code in the toolkit to support that. (d) simulating events ("playing" event sequences) and having the Bayes net respond to them. This functionality is split over several files. Here are the files and the functionality that they represent. BayesNetNode.py: class definition for the basic node in a Bayes net. BayesUpdating.py: computing the a-posteriori probability of a node given the probabilities of its parents. InputNode.py: class definition for "input nodes". InputNode is a subclass of BayesNetNode. Input nodes have special features that allow them to recognize evidence items (using regular-expression pattern matching of the string descriptions of events). OutputNode.py: class definition for "output nodes". OutputBode is a subclass of BayesNetNode. An output node can have a list of actions to be performed when the node's posterior probability exceeds a threshold ReadWriteSigmaFiles.py: Functionality for loading and saving Bayes nets in an XML format. SampleNets.py: Some code that constructs a sample Bayes net. This is called when SIGMAEditor.py is started up. SIGMAEditor.py: A main program that can be turned into an experimental application by adding menus, more code, etc. It has some facilities already for loading event sequence files and playing them. sample-event-file.txt: A sequence of events that exemplifies the format for these events. gma-mona.igm: A sample Bayes net in the form of an XML file. The SIGMAEditor program can read this type of file. Here are some limitations of the toolkit as of 23 February 2009: 1. Users cannot yet edit Bayes nets directly in the SIGMAEditor. Code has to be written to create new Bayes nets, at this time. 2. If you select the File menu's option to load a new Bayes net file, you get a fixed example: gma-mona.igm. This should be changed in the future to bring up a file dialog box so that the user can select the file. 3. When you "run" an event sequence in the SIGMAEditor, the program will present each event to each input node and find out if the input node's filter matches the evidence. If it does match, that fact is printed to standard output, but nothing else is done. What should then happen is that the node's probability is updated according to its response method, and if the new probability exceeds the node's threshold, then its successor ("children") get their probabilities updated, too. 4. No animation of the Bayes net is performed when an event sequence is run. Ideally, the diagram would be updated dynamically to show the activity, especially when posterior probabilities of nodes change and thresholds are exceeded. To use the BNT, do three kinds of development: A. create your own Bayes net whose input nodes correspond to pieces of evidence that might be presented and that might be relevant to drawing inferences about what's going on in the situation or process that you are analyzing. You do this by writing Python code that calls constructors etc. See the example in SampleNets.py. B. create a sample event stream that represents a plausible sequence of events that your system should be able to analyze. Put this in a file in the same format as used in sample-event-sequence.txt. C. modify the code of BNT or add new modules as necessary to obtain the functionality you want in your system. This could include code to perform actions whenever an output node's threshold is exceeded. It could include code to generate events (rather than read them from a file). And it could include code to describe more clearly what is going on whenever a node's probability is updated (e.g., what the significance of the update is -- more certainty about something, an indication that the weight of evidence is becoming strong, etc.)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值