remnenmf.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. function [ T , RMSE ] = remnenmf( W , X , G , F , Omega_G, Omega_F, Phi_G, Phi_F , InnerMinIter , InnerMaxIter , Tmax , v, F_theo, delta_measure)
  2. r = 0;
  3. X0 = X;
  4. Omega_G = (Omega_G == 1); % Logical mask is faster than indexing in matlab.
  5. Omega_F = (Omega_F == 1); % Logical mask is faster than indexing in matlab.
  6. % nOmega_G = ~Omega_G; % Logical mask is faster than indexing in matlab.
  7. % nOmega_F = ~Omega_F; % Logical mask is faster than indexing in matlab.
  8. [~, num_sensor] = size(F);
  9. num_sensor = num_sensor-1;
  10. em_iter_max = round(Tmax / delta_measure) ;
  11. T = nan(1,em_iter_max);
  12. RMSE = nan(2,em_iter_max);
  13. X = G*F+W.*(X0-G*F);
  14. [L,R]=RSI_compression(X,r);
  15. % Compress left and right
  16. X_L = L * X;
  17. X_R = X * R;
  18. G_L = L * G;
  19. F_R = F * R;
  20. GG = G_L' * G_L;
  21. GX = G_L' * X_L;
  22. GradF = GG * F - GX;
  23. FF = F_R * F_R';
  24. XF = X_R * F_R';
  25. GradG = G * FF - XF;
  26. d = Grad_P([GradG',GradF],[G',F]);
  27. StoppingCritF = 1.e-3*d;
  28. StoppingCritG = StoppingCritF;
  29. tic
  30. i = 1;
  31. niter = 0;
  32. RMSE(:,i) = vecnorm(F(:,1:end-1)- F_theo(:,1:end-1),2,2)/sqrt(num_sensor);
  33. T(i) = toc;
  34. while toc<Tmax
  35. % Estimation step
  36. X = G*F+W.*(X0-G*F);
  37. [L,R]=RSI_compression(X,r);
  38. % Compress left and right
  39. X_L = L * X;
  40. X_R = X * R;
  41. % Maximization step
  42. for j =1:v
  43. F_R = F * R;
  44. FF = F_R * F_R';
  45. XF = X_R * F_R' - Phi_G * FF;
  46. G(Omega_G) = 0; % Convert G to \Delta G
  47. [ G , iterG , ~ ] = MaJ_G_EM_NeNMF( G , FF , XF , InnerMaxIter , StoppingCritG , Omega_G); % Update \Delta G
  48. G(Omega_G) = Phi_G(Omega_G); % Convert \Delta G to G
  49. if(iterG<=InnerMinIter)
  50. StoppingCritG = 1.e-1*StoppingCritG;
  51. end
  52. G_L = L * G;
  53. GG = G_L' * G_L;
  54. GX = G_L' * X_L - GG * Phi_F;
  55. F(Omega_F) = 0; % Convert F to \Delta F
  56. [ F , iterF ] = MaJ_F_EM_NeNMF( GG , GX , F , InnerMaxIter , StoppingCritF , Omega_F); % Update \Delta F
  57. F(Omega_F) = Phi_F(Omega_F); % Convert \Delta F to F
  58. if(iterF<=InnerMinIter)
  59. StoppingCritF = 1.e-1*StoppingCritF;
  60. end
  61. if toc - i*delta_measure >= delta_measure
  62. i = i+1;
  63. if i > em_iter_max
  64. break
  65. end
  66. T(i) = toc;
  67. RMSE(:,i) = vecnorm(F(:,1:end-1) - F_theo(:,1:end-1),2,2)/sqrt(num_sensor);
  68. end
  69. end
  70. niter = niter + 1;
  71. end
  72. niter
  73. end
  74. function [ L,R ] = RSI_compression(X,r)
  75. % Tepper, M., & Sapiro, G. (2016). Compressed nonnegative
  76. % matrix factorization is fast and accurate. IEEE Transactions
  77. % on Signal Processing, 64(9), 2269-2283.
  78. % see: https://arxiv.org/pdf/1505.04650
  79. % The corresponding code is originally created by the authors
  80. % Then, it is modified by F. Yahaya.
  81. % Date: 13/04/2018
  82. %
  83. compressionLevel=10;
  84. [m,n]=size(X);
  85. l = min(n, max(compressionLevel, r + 10));
  86. OmegaL = randn(n,l);
  87. Y = X * OmegaL;
  88. for i=1:4
  89. [Y,~]=qr(Y,0);
  90. S=X'*Y;
  91. [Z,~]=qr(S,0);
  92. Y=X* Z;
  93. end
  94. [L,~]=qr(Y,0);
  95. L=L';
  96. OmegaR = randn(l, m);
  97. Y = OmegaR * X;
  98. for i=1:4
  99. [Y,~]=qr(Y',0);
  100. S=X*Y;
  101. [Z,~]=qr(S,0);
  102. Y=Z'*X;
  103. end
  104. Y=Y';
  105. [R,~] = qr(Y,0);
  106. end