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.

RunGraphEditDist2.m 6.9KB

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