annotate toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/ho1.m @ 0:cc4b1211e677 tip

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