[model] = LearnTreeModel(k,NumbVar,Card,SelPop,AuxFunVal,learning_params) LearnTreeModel: A maximum weighted tree is learned from the matrix of mutual information between the variables INPUTS k: Current generation NumbVar: Number of variables Card: Vector with the dimension of all the variables. SelPop: Population from which the model is learned AuxFunVal: Evaluation of the data set (required for some learning algorithms, not for this one) learning_params{1}(1) = {} OUTPUTS model: Structure containing the tree structure (model{1} = Cliques) and the parameters (model{2} = Tables) Last version 5/6/2009. Roberto Santana (roberto.santana@ehu.es)
0001 function [model] = LearnTreeModel(k,NumbVar,Card,SelPop,AuxFunVal,learning_params) 0002 % [model] = LearnTreeModel(k,NumbVar,Card,SelPop,AuxFunVal,learning_params) 0003 % LearnTreeModel: A maximum weighted tree is learned from the matrix of mutual information between the variables 0004 % INPUTS 0005 % k: Current generation 0006 % NumbVar: Number of variables 0007 % Card: Vector with the dimension of all the variables. 0008 % SelPop: Population from which the model is learned 0009 % AuxFunVal: Evaluation of the data set (required for some learning algorithms, not for this one) 0010 % learning_params{1}(1) = {} 0011 % OUTPUTS 0012 % model: Structure containing the tree structure (model{1} = Cliques) 0013 % and the parameters (model{2} = Tables) 0014 % 0015 % Last version 5/6/2009. Roberto Santana (roberto.santana@ehu.es) 0016 0017 N = size(SelPop,1); 0018 Cliques = []; 0019 0020 % Univariate and Bivariate probabilities are learned 0021 [UnivProb,BivProb]= FindMargProb(SelPop,NumbVar,Card); 0022 0023 % The Matrix of Mutual information is learned 0024 MI = IntMutualInfFromMargProb(NumbVar,Card,UnivProb,BivProb); 0025 0026 % The tree is extracted from the matrix of mutual information 0027 [Cliques] = CreateTreeStructure(MI); 0028 0029 for i=1:NumbVar 0030 nparent = Cliques(i,1); 0031 if nparent== 0 % The variable has no parent 0032 Tables{i} = (UnivProb{i}*N + 1) ./ ( (N + Card(i))*ones(1,Card(i))); 0033 else 0034 parent = Cliques(i,3); 0035 %[i,parent,Card(i),Card(parent)] 0036 if parent<i 0037 a = BivProb{parent,i}; 0038 %AuxBivProb = reshape(a',Card(parent),Card(i)) 0039 AuxBivProb = reshape(a',Card(i),Card(parent))'; 0040 else 0041 a = BivProb{i,parent}; 0042 AuxBivProb = reshape(a',Card(parent),Card(i)); 0043 0044 end 0045 aux = repmat(UnivProb{parent}',1,Card(i)); 0046 auxcard = repmat(Card(i),Card(parent),Card(i)); 0047 CondBivProb = (AuxBivProb*N +1) ./ (aux*N + auxcard); % Laplace Estimator 0048 Tables{i} = CondBivProb; 0049 end 0050 0051 end 0052 0053 model{1} = Cliques; 0054 model{2} = Tables; 0055 0056 return; 0057 0058 0059