You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RunGraphEditDist.m 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. clear;
  2. clc;
  3. % read original graph + missing node indexes
  4. % loop
  5. % read predict graph + restore graph which is the partal graph
  6. % read the nodes permutation
  7. % calc GED vice the orignal graph
  8. % end
  9. %graphDist = [];
  10. rootDir = 'C:\Users\Iraj\Desktop\DML\' ;
  11. datasetDir = strcat(rootDir,'produced_graphs/'); %' '; % sigal 28.8.12
  12. resultsDir = strcat(rootDir,'results_ged/');
  13. file1Iter = []; % networks options [1:1:10] - selection iter
  14. file2Iter = [0]; % networks options [1:1:10] - network iter
  15. missIter = [5]; % missing info options [1:1:5] - miss perc iter
  16. parmIter = ['a' 'b' 'c']; %run parameters options ['a' 'b' 'c']
  17. numNodes = 450;
  18. run=0;
  19. for f1 = file1Iter % loop over networks
  20. for f2 = file2Iter % loop over networks
  21. filePrefix = sprintf('testgraph_%d_%d',numNodes, f2);
  22. origFile = sprintf('%s.mat_%d_orig_edges.txt',filePrefix, f1);
  23. for i = missIter % loop over missing info options
  24. for j = parmIter % loop over run parameters
  25. run = run + 1;
  26. missFile = sprintf('%s%s.mat_%d_%d_miss.txt', datasetDir, filePrefix, f1, i);
  27. permFile = sprintf('%s%s_%d_%d%s.perm.orig', resultsDir, filePrefix, f1, i, j);
  28. restoreFile = sprintf('%s_%d_%d%s_restored.txt', filePrefix, f1, i, j);
  29. predictFile = sprintf('%s_%d_%d%s_predicted.txt', filePrefix, f1, i, j);
  30. graph0 = LoadAsciiGraph(datasetDir, origFile, numNodes);
  31. graph1 = LoadAsciiGraph(resultsDir, restoreFile, numNodes);
  32. graph2 = LoadAsciiGraph(resultsDir, predictFile, numNodes);
  33. permNodes = load(permFile);
  34. missNodes = load(missFile)'; % indexes already from 1
  35. permNodes = permNodes + 1; % fix indexes for matlab (add 1 to all entries)
  36. origNodes = size(permNodes,1);
  37. numMissingNodes = size(missNodes,2);
  38. numNgrNodes = numNodes - origNodes - numMissingNodes;
  39. ngrNodesLastInx = origNodes;
  40. missNodeLastInx = ngrNodesLastInx + numNgrNodes;
  41. nodes_to_keep = zeros(1, numNodes);
  42. % add original missing nodes and edges to restore graph
  43. for node = missNodes
  44. temp = graph0(node,:); % get row from original graph
  45. ind = find(temp); % get edges indexes
  46. missNodeLastInx = missNodeLastInx + 1; % next node index (append as last)
  47. nodeInx = missNodeLastInx;
  48. for other = ind
  49. [otherInx, permNodes] = GetNodeInxPermutation(other, permNodes);
  50. % add both edges
  51. graph1(nodeInx,otherInx) = 1;
  52. graph1(otherInx,nodeInx) = 1;
  53. % kep indexes
  54. nodes_to_keep(otherInx) = 1;
  55. nodes_to_keep(nodeInx) = 1;
  56. end
  57. end
  58. graph3 = graph2;
  59. % delete predict edges between ALL predict nodes in the predict graph
  60. for n1 = origNodes+1:numNodes
  61. for n2 = n1:numNodes
  62. graph3(n1,n2) = 0;
  63. graph3(n2,n1) = 0;
  64. end
  65. end
  66. graph4 = graph3;
  67. % duplicate edges to make graph undirected
  68. for n1 = origNodes+1:numNodes
  69. for n2 = 1:origNodes
  70. if graph4(n1,n2) == 1
  71. graph4(n2,n1) = 1;
  72. elseif graph4(n2,n1) == 1
  73. graph4(n1,n2) = 1;
  74. end
  75. end
  76. end
  77. % save(strcat(resultsDir,'graph1'),'graph1');
  78. % save(strcat(resultsDir,'graph2'),'graph2');
  79. % graph1 = sparse(graph1);
  80. % graph2 = sparse(graph2);
  81. nodes_to_remove = ~nodes_to_keep;
  82. indices_to_remove = find(nodes_to_remove);
  83. indices_to_keep = find(nodes_to_keep);
  84. graph1(indices_to_remove,:) = [];
  85. graph1(:,indices_to_remove) = [];
  86. graph2(indices_to_remove,:) = [];
  87. graph2(:,indices_to_remove) = [];
  88. graph3(indices_to_remove,:) = [];
  89. graph3(:,indices_to_remove) = [];
  90. graph4(indices_to_remove,:) = [];
  91. graph4(:,indices_to_remove) = [];
  92. fprintf('Starting GraphEditDistance (%d %d %d %s) %d ...\n',f2,f1,i,j,rem(now,1));
  93. bestDist1 = 3333; %GraphEditDistance(graph1, graph2, numMissingNodes+numNgrNodes);
  94. bestDist2 = 3333; %GraphEditDistance(graph1, graph3, numMissingNodes+numNgrNodes);
  95. bestDist3 = GraphEditDistance(graph1, graph4, numMissingNodes+numNgrNodes);
  96. fprintf('Completed GraphEditDistance (%d %d %d %s) %d.\n',f2,f1,i,j,rem(now,1));
  97. graphDist(run).file = strcat(filePrefix,'.mat');
  98. graphDist(run).f1 = f1;
  99. graphDist(run).f2 = f2;
  100. graphDist(run).miss = i;
  101. graphDist(run).missNum = numMissingNodes;
  102. graphDist(run).parms = j;
  103. graphDist(run).bestDist1 = bestDist1;
  104. graphDist(run).bestDist2 = bestDist2;
  105. graphDist(run).bestDist3 = bestDist3;
  106. end
  107. end
  108. end
  109. end
  110. dateNow = clock;
  111. dateNow = strcat(num2str(dateNow(1)),'_',num2str(dateNow(2)),'_', num2str(dateNow(3)),'_', num2str(dateNow(4)), num2str(dateNow(5)),'_', num2str(dateNow(6)));
  112. % dump graphDist as text
  113. outFile = sprintf('%sDumpGraphDist_1.txt',resultsDir);
  114. fileID = fopen(outFile,'w');
  115. fprintf('%d', fileID);
  116. for r = graphDist
  117. fprintf(fileID,'\t%s',r.file);
  118. fprintf(fileID,'\t%d',r.f2);
  119. fprintf(fileID,'\t%d',r.f1);
  120. fprintf(fileID,'\t%d',r.miss);
  121. fprintf(fileID,'\t%d',r.missNum);
  122. fprintf(fileID,'\t%s',r.parms);
  123. fprintf(fileID,'\t%3.1f',r.bestDist1);
  124. fprintf(fileID,'\t%3.1f',r.bestDist2);
  125. fprintf(fileID,'\t%3.1f',r.bestDist3);
  126. fprintf(fileID,'\n');
  127. end
  128. fclose(fileID);
  129. % dump all parameters
  130. outFile = sprintf('%sGraphDist_%s.mat',resultsDir, dateNow);
  131. save(outFile);
  132. fprintf('Completed RunExperiment.\n');