script_demo.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. % This matlab script provides a demonstration of the informed and
  2. % constrained NMF algorithms proposed in the article:
  3. % [1] C. DORFFER, M. Puigt, G. Delmaire and G. Roussel, "Informed Nonnegative
  4. % Matrix Factorization Methods for Mobile Sensor Network Calibration", in
  5. % IEEE Transactions on Signal and Information Processing over Networks,
  6. % vol. 4, no. 4, pp. 667-682, Dec. 2018.
  7. %%
  8. clear
  9. close all
  10. clc
  11. addpath('functions/')
  12. rng(3)
  13. %% Simulation parameters
  14. N_Ref = 3; % Nb. of reference measurements
  15. N_Cpt = 25; % Nb. of mobile sensors
  16. Mu_beta = .9; % Mean sensors gain
  17. Mu_alpha = 5; % Mean sensors offset
  18. Bound_beta = [.01;1.5]; % Gain boundaries
  19. Bound_alpha = [3.5;6.5]; % Offset boundaries
  20. MV = .9; % Missing Value prop.
  21. RV = 0; % RendezVous prop.
  22. var_n = 0; % Noise variance
  23. %% Scene simulation
  24. [xx,yy] = meshgrid((-1:2/9:1),(-1:2/9:1));
  25. sig = [1;1];
  26. y=@(xx,yy) exp(-[xx;yy]'*diag(sig)*[xx;yy]);
  27. for i = 1:100
  28. g(i) = y(xx(i),yy(i));
  29. end
  30. g = g-min(g);
  31. g = .5*(g/max(g))+1e-5;
  32. G_theo = [ones(100,1),g']; % Theoretical matrix G (see eq.(3) of [1])
  33. figure
  34. subplot(221)
  35. imagesc(reshape(g,10,10))
  36. %% Sensors simulation
  37. F_theo = [max(Bound_beta(1),min(Bound_beta(2),Mu_beta+.5*randn(1,N_Cpt)));...
  38. max(Bound_alpha(1),min(Bound_alpha(2),Mu_alpha+.5*randn(1,N_Cpt)))];
  39. F_theo = [F_theo,[0;1]]; % Theoretical matrix F (see eq.(3) of [1])
  40. %% Data simulation
  41. X_theo = G_theo*F_theo; % Theoretical matrix X (see eq.(2) of [1])
  42. W = zeros(100,N_Cpt+1);
  43. idx_Ref = randperm(100);
  44. idx_Ref = idx_Ref(1:N_Ref); % Reference measurement locations
  45. W(idx_Ref,end) = 1;
  46. N_RV = round(N_Cpt*RV); % Nb. of sensors having a RendezVous
  47. idx_CptRV = randperm(N_Cpt);
  48. idx_CptRV = idx_CptRV(1:N_RV); % Selection of sensors having a RendezVous
  49. idx_RefRV = randi(N_Ref,1,N_Cpt);
  50. idx_RefRV = idx_Ref(idx_RefRV(1:N_RV)); % Selection of the references for each RendezVous
  51. for i = 1 : N_RV
  52. W(idx_RefRV(i),idx_CptRV(i)) = 1;
  53. end
  54. N_data = round((1-MV)*(N_Cpt)*(100-N_Ref)); % Nb. of measurements in data matrix X
  55. xCpt = 1 : 100;
  56. xCpt(idx_Ref) = []; % Reference free locations
  57. [xx,yy] = meshgrid(xCpt,1:N_Cpt); % Possibly sensed locations
  58. idx_data = randperm((100-N_Ref)*N_Cpt);
  59. for i = 1 : N_data
  60. W(xx(idx_data(i)),yy(idx_data(i))) = 1; % Sensor measurement placement
  61. end
  62. N = var_n*randn(100,N_Cpt+1); % Noise simulation
  63. N(:,end) = 0;
  64. N = max(N,-X_theo);
  65. SNR = snr(X_theo(W~=0),N(W~=0));
  66. X = W.*(X_theo+N); % Data matrix X
  67. subplot(222)
  68. imagesc(X)
  69. %% Calibration parameters
  70. % % Common parameters
  71. N_iter = 1.e5; % Maximum nb. of iterations
  72. Omega_G = [ones(100,1),W(:,end)]; % Mask on known values in G (see eq.(14) of [1])
  73. Omega_F = [zeros(2,N_Cpt),[1;1]]; % Mask on known values in F (see eq.(15) of [1])
  74. Phi_G = [ones(100,1),X(:,end)]; % Known values in G (see eq.(14) of [1])
  75. Phi_F = [zeros(2,N_Cpt),[0;1]]; % Known values in F (see eq.(15) of [1])
  76. Ginit = abs(randn(100,2)); % Initial matrix G
  77. Ginit = (1-Omega_G).*Ginit+Phi_G;
  78. Finit = [max(Bound_beta(1),min(Bound_beta(2),Mu_beta+.5*randn(1,N_Cpt)));...
  79. max(Bound_alpha(1),min(Bound_alpha(2),Mu_alpha+.5*randn(1,N_Cpt)))];
  80. Finit = [Finit,[0;1]]; % Initial matrix F
  81. Finit = (1-Omega_F).*Finit+Phi_F;
  82. % % Parameters for the "average constrained" approach (called ACIN-Cal in [1])
  83. Mean_F = mean(F_theo(:,1:N_Cpt),2);
  84. mu = 10; % Regularization weight
  85. % % Parameters for the Sparsity based regularization (called SpIN-Cal in [1])
  86. % Dictionary construction
  87. D = real(ifft(diag(ones(100,1))));
  88. D = [D(:,1:15),g',D(:,1:15),g'];
  89. D(51:end,1:16) = 0;
  90. D(1:50,17:end) = 0;
  91. D = D*diag(1./sqrt(sum(D.^2))); % Atoms normalisation
  92. k = 2; % Nb. of atoms to be choosen by the OMP
  93. lambda = 10; % Regularization weight
  94. %% Calibration
  95. % % IN-Cal
  96. [ G_IN_Cal , F_IN_Cal , RMSE_IN_Cal ] = IN_Cal( W , X , Ginit , Finit , Omega_G , Omega_F , Phi_G , Phi_F , F_theo , N_iter );
  97. % % ACIN-Cal
  98. [ G_ACIN_Cal , F_ACIN_Cal , RMSE_ACIN_Cal ] = ACIN_Cal( W , X , Ginit , Finit , Omega_G , Omega_F , Phi_G , Phi_F , Mean_F , mu , F_theo , N_iter );
  99. % % SpIN-Cal
  100. [ G_SpIN_Cal , F_SpIN_Cal , RMSE_SpIN_Cal ] = SpIN_Cal( W , X , Ginit , Finit , Omega_G , Omega_F , Phi_G , Phi_F , D , k , lambda , F_theo , N_iter );
  101. % % SpAIN-Cal
  102. [ G_SpAIN_Cal , F_SpAIN_Cal , RMSE_SpAIN_Cal ] = SpAIN_Cal( W , X , Ginit , Finit , Omega_G , Omega_F , Phi_G , Phi_F , D , k , lambda , Mean_F , mu , F_theo , N_iter );
  103. subplot(223)
  104. semilogy(RMSE_IN_Cal)
  105. axis([0 N_iter 1.e-16 1])
  106. hold all
  107. semilogy(RMSE_ACIN_Cal)
  108. semilogy(RMSE_SpIN_Cal)
  109. semilogy(RMSE_SpAIN_Cal)