Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/ho1.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function ho1() | |
2 | |
3 % Example of how to create a higher order DBN | |
4 % Written by Rainer Deventer <deventer@informatik.uni-erlangen.de> 3/28/03 | |
5 | |
6 bnet = createBNetNL(); | |
7 | |
8 %%%%%%%%%%%% | |
9 | |
10 | |
11 function bnet = createBNetNL(varargin) | |
12 % Generate a Bayesian network, which is able to model nonlinearities at | |
13 % the input. The only input is the order of the dynamic system. If this | |
14 % parameter is missing, the an order of two is assumed | |
15 if nargin > 0 | |
16 order = varargin{1} | |
17 else | |
18 order = 2; | |
19 end | |
20 | |
21 ss = 6; % For each time slice the following nodes are modeled | |
22 % ud(t_k) Discrete node, which decides whether saturation is reached. | |
23 % Node number 2 | |
24 % uv(t_k) Visible input node with node number 2 | |
25 % uh(t_k) Hidden input node with node number 3 | |
26 % y(t_k) Modeled output, Number 4 | |
27 % z(t_k) Disturbing variable, number 5 | |
28 % q(t_k), number6 6 | |
29 | |
30 intra = zeros(ss,ss); | |
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
32 % Within each timeslice ud(t_k) is connected with uv(t_k) and uh(t_k) % | |
33 % This part is used to model saturation % | |
34 % A connection from uv(t_k) to uh(t_k) is omitted % | |
35 % Additionally y(t_k) is connected with q(t_k). To model the disturbing% | |
36 % value z(t_k) is connected with q(t_k). % | |
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
38 intra(1,2:3) = 1; % Connections ud(t_k) -> uv(t_k) and ud(t_k) -> uh(t_k) | |
39 intra(4:5,6) = 1; % Connectios y(t_k) -> q(t_k) and z(t_k) -> q(t_k) | |
40 | |
41 | |
42 | |
43 inter = zeros(ss,ss,order); | |
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
45 % The Markov assumption is not met as connections from time slice t to t+2 % | |
46 % exist. % | |
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
48 for i = 1:order | |
49 if i == 1 | |
50 inter(1,1,i) = 1; %Connect the discrete nodes. This is necessary to improve | |
51 %the disturbing reaction | |
52 inter(3,4,i) = 1; %Connect uh(t_{k-1}) with y(t_k) | |
53 inter(4,4,i) = 1; %Connect y(t_{k-1}) with y(t_k) | |
54 inter(5,5,i) = 1; %Connect z(t_{k-1}) with z(t_k) | |
55 else | |
56 inter(3,4,i) = 1; %Connect uh(t_{k-i}) with y(t_k) | |
57 inter(4,4,i) = 1; %Connect y(t_{k-i}) with y(t_k) | |
58 end | |
59 end | |
60 | |
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
62 % Define the dimensions of the discrete nodes. Node 1 has two states % | |
63 % 1 = lower saturation reached % | |
64 % 2 = Upper saturation reached % | |
65 % Values in between are model by probabilities between 0 and 1 % | |
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
67 node_sizes = ones(1,ss); | |
68 node_sizes(1) = 2; | |
69 dnodes = [1]; | |
70 | |
71 eclass = [1:6;7 2:3 8 9 6;7 2:3 10 11 6]; | |
72 bnet = mk_higher_order_dbn(intra,inter,node_sizes,... | |
73 'discrete',dnodes,... | |
74 'eclass',eclass); | |
75 | |
76 cov_high = 400; | |
77 cov_low = 0.01; | |
78 weight1 = randn(1,1); | |
79 weight2 = randn(1,1); | |
80 weight3 = randn(1,1); | |
81 weight4 = randn(1,1); | |
82 | |
83 numOfNodes = 5 + order; | |
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
85 % Nodes of the first time-slice % | |
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
87 % Discrete input node, | |
88 bnet.CPD{1} = tabular_CPD(bnet,1,'CPT',[1/2 1/2],'adjustable',0); | |
89 | |
90 | |
91 % Modeled visible input | |
92 bnet.CPD{2} = gaussian_CPD(bnet,2,'mean',[0 10],'clamp_mean',1,... | |
93 'cov',[10 10],'clamp_cov',1); | |
94 | |
95 % Modeled hidden input | |
96 bnet.CPD{3} = gaussian_CPD(bnet,3,'mean',[0, 10],'clamp_mean',1,... | |
97 'cov',[0.1 0.1],'clamp_cov',1); | |
98 | |
99 % Modeled output in the first timeslice, thus there are no parents | |
100 % Usuallz the output nodes get a low covariance. But in the first | |
101 % time-slice a prediction of the output is not possible due to | |
102 % missing information | |
103 bnet.CPD{4} = gaussian_CPD(bnet,4,'mean',0,'clamp_mean',1,... | |
104 'cov',cov_high,'clamp_cov',1); | |
105 | |
106 %Disturbance | |
107 bnet.CPD{5} = gaussian_CPD(bnet,5,'mean',0,... | |
108 'cov',[4],... | |
109 'clamp_mean',1,... | |
110 'clamp_cov',1); | |
111 | |
112 %Observed output. | |
113 bnet.CPD{6} = gaussian_CPD(bnet,6,'mean',0,... | |
114 'clamp_mean',1,... | |
115 'cov',cov_low,'clamp_cov',1,... | |
116 'weights',[1 1],'clamp_weights',1); | |
117 | |
118 % Discrete node at second time slice | |
119 bnet.CPD{7} = tabular_CPD(bnet,7,'CPT',[0.6 0.4 0.4 0.6],'adjustable',0); | |
120 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
121 % Node for the model output % | |
122 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
123 bnet.CPD{8} = gaussian_CPD(bnet,10,'mean',0,... | |
124 'cov',cov_high,... | |
125 'clamp_mean',1,... | |
126 'clamp_cov',1); | |
127 % 'weights',[0.0791 0.9578]); | |
128 | |
129 | |
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
131 % Node for the disturbance % | |
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
133 bnet.CPD{9} = gaussian_CPD(bnet,11,'mean',0,'clamp_mean',1,... | |
134 'cov',[4],'clamp_cov',1,... | |
135 'weights',[1],'clamp_weights',1); | |
136 | |
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
138 % Node for the model output % | |
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
140 bnet.CPD{10} = gaussian_CPD(bnet,16,'mean',0,'clamp_mean',1,... | |
141 'cov',cov_low,'clamp_cov',1); | |
142 % 'weights',[0.0188 -0.0067 0.0791 0.9578]); | |
143 | |
144 | |
145 | |
146 | |
147 %%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
148 % Node for the disturbance % | |
149 %%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
150 bnet.CPD{11} = gaussian_CPD(bnet,17,'mean',0,'clamp_mean',1,... | |
151 'cov',[0.2],'clamp_cov',1,... | |
152 'weights',[1],'clamp_weights',1); | |
153 | |
154 | |
155 | |
156 |