[bnet] = LearnBNwithObjectives(k,NumbVar,Card,AuxPop,AuxFunVal,learning_params) LearnBNwithObjectives: Learns the Bayesian network from the given population using Bayesian network learning algorithms of the BNtools and libraries (see references in the documentation) See also BNT structure learning package for explanation (http://bnt.insa-rouen.fr/ajouts.html) INPUTS k: Current generation NumbVar: Number of variables AuxPop: Selected population (data set for learning the BN) AuxFunVal: Evaluation of the data set (required for some learning algorithms, not for this one) Card: Vector with the dimension of all the variables. learning_params{1} = TypeLearning: Type of method used for learning the Bayesian network TypeLearning = {'pc','tree','k2','k2t'}. pc: PC algorithm. 'tree': MWST based tree algorithm. 'k2': K2 algorithm initialized from a random ordering of the variables k2t: K2 algorithm initialized from a tree dag ordering learning_params{2} = MaxParent: Maximum number of parents for the Bayesian Networks or maximum size of the conditioning set for PC. By default, MaxParent = n. learning_params{3} = epsilon: alpha is the significance level (default: 0.05) for the probabilistic independence tests in PC algorithm learning_params{4} = type_indeptest: Type of independence test used by PC. type_indeptest = {'pearson', 'LRT'} for Pearson's chi2 test (default) and G2 likelihood ratio test learning_params{5} = scoring_fn: Type of scoring function used by K2 structure learning algorithms. scoring_fn = {'bic','bayesian'}. Default (bic) learning_params{6} = verbose = {'yes','no'}. Whether to display the output of K2 learning algorithm while running OUTPUTS bnet: Bayesian network learned from the selected population Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)
0001 function[bnet] = LearnBNwithObjectives(k,NumbVar,Card,AuxPop,AuxFunVal,learning_params) 0002 % [bnet] = LearnBNwithObjectives(k,NumbVar,Card,AuxPop,AuxFunVal,learning_params) 0003 % LearnBNwithObjectives: Learns the Bayesian network from the given population using 0004 % Bayesian network learning algorithms of the BNtools and 0005 % libraries (see references in the documentation) 0006 % See also BNT structure learning package for explanation (http://bnt.insa-rouen.fr/ajouts.html) 0007 % INPUTS 0008 % k: Current generation 0009 % NumbVar: Number of variables 0010 % AuxPop: Selected population (data set for learning the BN) 0011 % AuxFunVal: Evaluation of the data set (required for some learning algorithms, not for this one) 0012 % Card: Vector with the dimension of all the variables. 0013 % learning_params{1} = TypeLearning: Type of method used for learning the Bayesian network 0014 % TypeLearning = {'pc','tree','k2','k2t'}. pc: PC algorithm. 0015 % 'tree': MWST based tree algorithm. 'k2': K2 algorithm initialized from a random 0016 % ordering of the variables k2t: K2 algorithm initialized from a tree dag ordering 0017 % learning_params{2} = MaxParent: Maximum number of parents for the Bayesian Networks or 0018 % maximum size of the conditioning set for PC. By default, MaxParent = n. 0019 % learning_params{3} = epsilon: alpha is the significance level (default: 0.05) for the 0020 % probabilistic independence tests in PC algorithm 0021 % learning_params{4} = type_indeptest: Type of independence test used by 0022 % PC. type_indeptest = {'pearson', 'LRT'} for Pearson's chi2 test (default) 0023 % and G2 likelihood ratio test 0024 % learning_params{5} = scoring_fn: Type of scoring function used by K2 structure learning algorithms. 0025 % scoring_fn = {'bic','bayesian'}. Default (bic) 0026 % learning_params{6} = verbose = {'yes','no'}. Whether to display the output of K2 learning algorithm while running 0027 % OUTPUTS 0028 % bnet: Bayesian network learned from the selected population 0029 % 0030 % Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es) 0031 0032 TypeLearning = char(cellstr(learning_params{1}(1))); 0033 MaxParent = cell2num(learning_params{1}(2)); 0034 alpha = cell2num(learning_params{1}(3)); 0035 type_indeptest = char(cellstr(learning_params{1}(4))); 0036 scoring_fn = char(cellstr(learning_params{1}(5))); 0037 verbose = char(cellstr(learning_params{1}(6))); 0038 0039 0040 SelPop = AuxPop'+1; % For the bnet learning procedure, variables are rows and observations columns 0041 % Entries in the matrix should be non-zero 0042 0043 % All nodes are set to be discrete 0044 for i=1:NumbVar 0045 nodetype{1,i} = 'tabular'; 0046 end 0047 0048 0049 switch lower(TypeLearning) 0050 case {'pc'} 0051 % PC algorithm 0052 pdag = learn_struct_pdag_pc('cond_indep_chisquare',NumbVar,MaxParent,SelPop,'pearson',alpha,Card); 0053 dag = cpdag_to_dag(pdag); 0054 case {'tree'} 0055 % MWST based tree algorithm 0056 root = fix(rand*NumbVar)+1; 0057 dag = full(learn_struct_mwst(SelPop,[],ones(1,NumbVar),nodetype,'mutual_info',root)); 0058 case {'k2'} 0059 %K2 algorithm 0060 root = fix(rand*NumbVar)+1; 0061 order = randperm(NumbVar); 0062 dag = learn_struct_K2(SelPop,Card,order,'max_fan_in',MaxParent,'scoring_fn',scoring_fn); 0063 case {'k2t'} 0064 %K2 algorithm initialized from a tree dag 0065 root = fix(rand*NumbVar)+1; 0066 dag = full(learn_struct_mwst(SelPop,[],ones(1,NumbVar),nodetype,'mutual_info',root)); 0067 order = topological_sort(dag); 0068 dag = learn_struct_K2(SelPop,Card,order,'max_fan_in',MaxParent,'scoring_fn',scoring_fn); 0069 end, 0070 0071 0072 init_bnet = mk_bnet(dag,Card); 0073 % All nodes are set to be discrete 0074 for i=1:NumbVar 0075 init_bnet.CPD{i} = tabular_CPD(init_bnet,i); 0076 end, 0077 0078 bnet = learn_params(init_bnet,SelPop); 0079 %figure 0080 %draw_graph(dag); 0081 0082