SpAIN_Cal.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. function [ G , F , R ] = SpAIN_Cal( W , X , G , F , Omega_G , Omega_F , Phi_G , Phi_F , D , k , lambda , Mean_F , mu , F_theo , N_iter )
  2. % Author: Clément DORFFER
  3. % Date: 26/11/2018
  4. % @: clement.dorffer@ensta-bretagne.fr
  5. % Goal: perform mobile sensor calibration using the Sparsity- and Average-Constrained Informed NMF calibraton technique.
  6. % If you use this code for research or educational purpose, please cite:
  7. %
  8. % C. Dorffer, M. Puigt, G. Delmaire, G. Roussel, Informed Nonnegative Matrix Factorization Methods for
  9. % Mobile Sensor Network Calibration, IEEE Transactions on Signal and Information Processing over Networks,
  10. % Volume 4, Issue 4, pp. 667-682, December 2018.
  11. %
  12. W2 = W.^2;
  13. tilde_W2 = [W2,lambda*ones(size(W,1),1)];
  14. Omega_Bar_G = ones(size(G))-Omega_G;
  15. Omega_Bar_F = ones(size(F))-Omega_F;
  16. Delta_G = G.*Omega_Bar_G;
  17. Delta_F = F.*Omega_Bar_F;
  18. m = size(F,2)-1;
  19. R = zeros(N_iter+1,1);
  20. R(1) = norm(F(2,1:end-1)-F_theo(2,1:end-1),2)/sqrt(size(F_theo,2)-1);
  21. for i = 1 : N_iter
  22. x = OMP(G(:,2),D,k);
  23. tilde_X = [X,D*x];
  24. tilde_F = [F,[0;1]];
  25. % updating G
  26. Delta_G = Updt_Delta_G( tilde_W2 , tilde_X , Delta_G , Phi_G , tilde_F , Omega_Bar_G );
  27. G = Phi_G + Delta_G;
  28. % updating F
  29. Delta_F = Updt_Delta_F( W2 , X , G , Delta_F , Phi_F , Omega_Bar_F , Mean_F , mu , m );
  30. F = Phi_F + Delta_F;
  31. R(i+1) = norm(F(2,1:end-1)-F_theo(2,1:end-1),2)/sqrt(size(F_theo,2)-1);
  32. end
  33. end
  34. function [ Delta_F ] = Updt_Delta_F( W , X , G , Delta_F , Phi_F , Omega_B_F , Mean_F , mu , m )
  35. %%%%%%%%%%%%%%%%%%%%%%%%%%%
  36. % Update rule for Delta_F %
  37. %%%%%%%%%%%%%%%%%%%%%%%%%%%
  38. Delta_F = Delta_F.*(Omega_B_F.*(G'*(W.*secu_plus(X-G*Phi_F)))+mu/m*diag(Mean_F)*Omega_B_F)./(Omega_B_F.*(G'*(W.*(G*Delta_F)))+mu/m^2*diag(Delta_F*ones(m+1,1))*Omega_B_F);
  39. Delta_F(isnan(Delta_F))=0;
  40. end
  41. function [ Delta_G ] = Updt_Delta_G( W , X , Delta_G , Phi_G , F , Omega_B_G )
  42. %%%%%%%%%%%%%%%%%%%%%%%%%%%
  43. % Update rule for Delta_G %
  44. %%%%%%%%%%%%%%%%%%%%%%%%%%%
  45. Delta_G = Delta_G.*(Omega_B_G).*((W.*secu_plus(X-Phi_G*F))*F')./((W.*(Delta_G*F)*F')); % mise à jour
  46. Delta_G(isnan(Delta_G))=0;
  47. end
  48. function [toto] = secu_plus(tutu,s)
  49. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  50. % Goal: Security in the NMF procedure which project the negative data to
  51. % epsilon (small user-defined threshold)
  52. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  53. if(nargin<2)
  54. s=1.e-12;
  55. end
  56. toto=max(tutu,s);
  57. toto(isnan(tutu)) = 0;
  58. end