remnenmf.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. function [ T , RMSE , MERs ] = remnenmf( X, X_theo, W, F_theo, Omega_G, Omega_F, Phi_G, Phi_F, G, F, config)
  2. %% loading the config parameters
  3. Tmax = config.Tmax;
  4. delta_measure = config.delta_measure;
  5. InnerMinIter = config.InnerMinIter;
  6. InnerMaxIter = config.InnerMaxIter;
  7. M_loop = config.M_loop;
  8. nu = config.nu;
  9. %%
  10. r = nu;
  11. X0 = X;
  12. Omega_G = (Omega_G == 1); % Logical mask is faster than indexing in matlab.
  13. Omega_F = (Omega_F == 1); % Logical mask is faster than indexing in matlab.
  14. nOmega_G = ~Omega_G; % Logical mask is faster than indexing in matlab.
  15. nOmega_F = ~Omega_F; % Logical mask is faster than indexing in matlab.
  16. num_sensor = config.numSensor;
  17. em_iter_max = round(Tmax / delta_measure) ;
  18. T = nan(1,em_iter_max);
  19. RMSE = nan(1+config.numSubSensor,em_iter_max);
  20. MERs = nan(1+config.numSubSensor,em_iter_max);
  21. nW = (1-W);
  22. % X = G*F+W.*(X0-G*F);
  23. X = X0 + nW.*(G*F);
  24. GG = G' * G;
  25. GX = G' * X ;
  26. GradF = GG * F - GX;
  27. FF = F * F';
  28. XF = X * F' ;
  29. GradG = nOmega_G.*(G * FF - XF);
  30. d = Grad_P([GradG',GradF],[G',F]);
  31. StoppingCritF = 1.e-3*d;
  32. StoppingCritG = 1.e-3*d;
  33. T_E = [];
  34. T_M = [];
  35. tic
  36. i = 1;
  37. niter = 0;
  38. RMSE(:,i) = vecnorm(F(:,1:num_sensor)- F_theo(:,1:num_sensor),2,2)/sqrt(num_sensor);
  39. T(i) = toc;
  40. while toc<Tmax
  41. t_e = toc;
  42. % Estimation step
  43. X = X0 + nW.*(G*F);
  44. % if mod(i-1,5) ~= 0
  45. % [L,R]=RSI_compression(X,r,L,R);
  46. % else
  47. % [L,R]=RSI_compression(X,r);
  48. % end
  49. [L,R]=RSI_compression(X,r);
  50. % Compress left and right
  51. X_L = L * X;
  52. X_R = X * R;
  53. T_E = cat(1,T_E,toc - t_e);
  54. % Maximization step
  55. for j =1:M_loop
  56. t_m = toc;
  57. % F_R = F * R;
  58. % FF = F_R * F_R';
  59. FF = F * F';
  60. XF = X_R * (F * R)' - Phi_G * FF;
  61. % G(Omega_G) = 0; % Convert G to \Delta G
  62. [ GradG , iterG ] = MaJ_G_EM_NeNMF( FF , XF , GradG , InnerMinIter , InnerMaxIter , StoppingCritG , nOmega_G); % Update \Delta G
  63. % G(Omega_G) = Phi_G(Omega_G); % Convert \Delta G to G
  64. G = GradG + Phi_G;
  65. niter = niter + iterG;
  66. if(iterG<=InnerMinIter)
  67. StoppingCritG = 1.e-1*StoppingCritG;
  68. end
  69. % G_L = L * G;
  70. % GG = G_L' * G_L;
  71. GG = G' * G;
  72. GX = (L * G)' * X_L - GG * Phi_F;
  73. F(Omega_F) = 0; % Convert F to \Delta F
  74. % F = F - Phi_F;
  75. [ F , iterF ] = MaJ_F_EM_NeNMF( GG , GX , F , InnerMinIter , InnerMaxIter , StoppingCritF , nOmega_F); % Update \Delta F
  76. F(Omega_F) = Phi_F(Omega_F); % Convert \Delta F to F
  77. % F = F + Phi_F;
  78. niter = niter + iterF;
  79. if(iterF<=InnerMinIter)
  80. StoppingCritF = 1.e-1*StoppingCritF;
  81. end
  82. if toc - i*delta_measure >= delta_measure
  83. i = i+1;
  84. if i > em_iter_max
  85. break
  86. end
  87. [MER,~]=bss_eval_mix(F_theo',F');
  88. MERs(:,i) = MER;
  89. T(i) = toc;
  90. RMSE(:,i) = vecnorm(F(:,1:num_sensor) - F_theo(:,1:num_sensor),2,2)/sqrt(num_sensor);
  91. end
  92. T_M = cat(1,T_M,toc - t_m);
  93. end
  94. end
  95. niter
  96. disp(['rem E step : ',num2str(mean(T_E))])
  97. disp(['rem M step : ',num2str(mean(T_M))])
  98. end
  99. function [ L,R ] = RSI_compression(X,r,varargin)
  100. % Tepper, M., & Sapiro, G. (2016). Compressed nonnegative
  101. % matrix factorization is fast and accurate. IEEE Transactions
  102. % on Signal Processing, 64(9), 2269-2283.
  103. % see: https://arxiv.org/pdf/1505.04650
  104. % The corresponding code is originally created by the authors
  105. % Then, it is modified by F. Yahaya.
  106. % Date: 13/04/2018
  107. %
  108. compressionLevel=2;
  109. [m,n]=size(X);
  110. l = min(min(n,m), max(compressionLevel, r ));
  111. switch nargin
  112. case 2
  113. OmegaL = randn(n,l);
  114. OmegaR = randn(l, m);
  115. q = 4;
  116. case 4
  117. OmegaL = varargin{2};
  118. OmegaR = varargin{1};
  119. q = 1;
  120. end
  121. Y = X * OmegaL;
  122. for i=1:q
  123. [Y,~]=qr(Y,0);
  124. S=X'*Y;
  125. [Z,~]=qr(S,0);
  126. Y=X* Z;
  127. end
  128. [L,~]=qr(Y,0);
  129. L=L';
  130. Y = OmegaR * X;
  131. for i=1:q
  132. [Y,~]=qr(Y',0);
  133. S=X*Y;
  134. [Z,~]=qr(S,0);
  135. Y=Z'*X;
  136. end
  137. Y=Y';
  138. [R,~] = qr(Y,0);
  139. end