emnenmf.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. function [ T , RMSE , MERs ] = emnenmf( 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. %%
  9. X0 =X;
  10. Omega_G = (Omega_G == 1); % Logical mask is faster than indexing in matlab.
  11. Omega_F = (Omega_F == 1); % Logical mask is faster than indexing in matlab.
  12. nOmega_G = ~Omega_G; % Logical mask is faster than indexing in matlab.
  13. nOmega_F = ~Omega_F; % Logical mask is faster than indexing in matlab.
  14. num_sensor = config.numSensor;
  15. em_iter_max = round(Tmax / delta_measure) ;
  16. T = nan(1,em_iter_max);
  17. RMSE = nan(1+config.numSubSensor,em_iter_max);
  18. MERs = nan(1+config.numSubSensor,em_iter_max);
  19. X = G*F+W.*(X0-G*F);
  20. GG = G'*G;
  21. GX = G'*X;
  22. GradF = GG*F-GX;
  23. FF = F*F';
  24. XF = X*F';
  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. T(i) = toc;
  32. RMSE(:,i) = vecnorm(F(:,1:num_sensor)- F_theo(:,1:num_sensor),2,2)/sqrt(num_sensor);
  33. niter = 0;
  34. T_E = [];
  35. T_M = [];
  36. while toc<Tmax
  37. t_e = toc;
  38. X = G*F+W.*(X0-G*F);
  39. T_E = cat(1,T_E,toc - t_e);
  40. for j =1:M_loop
  41. t_m = toc;
  42. FF = F*F';
  43. XF = X*F' - Phi_G*FF;
  44. G(Omega_G) = 0; % Convert G to \Delta G
  45. [ G , iterG ] = MaJ_G_EM_NeNMF( FF , XF , G , InnerMinIter , InnerMaxIter , StoppingCritG , nOmega_G); % Update \Delta G
  46. G(Omega_G) = Phi_G(Omega_G); % Convert \Delta G to G
  47. niter = niter + iterG;
  48. if(iterG<=InnerMinIter)
  49. StoppingCritG = 1.e-1*StoppingCritG;
  50. end
  51. GG = G'*G;
  52. GX = G'*X-GG*Phi_F;
  53. F(Omega_F) = 0; % Convert F to \Delta F
  54. [ F , iterF ] = MaJ_F_EM_NeNMF( GG , GX , F , InnerMinIter , InnerMaxIter , StoppingCritF , nOmega_F); % Update \Delta F
  55. F(Omega_F) = Phi_F(Omega_F); % Convert \Delta F to F
  56. niter = niter + iterF;
  57. if(iterF<=InnerMinIter)
  58. StoppingCritF = 1.e-1*StoppingCritF;
  59. end
  60. if toc - i*delta_measure >= delta_measure
  61. i = i+1;
  62. if i > em_iter_max
  63. break
  64. end
  65. [MER,~]=bss_eval_mix(F_theo',F');
  66. MERs(:,i) = MER;
  67. T(i) = toc;
  68. RMSE(:,i) = vecnorm(F(:,1:end-1) - F_theo(:,1:end-1),2,2)/sqrt(num_sensor);
  69. end
  70. T_M = cat(1,T_M,toc - t_m);
  71. end
  72. end
  73. niter
  74. disp(['em E step : ',num2str(mean(T_E))])
  75. disp(['em M step : ',num2str(mean(T_M))])
  76. disp(['RMSE 2ème colonne de G : ',num2str(norm(G(:,2) - X_theo(:,end),2)/sqrt(config.sceneWidth*config.sceneLength))])
  77. end