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