IN_Cal.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. function [ T , RMSE ] = IN_Cal( W , X , G , F , Omega_G , Omega_F , Phi_G , Phi_F , F_theo , Tmax, delta_measure )
  2. [~, num_sensor] = size(F);
  3. num_sensor = num_sensor-1;
  4. W2 = W.^2;
  5. Omega_Bar_G = ones(size(G))-Omega_G;
  6. Omega_Bar_F = ones(size(F))-Omega_F;
  7. Delta_G = G.*Omega_Bar_G;
  8. Delta_F = F.*Omega_Bar_F;
  9. iter_max = round(Tmax / delta_measure) ;
  10. T = nan(1,iter_max);
  11. RMSE = nan(2,iter_max);
  12. tic
  13. i = 1;
  14. T(i) = toc;
  15. RMSE(:,i) = vecnorm(F(:,1:end-1)-F_theo(:,1:end-1),2,2)/sqrt(num_sensor);
  16. while toc<Tmax
  17. % updating G
  18. Delta_G = Updt_Delta_G( W2 , X , Delta_G , Phi_G , F , Omega_Bar_G );
  19. G = Phi_G + Delta_G;
  20. % updating F
  21. Delta_F = Updt_Delta_F( W2 , X , G , Delta_F , Phi_F , Omega_Bar_F );
  22. F = Phi_F + Delta_F;
  23. if toc - i*delta_measure >= delta_measure
  24. i = i+1;
  25. if i > iter_max
  26. break
  27. end
  28. T(i) = toc;
  29. RMSE(:,i) = vecnorm(F(:,1:end-1) - F_theo(:,1:end-1),2,2)/sqrt(num_sensor);
  30. end
  31. end
  32. end
  33. function [ Delta_F ] = Updt_Delta_F( W , X , G , Delta_F , Phi_F , Omega_B_F )
  34. %%%%%%%%%%%%%%%%%%%%%%%%%%%
  35. % Update rule for Delta_F %
  36. %%%%%%%%%%%%%%%%%%%%%%%%%%%
  37. Delta_F = Delta_F.*(Omega_B_F).*((G'*(W.*secu_plus(X-G*Phi_F)))./(G'*(W.*(G*Delta_F))));
  38. Delta_F(isnan(Delta_F))=0;
  39. end
  40. function [ Delta_G ] = Updt_Delta_G( W , X , Delta_G , Phi_G , F , Omega_B_G )
  41. %%%%%%%%%%%%%%%%%%%%%%%%%%%
  42. % Update rule for Delta_G %
  43. %%%%%%%%%%%%%%%%%%%%%%%%%%%
  44. Delta_G = Delta_G.*(Omega_B_G).*((W.*secu_plus(X-Phi_G*F))*F')./((W.*(Delta_G*F)*F')); % mise à jour
  45. Delta_G(isnan(Delta_G))=0;
  46. end
  47. function [toto] = secu_plus(tutu,s)
  48. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  49. % Goal: Security in the NMF procedure which project the negative data to
  50. % epsilon (small user-defined threshold
  51. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  52. if(nargin<2)
  53. s=1.e-12;
  54. end
  55. toto=max(tutu,s);
  56. toto(isnan(tutu)) = 0;
  57. end