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