123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- clear;
- clc;
-
- % read original graph + missing node indexes
- % loop
- % read predict graph + restore graph which is the partal graph
- % read the nodes permutation
- % calc GED vice the orignal graph
- % end
-
- rootDir = 'D:/SocialNets/Steam/Results_Test/BFS_50Att/compareGED/KronResults_BFS/' ;
- datasetDir = strcat(rootDir,'Iter2/'); %' '; % sigal 28.8.12
- resultsDir = strcat(datasetDir,'KronResults2/');
- file1Iter = 2; % networks options [1:1:10] - selection iter
- file2Iter = [0]; %% 1 2 3 4 5 6 7 9]; %%0:1:9; % networks options [1:1:10] - network iter
- missIter = 3:4; %%1:1:5; %%5; % missing info options [1:1:5] - miss perc iter
- parmIter = ['a']; %% 'b' 'c']; %run parameters options ['a' 'b' 'c']
- numNodes = 2048;
- run=0;
-
- for f1 = file1Iter % loop over networks
- for f2 = file2Iter % loop over networks
- prefix = sprintf('Steam_GM2_GR2_%d_%d',numNodes, f2);
- origSuffix = sprintf('.mat_%d_orig_edges.txt', f1);
-
- files = dir(strcat(datasetDir, prefix, '*', origSuffix));
- filePrefix = strrep(files(1).name, strcat('.txt',origSuffix), '');
-
- origFile = sprintf('%s.txt%s',filePrefix, origSuffix);
- for i = missIter % loop over missing info options
- for j = parmIter % loop over run parameters
-
- run = run +1;
-
- missFile = sprintf('%s%s.txt.mat_%d_%d_miss.txt', datasetDir, filePrefix, f1, i);
-
- permFile = sprintf('%s%s_%d_%d%s.perm.orig', resultsDir, filePrefix, f1, i, j);
-
- restoreFile = sprintf('%s_%d_%d%s_restored.txt', filePrefix, f1, i, j);
- predictFile = sprintf('%s_%d_%d%s_predicted.txt', filePrefix, f1, i, j);
-
- graph0 = LoadAsciiGraph2(datasetDir, origFile, numNodes);
- graph1 = LoadAsciiGraph2(resultsDir, restoreFile, numNodes);
- graph2 = LoadAsciiGraph2(resultsDir, predictFile, numNodes);
-
- permNodes = load(permFile);
- missNodes = load(missFile)'; % indexes already from 1
-
- permNodes = permNodes + 1; % fix indexes for matlab (add 1 to all entries)
-
- origNodes = size(permNodes,1);
- numMissingNodes = size(missNodes,2);
- numNgrNodes = numNodes - origNodes - numMissingNodes;
- ngrNodesLastInx = origNodes;
- missNodeLastInx = ngrNodesLastInx + numNgrNodes;
-
- nodes_to_keep = zeros(1, numNodes);
-
- % add original missing nodes and edges to restore graph
- for node = missNodes
- temp = graph0(node,:); % get row from original graph
- ind = find(temp); % get edges indexes
- missNodeLastInx = missNodeLastInx + 1; % next node index (append as last)
- nodeInx = missNodeLastInx;
-
- for other = ind
- [otherInx, permNodes] = GetNodeInxPermutation(other, permNodes);
-
- % add both edges
- graph1(nodeInx,otherInx) = 1;
- graph1(otherInx,nodeInx) = 1;
-
- % kep indexes
- nodes_to_keep(otherInx) = 1;
- nodes_to_keep(nodeInx) = 1;
- end
- end
-
- graph3 = graph2;
- % delete predict edges between ALL predict nodes in the predict graph
- for n1 = origNodes+1:numNodes
- for n2 = n1:numNodes
- graph3(n1,n2) = 0;
- graph3(n2,n1) = 0;
- end
- end
-
- graph4 = graph3;
- % duplicate edges to make graph undirected
- for n1 = origNodes+1:numNodes
- for n2 = 1:origNodes
- if graph4(n1,n2) == 1
- graph4(n2,n1) = 1;
- elseif graph4(n2,n1) == 1
- graph4(n1,n2) = 1;
- end
- end
- end
-
- % save(strcat(resultsDir,'graph1'),'graph1');
- % save(strcat(resultsDir,'graph2'),'graph2');
- % graph1 = sparse(graph1);
- % graph2 = sparse(graph2);
-
- nodes_to_remove = ~nodes_to_keep;
- indices_to_remove = find(nodes_to_remove);
- indices_to_keep = find(nodes_to_keep);
-
- graph1(indices_to_remove,:) = [];
- graph1(:,indices_to_remove) = [];
- graph2(indices_to_remove,:) = [];
- graph2(:,indices_to_remove) = [];
- graph3(indices_to_remove,:) = [];
- graph3(:,indices_to_remove) = [];
- graph4(indices_to_remove,:) = [];
- graph4(:,indices_to_remove) = [];
-
- fprintf('Starting GraphEditDistance (%d %d %d %s) %d ...\n',f2,f1,i,j,rem(now,1));
- % bestDist1 = 3333; %GraphEditDistance(graph1, graph2, numMissingNodes+numNgrNodes);
- % bestDist2 = 3333; %GraphEditDistance(graph1, graph3, numMissingNodes+numNgrNodes);
- bestDist3 = GraphEditDistance(graph1, graph3, numMissingNodes+numNgrNodes);
- fprintf('Completed GraphEditDistance (%d %d %d %s) %d.\n',f2,f1,i,j,rem(now,1));
-
- graphDist(run).file = strcat(filePrefix,'.mat');
- graphDist(run).f1 = f1;
- graphDist(run).f2 = f2;
- graphDist(run).miss = i;
- graphDist(run).missNum = numMissingNodes;
- graphDist(run).parms = j;
- % graphDist(run).bestDist1 = bestDist1;
- % graphDist(run).bestDist2 = bestDist2;
- graphDist(run).bestDist3 = bestDist3;
-
- end
- end
- end
- end
-
- dateNow = clock;
- dateNow = strcat(num2str(dateNow(1)),'_',num2str(dateNow(2)),'_', num2str(dateNow(3)),'_', num2str(dateNow(4)), num2str(dateNow(5)),'_', num2str(dateNow(6)));
-
- % dump graphDist as text
- outFile = sprintf('%sDumpGraphDist_%s.txt',resultsDir, dateNow);
- fileID = fopen(outFile,'w');
- for r = graphDist
- fprintf(fileID,'\t%s',r.file);
- fprintf(fileID,'\t%d',r.f2);
- fprintf(fileID,'\t%d',r.f1);
- fprintf(fileID,'\t%d',r.miss);
- fprintf(fileID,'\t%d',r.missNum);
- fprintf(fileID,'\t%s',r.parms);
- % fprintf(fileID,'\t%3.1f',r.bestDist1);
- % fprintf(fileID,'\t%3.1f',r.bestDist2);
- fprintf(fileID,'\t%3.1f',r.bestDist3);
- fprintf(fileID,'\n');
- end
- fclose(fileID);
-
- % dump all parameters
- outFile = sprintf('%sGraphDist_%s.mat',resultsDir, dateNow);
- save(outFile);
-
- fprintf('Completed RunExperiment.\n');
|