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.

CalcPHsAffinityByImages.m 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. function [affinity] = CalcPHsAffinityByImages(data, imagesData, lastKnownNode, missingNodesMap, missProb, simType, simProbDiff)
  2. % sigal 23.1.14
  3. profileFactor = 1000;
  4. profilePrefix = 100;
  5. firstPHsRow = 2;
  6. % simProb = 0.2; %%0.2;
  7. % misProb = 0; %0.2; %%no images
  8. n = size(data,1);
  9. firstPH = lastKnownNode+1;
  10. if firstPH > n
  11. LogMsg(sprintf('*** ERROR: CalcPHsAffinityByImages firstPH %d >size %d.',firstPH, n));
  12. return
  13. end
  14. if missProb < 0 || missProb > 0.8
  15. LogMsg(sprintf('*** ERROR: CalcPHsAffinityByImages invalid parameter (missProbb=%.2f).',missProb));
  16. return
  17. end
  18. if simType ~= 0 && (simProbDiff > 0.5 || simProbDiff < 0)
  19. LogMsg(sprintf('*** ERROR: CalcPHsAffinityByImages invalid parameter (simType=%d, simProbDiff=%.2f).',simType, simProbDiff));
  20. return
  21. end
  22. numPHs = size(data,1) - firstPH +1;
  23. phsImages = zeros(numPHs,1);
  24. for j=1:size(missingNodesMap,2)
  25. for i=firstPHsRow+1:size(missingNodesMap,1)
  26. ph = missingNodesMap(i,j);
  27. if ph ~= 0
  28. currentPH = ph - lastKnownNode;
  29. %Sigal - pid = uid*100+p_index (starting from thrid row)
  30. %avigail - uid.Value*100000 + unameId*1000 + index
  31. currentImage = (profilePrefix+missingNodesMap(2,j))*profileFactor+(i-firstPHsRow);
  32. phsImages(currentPH) = currentImage;
  33. end
  34. end
  35. end
  36. maxExpImages = max(phsImages,1);
  37. maxImagesData = size(imagesData,1);
  38. if simType == 0 && maxImagesData < maxExpImages
  39. LogMsg(sprintf('*** ERROR: CalcPHsAffinityByImages invalid parameter (simType=%d, maxExpImages=%d>maxImagesData=%d).',simType, maxExpImages, maxImagesData));
  40. return
  41. end
  42. affinity = zeros(numPHs,numPHs);
  43. for i=1:numPHs
  44. for j=1:i
  45. if i==j
  46. affinity(i,j) = 1;
  47. else
  48. % get pictures indexes
  49. pic1 = phsImages(i);
  50. pic2 = phsImages(j);
  51. if pic1>pic2%% swap, make sure pic2>pic1
  52. temp = pic2;
  53. pic2 = pic1;
  54. pic1 = temp;
  55. end
  56. % get affinity
  57. if simType == 0 % use real data
  58. if size(imagesData,1) >= pic1 && rand(1) >= missProb
  59. affinity(i,j) = imagesData(pic1, pic2);
  60. affinity(j,i) = affinity(i,j);
  61. end
  62. else % use random data
  63. if simType == 1 % 1=rand(uniform distribution) between (0,1)
  64. randVal = rand(1);
  65. else % 2=randn(normal distribution): mean=0.5, sigma=0.25, 95% between (0,1)
  66. randVal = 0.5+randn(1)*0.25;
  67. end
  68. if (pic2-pic1)<profileFactor % i.e. same profile
  69. val = randVal*(1-simProbDiff)+simProbDiff;
  70. else
  71. val = randVal*(1-simProbDiff);
  72. end
  73. if rand(1) >= missProb
  74. affinity(i,j) = val;
  75. affinity(j,i) = affinity(i,j);
  76. end
  77. end
  78. end
  79. end
  80. end
  81. nnz_n = nnz(affinity);
  82. nnz_p = 100*nnz_n/(numPHs*numPHs);
  83. LogMsg(sprintf('PHsImgAffinity - nnz=%d, %7.5f%%',nnz_n,nnz_p));
  84. end %function