[run_structures] = ReadMNStructures(n, maxgen, nruns,AllModels) ReadMNStructures: Given the MN or factorization models learned during the execution of Mateda (i.e. Cliques saved in Cache{k,:}. Extract information ready for analysis and visualization INPUTS n: Number of variables mangen: maximum number of generations nruns: number of runs of the algorithm AllModels: Cell array containing in each row all the factorized models saved during one run of the corresponding EDA (e.g. MOA,FDA,etc) , i.e. AllModels{i} = Cache{3,:} where Cache is the output of the EDA that learns the factorizations OUTPUTS run_structures{1} = indexmatrix(n,n): Associates an index to each possible edge in the network. e.g. indexmatrix(1,2) = 1, number of edges m = n*(n+1)/2; run_structures{2} = AllBigMatrices{nruns}(m,maxgen}: For each run contains whether the edge i appeared in generation j run_structures{3} = AllSumMatrices(m,maxgen): = \sum_i^nruns AllBigMatrices{i}, i.e. the number of runs that each edge i appeared in generation j run_structures{4} = AllContactMatrix{maxgen}(n,n): The number of runs in which edge i,j was present in generation k. run_structures{5} = SumAllContactMatrix(n,n): = \sum_k^maxgen AllContactMatrix{k}. i.e. Total number of times edge i,j was present in all the structures learned in all generations of all runs. Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)
0001 function[run_structures] = ReadMNStructures(n, maxgen, nruns,AllModels) 0002 % [run_structures] = ReadMNStructures(n, maxgen, nruns,AllModels) 0003 % ReadMNStructures: Given the MN or factorization models learned during the execution of 0004 % Mateda (i.e. Cliques saved in Cache{k,:}. Extract information 0005 % ready for analysis and visualization 0006 % INPUTS 0007 % n: Number of variables 0008 % mangen: maximum number of generations 0009 % nruns: number of runs of the algorithm 0010 % AllModels: Cell array containing in each row all the factorized models saved during 0011 % one run of the corresponding EDA (e.g. MOA,FDA,etc) , i.e. AllModels{i} = Cache{3,:} where Cache 0012 % is the output of the EDA that learns the factorizations 0013 % OUTPUTS 0014 % run_structures{1} = indexmatrix(n,n): Associates an index to each possible edge in the network. 0015 % e.g. indexmatrix(1,2) = 1, number of edges m = n*(n+1)/2; 0016 % run_structures{2} = AllBigMatrices{nruns}(m,maxgen}: For each run contains whether the edge i appeared in generation j 0017 % run_structures{3} = AllSumMatrices(m,maxgen): = \sum_i^nruns AllBigMatrices{i}, 0018 % i.e. the number of runs that each edge i appeared in generation j 0019 % run_structures{4} = AllContactMatrix{maxgen}(n,n): The number of runs in which edge i,j 0020 % was present in generation k. 0021 % run_structures{5} = SumAllContactMatrix(n,n): = \sum_k^maxgen AllContactMatrix{k}. 0022 % i.e. Total number of times edge i,j was present in all the structures 0023 % learned in all generations of all runs. 0024 % 0025 % Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es) 0026 0027 0028 [m,indexmatrix] = Find_indexmatrix(n); 0029 0030 0031 % The matrices containing the occurrence of edges at each generation are constructed 0032 AllSumMatrices = zeros(m,maxgen); 0033 0034 for j=1:maxgen 0035 AllContactMatrix{j}= zeros(n,n); 0036 end 0037 0038 for i=1:nruns, 0039 AllCliques = AllModels{i}; 0040 BigMatrix = zeros(m,maxgen); 0041 edgemat = zeros(n,n); 0042 for j=1:size(AllCliques,2), 0043 Cliques = AllCliques{j}; 0044 for k=1:size(Cliques,1) 0045 for kk=3:size(Cliques(k,:),2)-1; 0046 for kkk=kk+1:size(Cliques(k,:),2); 0047 edgemat(Cliques(k,kk),Cliques(k,kkk)) = 1; 0048 end 0049 end 0050 end 0051 sim_mat = (edgemat' + edgemat) > 0; 0052 AllContactMatrix{j} = AllContactMatrix{j} + sim_mat; 0053 edgeindex = indexmatrix(find(sim_mat==1)); 0054 if ~isempty(edgeindex) 0055 BigMatrix(edgeindex,j) = 1; 0056 end 0057 end 0058 AllBigMatrices{i} = BigMatrix; 0059 AllSumMatrices = AllSumMatrices + BigMatrix; 0060 end 0061 0062 SumAllContactMatrix = zeros(n,n); 0063 for j=1:maxgen 0064 SumAllContactMatrix = SumAllContactMatrix + AllContactMatrix{j}; 0065 end 0066 0067 run_structures{1} = indexmatrix; 0068 run_structures{2} = AllBigMatrices; 0069 run_structures{3} = AllSumMatrices; 0070 run_structures{4} = AllContactMatrix; 0071 run_structures{5} = SumAllContactMatrix; 0072 0073 0074 0075