Home > Mateda2.0 > knowledge_extraction > visualization > MakePajekDynGraphFromDags.m

# MakePajekDynGraphFromDags

## PURPOSE

MakePajekDynGraphFromDags(listdags,pajekfilename)

## SYNOPSIS

function MakePajekDynGraphFromDags(listdags,pajekfilename)

## DESCRIPTION

     MakePajekDynGraphFromDags(listdags,pajekfilename)
     MakePajekDynGraphFromDags:  Creates a dynamic graph in .tin format (to be read by
     Pajek program http://vlado.fmf.uni-lj.si/pub/networks/pajek/ ) of the Bayesian networks
     structure learned at each step of an EDA that learns Bayesian networks
     Pajek allows sophisticated network analysis and visualization
     INPUTS
     listdag: List of Bayesian network structures. listdags{i} is the dag
     learned at generation i
     pajekfilename: Name of the pajek file containing the structure of the
     network

     EXAMPLE
    for i=1:size(Cache,2),
    listdags{i} = Cache{3,i}
    end
     MakePajekDynGraphFromDags(listdags,'EDAstructures.tin')

     Last version 3/9/2009. Roberto Santana (roberto.santana@ehu.es)

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function  MakePajekDynGraphFromDags(listdags,pajekfilename)
    0002 % MakePajekDynGraphFromDags(listdags,pajekfilename)
    0003 % MakePajekDynGraphFromDags:  Creates a dynamic graph in .tin format (to be read by
    0004 % Pajek program http://vlado.fmf.uni-lj.si/pub/networks/pajek/ ) of the Bayesian networks
    0005 % structure learned at each step of an EDA that learns Bayesian networks
    0006 % Pajek allows sophisticated network analysis and visualization
    0007 % INPUTS
    0008 % listdag: List of Bayesian network structures. listdags{i} is the dag
    0009 % learned at generation i
    0010 % pajekfilename: Name of the pajek file containing the structure of the
    0011 % network
    0012 %
    0013 %
    0014 % EXAMPLE
    0015  %for i=1:size(Cache,2),
    0016   %listdags{i} = Cache{3,i}
    0017  %end
    0018 % MakePajekDynGraphFromDags(listdags,'EDAstructures.tin')
    0019 %
    0020 % Last version 3/9/2009. Roberto Santana (roberto.santana@ehu.es)
    0021
    0022
    0023 ndags = size(listdags,2);
    0024 n = size(listdags{1}.dag,1);
    0025
    0026 Pos(:,1) = [0:1/n:1];
    0027 Pos(:,2) = 0.5;
    0028
    0029
    0030
    0031 fid = fopen(pajekfilename,'wt');
    0032         fprintf(fid,'*Vertices %d \n', n);
    0033         fprintf(fid,'*Events \n');
    0034
    0035         fprintf(fid,'TI = 1 \n');
    0036         for i=1:n,
    0037           auxstr = ['"v',num2str(i),'"'];
    0038           auxstr1 = 'ellipse ic Black fos 20';
    0039           fprintf(fid,'AV %d %s %d %d %s \n',i,auxstr,Pos(i,1),Pos(i,2),auxstr1);
    0040         end,
    0041
    0042    for t=1:ndags
    0043     if(t>1)
    0044       for i=1:n,
    0045        for j=1:n,
    0046          if listdags{t-1}.dag(i,j)==1
    0047              fprintf(fid,'DA %d %d \n',i,j);
    0048          end
    0049        end
    0050       end
    0051     end
    0052       for i=1:n,
    0053        for j=1:n,
    0054          if listdags{t}.dag(i,j)==1
    0055              fprintf(fid,'AA %d %d \n',i,j);
    0056              fprintf(fid,'SA %d %d \n',i,j);
    0057          end
    0058        end
    0059       end
    0060       fprintf(fid,'TE %d \n',t);
    0061       if t<ndags
    0062         fprintf(fid,'TI %d \n',t+1);
    0063       end
    0064    end
    0065
    0066   fclose(fid)
    0067