阡陌交通是什么意思:如何使用贝叶斯网络工具箱 - 讶究'Blog - 欢迎光临 讶究'Blog O(∩_∩)O...
来源:百度文库 编辑:中财网 时间:2024/05/04 18:51:30
如何使用贝叶斯网络工具箱
admin , 2010/03/08 11:08 , Matlab , 评论(0) , 阅读(601) , Via 本站原创 大 | 中 | 小 引用地址:注意: 该地址仅在今日23:59:59之前有效
如何使用贝叶斯网络工具箱
贝叶斯网络是一种概率网络,它是基于概率推理的图形化网络,而贝叶斯公式则是这个概率网络的基础。
贝叶斯网络的拓扑结构是一个具有概率分布的有向弧段(DAG)。它是由节点和有向弧段组成的。节点代表事件或变量,弧段代表节点之间的因果关系或概率关系,而弧段是有向的,不构成回路。
贝叶斯网络工具箱采用MATLAB语言编制的贝叶斯网络工具箱(Bayesian Networks Toolbox,BNT)可实现贝叶斯网络结构学习、参数学习、推理和构建贝叶斯分类器,此工具箱在贝叶斯学习编程方面非常灵活。利用贝叶斯网络工具箱可以解决贝叶斯学习和推理问题,下面以运行官方模板为例。
详细信息:http://www.media.mit.edu/wearables/mithril/BNT/mixtureBNT.txt
下载mixtureBNT
http://www.media.mit.edu/wearables/mithril/BNT/mixtureBNT.zip
http://www.media.mit.edu/wearables/mithril/BNT/mixtureBNT.tar.gz
>> cd d:\我的文档\桌面\mixtureBNT
>> dir
. mixtureBNT.m mixtureBNT.txt
.. mixtureBNT.mat
>> mixtureBNT
ans =
570 31
ans =
120 31
EM iteration 1, ll = -20167.3701
EM iteration 2, ll = 6959.8468
EM iteration 3, ll = 6959.8468
EM iteration 4, ll = 6959.8469
EM iteration 5, ll = 6959.8471
EM iteration 6, ll = 6959.8482
EM iteration 7, ll = 6959.8519
EM iteration 8, ll = 6959.8640
EM iteration 9, ll = 6959.8963
EM iteration 10, ll = 6959.9513
Current plot held
Current plot held
>>
附:mixtureBNT.m 内容
load 'mixtureBNT.mat'
size(walkingX)
size(runningX)
dag = [ 0 1 1 ; 0 0 1 ; 0 0 0 ];
discrete_nodes = [1 2];
nodes = [1 : 3];
node_sizes=[ 2 2 31];
bnet = mk_bnet(dag, node_sizes, 'discrete', discrete_nodes);
bnet.CPD{1} = tabular_CPD(bnet,1);
bnet.CPD{2} = tabular_CPD(bnet,2);
bnet.CPD{3} = gaussian_CPD(bnet, 3);
%bnet.CPD{3} = gaussian_CPD(bnet, 3,'cov_type','diag');
trainingX = walkingX(1:100,:);
trainingX(101:200,:)=runningX(1:100,:);
trainingC(1:100) = 1; %% Class 1 is walking
trainingC(101:200) = 2; %% Class 2 is running
testX(1:20,:) = walkingX(101:120,:); %% The first 20 are walking
testX(21:40,:) = runningX(101:120,:); %% The next 20 are running
training= cell(3,length(trainingX));
training(3,:) = num2cell(trainingX',1);
training(1,:) = num2cell(trainingC,1);
engine = jtree_inf_engine(bnet);
maxiter=10; %% The number of iterations of EM (max)
epsilon=1e-100; %% A very small stopping criterion
[bnet2, ll, engine2] = learn_params_em(engine,training,maxiter,epsilon);
class0= cell(3,1); %% Create an empty cell array for observations
class1 = class0;
class2 = class0;
class1{1} = 1; %% The class node is observed to be walking
class2{1} = 2; %% The class node is observed to be running
for i=1:100
sample1=sample_bnet(bnet2,'evidence',class1);
sample2=sample_bnet(bnet2,'evidence',class2);
modelX(i,:)=sample1{3}';
modelX(i+100,:)=sample2{3}';
end
figure
subplot(2,1,1);
plot(trainingX);
subplot(2,1,2);
plot(modelX);
evidence=class0; %% Start out with nothing observed
for i=1:40
evidence{3}=testX(i,:)';
[engine3, ll] = enter_evidence(engine2,evidence);
marg = marginal_nodes(engine3,1);
p(i,:)=marg.T';
end
figure;
subplot(2,1,1);
plot(testX);
hold
plot(p(:,1)); %% Plot the output of the walking classifier
subplot(2,1,2);
plot(testX);
hold
plot(p(:,2)); %% Plot the output of the running classifier