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.

CheckProperties2.m 7.2KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. clear;
  2. clc;
  3. %affinity calculation types
  4. % affinity_calculation_shortest_path = 0;
  5. % affinity_calculation_euclid = 1;
  6. % affinity_calculation_common_friends = 2;
  7. % affinity_calculation_random_clustering = 3;
  8. % affinity_calculation_adamic_adar = 4;
  9. % affinity_calculation_katz_beta_0_5 = 5;
  10. % affinity_calculation_katz_beta_0_05 = 6;
  11. % affinity_calculation_katz_beta_0_005 = 7;
  12. affinities = 3; %%[2,3,4,6]; %3,4]; %,6];
  13. num_missing_nodes_arr = 11; %%[11 21 31 41 50]; %%5:5:30; %10:10:50; %%[11 21 31 41 50]; %10:10:50;
  14. percentKnownPHsVec = 1;
  15. datasetDir = 'D:/SocialNets/Steam/Results_Test/FF75_Steam_GM2_20/' ;
  16. results_dir = strcat(datasetDir,'All_W3/');
  17. filePrefix = 'Steam_*';
  18. netSizes = 2048; %%[2048];
  19. runAlgFlag = 1;
  20. debugFlag = 0;
  21. dumpFlag = 0;
  22. numThreshold = 0;
  23. %%maxAttStat = 0.25; % use this attribute only if it appears less than this percentage
  24. numAttrCols = 21; %40; %50
  25. %attSelected = ones(1,numAttrCols);
  26. %attSelected(1) = 0; %skip country
  27. attWeight = 0.3;
  28. addMissingAtt = 0;
  29. date_now = clock;
  30. date_now = strcat(num2str(date_now(1)),'_',num2str(date_now(2)),'_', num2str(date_now(3)),'_', num2str(date_now(4)), num2str(date_now(5)),'_', num2str(date_now(6)));
  31. LogMsg(sprintf('%s Strating CheckProperties ...',date_now));
  32. outFile = sprintf('%sPropertiesData_%s.txt', results_dir, date_now);
  33. fileID = 0;
  34. for nodes = netSizes
  35. prefix = sprintf('%s%s%d_%s',datasetDir,filePrefix,nodes,'*.mat');
  36. files = dir(prefix);
  37. firstIter = 1;
  38. for iter = 1 %1:2 %100 % loop over same network with different missing nodes
  39. for i = 1:size(files,1) % loop over the list of networks
  40. file = files(i).name;
  41. fprintf('reading network information from file %s%s ...\n', datasetDir, file);
  42. load(strcat(datasetDir, file), 'data');
  43. data = sparse(data);
  44. for maxAttStat = [0.25 0.3 0.4 0.5 0.75 1]
  45. attSelected = ones(1,numAttrCols);
  46. %skip all games
  47. % for g=2:1:11
  48. % attSelected(g) = 0;
  49. % end
  50. %skip all groups
  51. % for g=12:1:50
  52. % attSelected(g) = 0;
  53. % end
  54. attSelectedNum = nnz(attSelected);
  55. attFile = strrep(file, '.txt.mat', '.usr.txt');
  56. [attributes, attUpperRange, attSelected, attStat] = PrepareAttributes2(datasetDir, attFile, nodes, numAttrCols, maxAttStat, attSelected);
  57. if runAlgFlag == 1
  58. date_now = clock;
  59. date_now = strcat(num2str(date_now(1)),'_',num2str(date_now(2)),'_', num2str(date_now(3)),'_', num2str(date_now(4)), num2str(date_now(5)),'_', num2str(date_now(6)));
  60. % make sure dump & results directories exist
  61. if (firstIter == 1 && i == 1)
  62. firstIter = 0;
  63. if isdir(results_dir) == 0
  64. mkdir(results_dir);
  65. end
  66. fileID = fopen(outFile,'w');
  67. fprintf(fileID,'\tfile\ti\titer\tnodes\tedges\tnonedges\tmaxAttStat\tattSelectedNum\tnumAtt');
  68. fprintf(fileID,'\tedgesAttNNZ\tedgesAttOne\tpercAttOne\tedgesAttZero\tpercAttZero\tedgesAvg\tedgesAvgNNZ');
  69. fprintf(fileID,'\tnonedgesAttNNZ\tnonedgesAttOne\tpercAttOne\tnonedgesAttZero\tpercAttZero\tnonedgesAvg\tnonedgesAvgNNZ');
  70. fprintf(fileID,'\n');
  71. end
  72. % pre process attributes (translate to binary attributes)
  73. [attData, totalAttNum] = PreProcessDataAttributes(data, attributes, attUpperRange);
  74. % Calc Attributes Affinity - similarity score
  75. fprintf('calculating attribtes affinity matrix...\n');
  76. [attAffinity] = CalcAttributesAffinity(data, attData, nodes, addMissingAtt, 1, 1);
  77. numAtt = nnz(attSelected); %%size(attributes,2);
  78. edges = nnz(data);
  79. nonedges = nodes*nodes-nodes-edges;
  80. % save iteration data
  81. fprintf(fileID,'\t%s',file);
  82. fprintf(fileID,'\t%d',i);
  83. fprintf(fileID,'\t%d',iter);
  84. fprintf(fileID,'\t%d',nodes);
  85. fprintf(fileID,'\t%d',edges);
  86. fprintf(fileID,'\t%d',nonedges);
  87. fprintf(fileID,'\t%d',maxAttStat);
  88. fprintf(fileID,'\t%d',attSelectedNum);
  89. fprintf(fileID,'\t%d',numAtt);
  90. % edges properties
  91. edgesInd = find(data);
  92. edgesAttInd = find(attAffinity(edgesInd));
  93. edgesAttNNZ = size(edgesAttInd,1);
  94. edgesAttOne = size(find(attAffinity(edgesInd)==1),1);
  95. edgesAttZero = edges-edgesAttNNZ;
  96. edgesAttSum = full(sum(sum(attAffinity(edgesInd))));
  97. edgesAvg = edgesAttSum/edges;
  98. edgesAvgNNZ = edgesAttSum/edgesAttNNZ;
  99. fprintf(fileID,'\t%d',edgesAttNNZ);
  100. fprintf(fileID,'\t%d\t%d',edgesAttOne,edgesAttOne/edges);
  101. fprintf(fileID,'\t%d\t%d',edgesAttZero,edgesAttZero/edges);
  102. fprintf(fileID,'\t%d',edgesAvg);
  103. fprintf(fileID,'\t%d',edgesAvgNNZ);
  104. % nonedges properties
  105. nonedges = nodes*nodes-nodes-edges;
  106. nonedgesInd = find(data==0);
  107. nonedgesAttInd = find(attAffinity(nonedgesInd));
  108. nonedgesAttNNZ = size(nonedgesAttInd,1)-nodes;
  109. nonedgesAttOne = size(find(attAffinity(nonedgesInd)==1),1)-nodes;
  110. nonedgesAttZero = nonedges-nonedgesAttNNZ;
  111. nonedgesAttSum = full(sum(sum(attAffinity(nonedgesInd))))-nodes;
  112. nonedgesAvg = nonedgesAttSum/nonedges;
  113. nonedgesAvgNNZ = nonedgesAttSum/nonedgesAttNNZ;
  114. fprintf(fileID,'\t%d',nonedgesAttNNZ);
  115. fprintf(fileID,'\t%d\t%d',nonedgesAttOne,nonedgesAttOne/nonedges);
  116. fprintf(fileID,'\t%d\t%d',nonedgesAttZero,nonedgesAttZero/nonedges);
  117. fprintf(fileID,'\t%d',nonedgesAvg);
  118. fprintf(fileID,'\t%d',nonedgesAvgNNZ);
  119. fprintf(fileID,'\n');
  120. %LogMsg(sprintf('Results for file %s,iter %d at %s',file,iter,out_file));
  121. %fprintf('Completed RunExperiment cycle - results at %s.\n',out_file);
  122. end
  123. end
  124. % beep;
  125. end
  126. end
  127. end
  128. if fileID ~= 0
  129. fclose(fileID);
  130. end
  131. LogMsg(sprintf('%s Completed RunExperiment.',date_now));