about summary refs log tree commit diff
path: root/sourcecodes/parameter_learning/parameterLearning.m
blob: 2c4a1f9f538b6fb41cd4211dd0cdaccfa95e765e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function [ bnet ] = parameterLearning( bnet,cases,engine_name )
%parameterLearning Do parameter learning and inference
% It returns the bnet with parameters learned from the data in cases.
% 
% This is very basic now. It could be modified to use different engine
%  types in the future. Now, I always use the 'jtree_inf_engine'.
%  with dirichlet priors
%
% parameterLearning is called by runBN_initial.m, 
%   Predictmultiple.m, and Predictmultipleintervention.m


%engine is an optional argument
if nargin < 3
    engine_name = 'jtree_inf_engine';
end


%First do parameter learning with all the data
[bnet] = getParams(bnet,cases);




end

function [ bnet ] = getParams( bnet, cases )
%getParams Code to initialize CPT and do parameter learning.
%This will be very basic for now.  I can add more options later.
%

dnodes = bnet.dnodes;
cnodes = bnet.cnodes;
nnodes = size(dnodes,2)+size(cnodes,2);

%make dnodes tabular_CPT
for i = 1:size(dnodes,2)
%    bnet.CPD{dnodes(i)} = tabular_CPD(bnet,dnodes(i));
    bnet.CPD{dnodes(i)} = tabular_CPD(bnet,dnodes(i),'prior_type','dirichlet');
end

for i = 1:size(cnodes,2)
    bnet.CPD{cnodes(i)} = gaussian_CPD(bnet,cnodes(i));
end

bnet = learn_params(bnet,cases);


end