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.

CheckProperties3.m 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/Exp_Train/' ;
  16. results_dir = strcat(datasetDir,'Stat/');
  17. filePrefix = 'Steam_*';
  18. netSizes = [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 = 60; %%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('%sPropertiesStat_%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 = 1 %%[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\tAttId\tAttPerc');
  68. fprintf(fileID,'\tedgesAttOne\tpercAttOne\tedgesAttZero\tpercAttZero\tedgesAttTwo\tpercAttTwo');
  69. fprintf(fileID,'\tnonedgesAttOne\tpercAttOne\tnonedgesAttZero\tpercAttZero\tnonedgesAttTwo\tpercAttTwo');
  70. fprintf(fileID,'\n');
  71. end
  72. numAtt = nnz(attSelected); %%size(attributes,2);
  73. edges = nnz(data);
  74. nonedges = nodes*nodes-nodes-edges;
  75. for attId = 1:numAttrCols
  76. % Calc Attributes Affinity - similarity score
  77. fprintf('calculating attribtes similarity matrix for attId=%d ...\n',attId);
  78. [attSimilarity] = CalcOneAttributeSimilarity(data, attributes, attId, 1);
  79. % save iteration data
  80. fprintf(fileID,'\t%s',file);
  81. fprintf(fileID,'\t%d',i);
  82. fprintf(fileID,'\t%d',iter);
  83. fprintf(fileID,'\t%d',nodes);
  84. fprintf(fileID,'\t%d',edges);
  85. fprintf(fileID,'\t%d',nonedges);
  86. fprintf(fileID,'\t%d',maxAttStat);
  87. fprintf(fileID,'\t%d',attSelectedNum);
  88. fprintf(fileID,'\t%d',numAtt);
  89. fprintf(fileID,'\t%d',attId);
  90. fprintf(fileID,'\t%d',attStat(attId));
  91. %Note - Sigal, replace 0 and 2 so we can have sparse matrix
  92. % edges properties
  93. edgesInd = find(data);
  94. edgesAttOne = size(find(attSimilarity(edgesInd)==1),1);
  95. edgesAttTwo = size(find(attSimilarity(edgesInd)==0),1);
  96. edgesAttZero = size(find(attSimilarity(edgesInd)==2),1);
  97. fprintf(fileID,'\t%d\t%d',edgesAttOne,edgesAttOne/edges);
  98. fprintf(fileID,'\t%d\t%d',edgesAttZero,edgesAttZero/edges);
  99. fprintf(fileID,'\t%d\t%d',edgesAttTwo,edgesAttTwo/edges);
  100. % nonedges properties
  101. nonedges = nodes*nodes-nodes-edges;
  102. nonedgesInd = find(data==0);
  103. nonedgesAttOne = size(find(attSimilarity(nonedgesInd)==1),1)-nodes;
  104. nonedgesAttTwo = size(find(attSimilarity(nonedgesInd)==0),1);
  105. nonedgesAttZero = size(find(attSimilarity(nonedgesInd)==2),1);
  106. fprintf(fileID,'\t%d\t%d',nonedgesAttOne,nonedgesAttOne/nonedges);
  107. fprintf(fileID,'\t%d\t%d',nonedgesAttZero,nonedgesAttZero/nonedges);
  108. fprintf(fileID,'\t%d\t%d',nonedgesAttTwo,nonedgesAttTwo/nonedges);
  109. fprintf(fileID,'\n');
  110. %LogMsg(sprintf('Results for file %s,iter %d at %s',file,iter,out_file));
  111. %fprintf('Completed RunExperiment cycle - results at %s.\n',out_file);
  112. end
  113. end
  114. end
  115. % beep;
  116. end
  117. end
  118. end
  119. if fileID ~= 0
  120. fclose(fileID);
  121. end
  122. LogMsg(sprintf('%s Completed RunExperiment.',date_now));