Daniel@0: function ho1() Daniel@0: Daniel@0: % Example of how to create a higher order DBN Daniel@0: % Written by Rainer Deventer 3/28/03 Daniel@0: Daniel@0: bnet = createBNetNL(); Daniel@0: Daniel@0: %%%%%%%%%%%% Daniel@0: Daniel@0: Daniel@0: function bnet = createBNetNL(varargin) Daniel@0: % Generate a Bayesian network, which is able to model nonlinearities at Daniel@0: % the input. The only input is the order of the dynamic system. If this Daniel@0: % parameter is missing, the an order of two is assumed Daniel@0: if nargin > 0 Daniel@0: order = varargin{1} Daniel@0: else Daniel@0: order = 2; Daniel@0: end Daniel@0: Daniel@0: ss = 6; % For each time slice the following nodes are modeled Daniel@0: % ud(t_k) Discrete node, which decides whether saturation is reached. Daniel@0: % Node number 2 Daniel@0: % uv(t_k) Visible input node with node number 2 Daniel@0: % uh(t_k) Hidden input node with node number 3 Daniel@0: % y(t_k) Modeled output, Number 4 Daniel@0: % z(t_k) Disturbing variable, number 5 Daniel@0: % q(t_k), number6 6 Daniel@0: Daniel@0: intra = zeros(ss,ss); Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Within each timeslice ud(t_k) is connected with uv(t_k) and uh(t_k) % Daniel@0: % This part is used to model saturation % Daniel@0: % A connection from uv(t_k) to uh(t_k) is omitted % Daniel@0: % Additionally y(t_k) is connected with q(t_k). To model the disturbing% Daniel@0: % value z(t_k) is connected with q(t_k). % Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: intra(1,2:3) = 1; % Connections ud(t_k) -> uv(t_k) and ud(t_k) -> uh(t_k) Daniel@0: intra(4:5,6) = 1; % Connectios y(t_k) -> q(t_k) and z(t_k) -> q(t_k) Daniel@0: Daniel@0: Daniel@0: Daniel@0: inter = zeros(ss,ss,order); Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % The Markov assumption is not met as connections from time slice t to t+2 % Daniel@0: % exist. % Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: for i = 1:order Daniel@0: if i == 1 Daniel@0: inter(1,1,i) = 1; %Connect the discrete nodes. This is necessary to improve Daniel@0: %the disturbing reaction Daniel@0: inter(3,4,i) = 1; %Connect uh(t_{k-1}) with y(t_k) Daniel@0: inter(4,4,i) = 1; %Connect y(t_{k-1}) with y(t_k) Daniel@0: inter(5,5,i) = 1; %Connect z(t_{k-1}) with z(t_k) Daniel@0: else Daniel@0: inter(3,4,i) = 1; %Connect uh(t_{k-i}) with y(t_k) Daniel@0: inter(4,4,i) = 1; %Connect y(t_{k-i}) with y(t_k) Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Define the dimensions of the discrete nodes. Node 1 has two states % Daniel@0: % 1 = lower saturation reached % Daniel@0: % 2 = Upper saturation reached % Daniel@0: % Values in between are model by probabilities between 0 and 1 % Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: node_sizes = ones(1,ss); Daniel@0: node_sizes(1) = 2; Daniel@0: dnodes = [1]; Daniel@0: Daniel@0: eclass = [1:6;7 2:3 8 9 6;7 2:3 10 11 6]; Daniel@0: bnet = mk_higher_order_dbn(intra,inter,node_sizes,... Daniel@0: 'discrete',dnodes,... Daniel@0: 'eclass',eclass); Daniel@0: Daniel@0: cov_high = 400; Daniel@0: cov_low = 0.01; Daniel@0: weight1 = randn(1,1); Daniel@0: weight2 = randn(1,1); Daniel@0: weight3 = randn(1,1); Daniel@0: weight4 = randn(1,1); Daniel@0: Daniel@0: numOfNodes = 5 + order; Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Nodes of the first time-slice % Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Discrete input node, Daniel@0: bnet.CPD{1} = tabular_CPD(bnet,1,'CPT',[1/2 1/2],'adjustable',0); Daniel@0: Daniel@0: Daniel@0: % Modeled visible input Daniel@0: bnet.CPD{2} = gaussian_CPD(bnet,2,'mean',[0 10],'clamp_mean',1,... Daniel@0: 'cov',[10 10],'clamp_cov',1); Daniel@0: Daniel@0: % Modeled hidden input Daniel@0: bnet.CPD{3} = gaussian_CPD(bnet,3,'mean',[0, 10],'clamp_mean',1,... Daniel@0: 'cov',[0.1 0.1],'clamp_cov',1); Daniel@0: Daniel@0: % Modeled output in the first timeslice, thus there are no parents Daniel@0: % Usuallz the output nodes get a low covariance. But in the first Daniel@0: % time-slice a prediction of the output is not possible due to Daniel@0: % missing information Daniel@0: bnet.CPD{4} = gaussian_CPD(bnet,4,'mean',0,'clamp_mean',1,... Daniel@0: 'cov',cov_high,'clamp_cov',1); Daniel@0: Daniel@0: %Disturbance Daniel@0: bnet.CPD{5} = gaussian_CPD(bnet,5,'mean',0,... Daniel@0: 'cov',[4],... Daniel@0: 'clamp_mean',1,... Daniel@0: 'clamp_cov',1); Daniel@0: Daniel@0: %Observed output. Daniel@0: bnet.CPD{6} = gaussian_CPD(bnet,6,'mean',0,... Daniel@0: 'clamp_mean',1,... Daniel@0: 'cov',cov_low,'clamp_cov',1,... Daniel@0: 'weights',[1 1],'clamp_weights',1); Daniel@0: Daniel@0: % Discrete node at second time slice Daniel@0: bnet.CPD{7} = tabular_CPD(bnet,7,'CPT',[0.6 0.4 0.4 0.6],'adjustable',0); Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Node for the model output % Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: bnet.CPD{8} = gaussian_CPD(bnet,10,'mean',0,... Daniel@0: 'cov',cov_high,... Daniel@0: 'clamp_mean',1,... Daniel@0: 'clamp_cov',1); Daniel@0: % 'weights',[0.0791 0.9578]); Daniel@0: Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Node for the disturbance % Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: bnet.CPD{9} = gaussian_CPD(bnet,11,'mean',0,'clamp_mean',1,... Daniel@0: 'cov',[4],'clamp_cov',1,... Daniel@0: 'weights',[1],'clamp_weights',1); Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Node for the model output % Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: bnet.CPD{10} = gaussian_CPD(bnet,16,'mean',0,'clamp_mean',1,... Daniel@0: 'cov',cov_low,'clamp_cov',1); Daniel@0: % 'weights',[0.0188 -0.0067 0.0791 0.9578]); Daniel@0: Daniel@0: Daniel@0: Daniel@0: Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: % Node for the disturbance % Daniel@0: %%%%%%%%%%%%%%%%%%%%%%%%%%%% Daniel@0: bnet.CPD{11} = gaussian_CPD(bnet,17,'mean',0,'clamp_mean',1,... Daniel@0: 'cov',[0.2],'clamp_cov',1,... Daniel@0: 'weights',[1],'clamp_weights',1); Daniel@0: Daniel@0: Daniel@0: Daniel@0: