Home > Mateda2.0 > learning > LearnFDAParameters.m

# LearnFDAParameters

## PURPOSE

[Tables] = LearnFDAParameters(Cliques,SelPop,NumbVar,Card)

## SYNOPSIS

function[Tables] = LearnFDAParameters(Cliques,SelPop,NumbVar,Card)

## DESCRIPTION

     [Tables] = LearnFDAParameters(Cliques,SelPop,NumbVar,Card)
     LearnFDAParameter: The parameters of the factorized  model represented in Cliques
                        are learned from data
     INPUTS
     Cliques: Structure of the model in a list of cliques that defines the junction graph.
              Each row of Cliques is a clique. The first value is the number of overlapping variables.
              The second, is the number of new variables.
              Then, overlapping variables are listed and  finally new variables are listed.
     NumbVar: Number of variables
     Card: Vector with the dimension of all the variables.
     SelPop:  Population from which the model is learned
     OUTPUTS
     Tables: Probability tables for each variable conditioned on its neighbors

     Last version 8/26/2008. Roberto Santana and Siddarta Shakya (roberto.santana@ehu.es)

## CROSS-REFERENCE INFORMATION

This function calls:

- FindAccCard [AccCard] = FindAccCard(length,Card)
- IndexconvertCard [num] = IndexconvertCard(valindex,length,AccCard)
- NumconvertCard [valindex] = NumconvertCard(num,length,AccCard)

This function is called by:

- LearnFDA [model] = LearnFDA(k,NumbVar,Card,SelPop,AuxFunVal,learning_params)
- LearnMOAModel [model] = LearnMOAModel(k,NumbVar,Card,SelPop,AuxFunVal,learning_params)
- LearnMargProdModel [model] = LearnMargProdModel(k,NumbVar,Card,SelPop,AuxFunVal,learning_params)

## SOURCE CODE

    0001 function[Tables] = LearnFDAParameters(Cliques,SelPop,NumbVar,Card)
    0002 % [Tables] = LearnFDAParameters(Cliques,SelPop,NumbVar,Card)
    0003 % LearnFDAParameter: The parameters of the factorized  model represented in Cliques
    0004 %                    are learned from data
    0005 % INPUTS
    0006 % Cliques: Structure of the model in a list of cliques that defines the junction graph.
    0007 %          Each row of Cliques is a clique. The first value is the number of overlapping variables.
    0008 %          The second, is the number of new variables.
    0009 %          Then, overlapping variables are listed and  finally new variables are listed.
    0010 % NumbVar: Number of variables
    0011 % Card: Vector with the dimension of all the variables.
    0012 % SelPop:  Population from which the model is learned
    0013 % OUTPUTS
    0014 % Tables: Probability tables for each variable conditioned on its neighbors
    0015 %
    0016 % Last version 8/26/2008. Roberto Santana and Siddarta Shakya (roberto.santana@ehu.es)
    0017
    0018
    0019 NumberCliques = size(Cliques,1);
    0020
    0021
    0022 %%%%%%%%%%%%%%%%%%%%%%  First step  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0023
    0024 % The tables of all the cliques are filled
    0025
    0026
    0027 for i=1:size(Cliques,1)
    0028
    0029   sizeCliqOther = Cliques(i,2);
    0030   sizeCliqSolap = Cliques(i,1);
    0031
    0032   CliqOther = Cliques(i,Cliques(i,1)+3:Cliques(i,1)+Cliques(i,2)+2);
    0033   AccCardOther = FindAccCard(sizeCliqOther,Card(CliqOther));
    0034   dimOther =   NumconvertCard(Card(CliqOther)-1,sizeCliqOther,AccCardOther)+1;
    0035
    0036   if(sizeCliqSolap > 0)
    0037     CliqSolap = Cliques(i,3:(Cliques(i,1)+2));
    0038     AccCardSolap = FindAccCard(sizeCliqSolap,Card(CliqSolap));
    0039     dimSolap =   NumconvertCard(Card(CliqSolap)-1,sizeCliqSolap,AccCardSolap)+1;
    0040     aux=zeros(dimSolap,dimOther);
    0041   else
    0042     AccCardSolap = [];
    0043     CliqSolap = [];
    0044     aux=zeros(1,dimOther);
    0045     dimSolap = 1;
    0046   end
    0047
    0048   AllVars = [CliqSolap,CliqOther];
    0049
    0050
    0051  for j=1:dimSolap
    0052     if (sizeCliqSolap>0)
    0053       solapval = IndexconvertCard(j-1,sizeCliqSolap,AccCardSolap);
    0054     else
    0055       solapval=[];
    0056     end
    0057
    0058     for k=1:dimOther
    0059      auxSelPop=SelPop(:,[CliqSolap,CliqOther]);
    0060      otherval =  IndexconvertCard(k-1,sizeCliqOther,AccCardOther);
    0061      allvarvalues = [solapval,otherval];
    0062
    0063      if(size(allvarvalues,2)==1)
    0064        aux(j,k) =  sum((auxSelPop==repmat(allvarvalues,size(SelPop,1),1))');
    0065      else
    0066        aux(j,k)=sum( sum((auxSelPop==repmat(allvarvalues,size(SelPop,1),1))') == size(allvarvalues,2));
    0067      end
    0068     end
    0069    %aux(j,:) = (aux(j,:))/(sum(aux(j,:)));
    0070    aux(j,:) = (aux(j,:)+1)/(sum(aux(j,:))+dimOther); % Laplace Estimator
    0071   end
    0072  %aux=aux/sum(sum(aux)); % Normalization
    0073
    0074
    0075  % En Table i se guardan las probabilidades del clique i
    0076
    0077  eval(['Tables{',num2str(i),'}=aux;']);
    0078
    0079 end
    0080