remnenmf.m 3.2 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( FF , XF , G , InnerMinIter , InnerMaxIter , StoppingCritG , nOmega_G); % Update \Delta G
  48. G(Omega_G) = Phi_G(Omega_G); % Convert \Delta G to G
  49. niter = niter + iterG;
  50. if(iterG<=InnerMinIter)
  51. StoppingCritG = 1.e-1*StoppingCritG;
  52. end
  53. G_L = L * G;
  54. GG = G_L' * G_L;
  55. GX = G_L' * X_L - GG * Phi_F;
  56. F(Omega_F) = 0; % Convert F to \Delta F
  57. [ F , iterF ] = MaJ_F_EM_NeNMF( GG , GX , F , InnerMinIter , InnerMaxIter , StoppingCritF , nOmega_F); % Update \Delta F
  58. F(Omega_F) = Phi_F(Omega_F); % Convert \Delta F to F
  59. niter = niter + iterF;
  60. if(iterF<=InnerMinIter)
  61. StoppingCritF = 1.e-1*StoppingCritF;
  62. end
  63. if toc - i*delta_measure >= delta_measure
  64. i = i+1;
  65. if i > em_iter_max
  66. break
  67. end
  68. T(i) = toc;
  69. RMSE(:,i) = vecnorm(F(:,1:end-1) - F_theo(:,1:end-1),2,2)/sqrt(num_sensor);
  70. end
  71. end
  72. end
  73. niter
  74. end
  75. function [ L,R ] = RSI_compression(X,r)
  76. % Tepper, M., & Sapiro, G. (2016). Compressed nonnegative
  77. % matrix factorization is fast and accurate. IEEE Transactions
  78. % on Signal Processing, 64(9), 2269-2283.
  79. % see: https://arxiv.org/pdf/1505.04650
  80. % The corresponding code is originally created by the authors
  81. % Then, it is modified by F. Yahaya.
  82. % Date: 13/04/2018
  83. %
  84. compressionLevel=20;
  85. [m,n]=size(X);
  86. l = min(n, max(compressionLevel, r + 10));
  87. OmegaL = randn(n,l);
  88. Y = X * OmegaL;
  89. for i=1:4
  90. [Y,~]=qr(Y,0);
  91. S=X'*Y;
  92. [Z,~]=qr(S,0);
  93. Y=X* Z;
  94. end
  95. [L,~]=qr(Y,0);
  96. L=L';
  97. OmegaR = randn(l, m);
  98. Y = OmegaR * X;
  99. for i=1:4
  100. [Y,~]=qr(Y',0);
  101. S=X*Y;
  102. [Z,~]=qr(S,0);
  103. Y=Z'*X;
  104. end
  105. Y=Y';
  106. [R,~] = qr(Y,0);
  107. end