remnenmf_not_full.m 4.1 KB

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