[Cliques,deep]=FactAffinityElim(MI,vars,sizeconstraint,p,deep) FactAffinityElim: Finds a set of cliques from a matrix of mutual information using affinity propagation. The application of the algorithm is recursive. INPUTS vars: vars that will be involved in the factorization (initially all the variables sizeconstraint: Maximum size of the factors involved in the factorization p: Preference parameter for affinity propagation deep: Parameter to control the recursive calls OUTPUTS Cliques: Structure of the model in a list of cliques that defines the (chain shaped) junction tree. 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. Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)
0001 function [Cliques,deep]=FactAffinityElim(MI,vars,sizeconstraint,p,deep) 0002 % [Cliques,deep]=FactAffinityElim(MI,vars,sizeconstraint,p,deep) 0003 % FactAffinityElim: Finds a set of cliques from a matrix of mutual information 0004 % using affinity propagation. The application of 0005 % the algorithm is recursive. 0006 % INPUTS 0007 % vars: vars that will be involved in the factorization (initially all the 0008 % variables 0009 % sizeconstraint: Maximum size of the factors involved in the factorization 0010 % p: Preference parameter for affinity propagation 0011 % deep: Parameter to control the recursive calls 0012 % OUTPUTS 0013 % Cliques: Structure of the model in a list of cliques that defines the (chain shaped) junction tree. 0014 % Each row of Cliques is a clique. The first value is the number of overlapping variables. 0015 % The second, is the number of new variables. 0016 % Then, overlapping variables are listed and finally new variables are listed. 0017 % 0018 % Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es) 0019 0020 0021 if deep>=10 0022 MI = MI + mean(MI(:))*rand(size(MI)); 0023 end 0024 0025 0026 n = size(MI,1); 0027 outvars = []; 0028 0029 [idx,netsim,dpsim,expref,unconverged]=apcluster(MI,p,'dampfact',0.5); %Find the clusters of the MI matrix 0030 nconv = 0; 0031 while(unconverged & nconv<10) 0032 [idx,netsim,dpsim,expref,unconverged]=apcluster(MI+min(MI(:))*rand(size(MI)),p,'dampfact',0.9); 0033 nconv = nconv+1 0034 end 0035 0036 Cliques = []; 0037 nclusters = length(unique(idx)); 0038 exemplars = unique(idx); 0039 for i=1:nclusters 0040 clusters{i} = find(idx==exemplars(i)); 0041 clustsize = size(clusters{i},1); 0042 0043 if(clustsize>sizeconstraint) 0044 outvars = [outvars,clusters{i}']; 0045 else 0046 %vars(clusters{i}')' 0047 Cliq = [0,clustsize,vars(clusters{i}'),zeros(1,sizeconstraint-clustsize)]; 0048 Cliques = [Cliques;Cliq]; 0049 end 0050 end 0051 if(~isempty(outvars)) 0052 if(isempty(Cliques)) 0053 deep = deep + 1; 0054 end, 0055 0056 MI1 = MI(:,outvars); 0057 MI1 = MI1(outvars,:); 0058 p = median(MI1); %median(MI1(:)); 0059 %p= min(MI1(:))+(max(MI1(:))-min(MI1(:)))*rand(); % Set preference to median similarity 0060 [Cliques1,deep]=FactAffinityElim(MI1,vars(outvars),sizeconstraint,p,deep); 0061 Cliques = [Cliques;Cliques1]; 0062 end 0063 0064 0065