bayesnet / bnt

Bayes Net Toolbox for Matlab
460 stars 247 forks source link

conditional linear gaussian distribution (CLG) prediction #83

Closed Vivian966 closed 4 years ago

Vivian966 commented 4 years ago

I want to predict the conditional gaussian variable Y with continuous parent X and discrete parent Q, and steps are as following: Step1: making the graph dag(1:9,10)=1
image

Step2:making the model node_sizes =[1 1 1 1 1 1 1 1 2 1]; dnodes = [9]; cnodes = mysetdiff(1:n, dnodes) onodes =[1 2 3 4 5 6 7 8 9]; bnet = mk_bnet(dag, node_sizes, 'discrete',dnodes,'observed', onodes);

Step3: Specifying the parameters seed = 0; rand('state', seed); randn('state', seed); % cnodes(X:nodes (i=1:8)): bnet.CPD{i}=root_CPD(bnet, i); % dnode(Q: node 9): bnet.CPD{9}=tabular_CPD(bnet, 9); % cnode(Y: node 10) bnet.CPD{10}=gaussian_CPD(bnet, 10);

Step4: Training the model load data –ascii; % splitting the data into two sets: train and test data ncases = size(train, 1);
cases=cell(10,ncases); observed=[1 2 3 4 5 6 7 8 9]; cases(onodes,:) = num2cell(train');
engine =jtree_inf_engine(bnet); [bnet2,LL,engine2]=learn_params_em(engine,cases,max_iter,thresh);

Step5: Inference/ prediction evidence = cell(1,10); for i=1:N % N is the number of the test data for j=1:9
evidence{j}= test(i,j); [engine3, loglik] = enter_evidence(engine2,evidence);
j=j+1; end marg = marginal_nodes(engine3,10); m(:,i)=marg.mu; end pre_mu=m';
The pre_mu has very high error with the measure value. I don't if my methods or procedures are wrong, so maybe someone could help me on this. Greetings from China, Vivian