Home > Mateda2.0 > learning > LearnMOAProb.m

# LearnMOAProb

## PURPOSE

[Tables] = LearnMOAProb(Cliques,SelPop,NumbVar,N,Card)

## SYNOPSIS

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

## DESCRIPTION

     [Tables] = LearnMOAProb(Cliques,SelPop,NumbVar,N,Card)
     LearnMOAProb:   Learn the marginal tables for each clique (the variable and its neighborhood)

     INPUT
     Cliques:    Structure of the model in a list of cliques that defines the  neighborhood of the variable
                 Each row of Cliques is a clique. The first value is the number of overlapping variables (neighbors of
                 variable i)
                 The second, is the number of new variables (Variable i, but it could be extended to blocks of variables).
                 Then, neighbor  variables are listed and  finally variable i is listed.
     SelPop:     Selected population
     NumbVar:    Number of variables
     N:          Size of the new population
     Card:       Vector with the dimension of all the variables.

     OUTPUT
     Tables:     Probability tables for each clique

     Last version 8/26/2008. Roberto Santana (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:

## SOURCE CODE

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