data_gen.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. function [X, X_theo, W, F_theo, Omega_G, Omega_F, Phi_G, Phi_F, Ginit, Finit] = data_gen(config, run)
  2. rng(run+1306) % Random seed
  3. s_width = config.sceneWidth;
  4. s_length = config.sceneLength;
  5. N_Ref = config.numRef;
  6. N_Cpt = config.numSensor;
  7. N_sousCpt = config.numSubSensor;
  8. Bound_phen = config.Bound_phen;
  9. Mu_beta = config.Mu_beta;
  10. Mu_alpha = config.Mu_alpha;
  11. Bound_beta = config.Bound_beta;
  12. Bound_alpha = config.Bound_alpha;
  13. gamma = config.gamma;
  14. MV = config.mvR;
  15. RV = config.rdvR;
  16. var_n = config.var_n;
  17. %% Scene simulation
  18. n_pic = 15;
  19. s_n = s_width*s_length; % Total number of areas in the scene
  20. [xx,yy] = meshgrid((-1:2/(s_width-1):1),(-1:2/(s_length-1):1));
  21. xxyy = cat(2,xx(:),yy(:));
  22. G_theo = ones(s_n,1);
  23. for sensor = 1:N_sousCpt
  24. g = zeros(s_n,1);
  25. for pic = 1:n_pic
  26. mu = 2*(rand(1,2)-0.5);
  27. sig = diag([ Bound_phen((sensor-1)*2+1) + (Bound_phen((sensor-1)*2+2) - Bound_phen((sensor-1)*2+1))*abs(randn()+0.5) , ...
  28. Bound_phen((sensor-1)*2+1) + (Bound_phen((sensor-1)*2+2) - Bound_phen((sensor-1)*2+1))*abs(randn()+0.5) ]);
  29. g = g + mvnpdf(xxyy,mu,sig);
  30. end
  31. g = (Bound_phen((sensor-1)*2+2) - Bound_phen((sensor-1)*2+1))/(max(g)-min(g))*(g-min(g)) + Bound_phen((sensor-1)*2+1);
  32. % .5*(g/max(g))+1e-5
  33. G_theo = cat(2, G_theo, g);
  34. end
  35. %% Sensors simulation
  36. F_theo = zeros(N_sousCpt+1, N_sousCpt*(N_Cpt+1));
  37. for sensor = 1:N_sousCpt
  38. F_theo(1,(sensor-1)*(N_Cpt+1)+1:sensor*(N_Cpt+1)) = ...
  39. cat(2, max(Bound_beta((sensor-1)*2+1), min(Bound_beta((sensor-1)*2+2), ...
  40. Mu_beta(sensor)+(Bound_beta((sensor-1)*2+2)-Bound_beta((sensor-1)*2+1))*0.55*randn(1,N_Cpt))), 0);
  41. end
  42. for sen = 1:N_sousCpt
  43. f_theo = cat(2, max(Bound_alpha((sen-1)*2+1),...
  44. min( Bound_alpha((sen-1)*2+2), ...
  45. Mu_alpha(sen)+(Bound_alpha((sen-1)*2+2)-Bound_alpha((sen-1)*2+1))*0.25*randn(1,N_Cpt))), 1);
  46. F_theo(sen+1, (sen-1)*(N_Cpt+1)+1:sen*(N_Cpt+1)) = f_theo;
  47. C = (1-gamma)/gamma*(F_theo(1,(sen-1)*(N_Cpt+1)+1:sen*(N_Cpt+1)-1)+Bound_phen((sen-1)*2+1)*f_theo(1:end-1));
  48. list_nosen = 1:N_sousCpt;
  49. list_nosen(sen) = [];
  50. maxPhen_nosen = norm(Bound_phen(2*list_nosen));
  51. for sor = list_nosen
  52. f_theo_nosen = rand(1,N_Cpt).*C/(sqrt(N_sousCpt)*maxPhen_nosen);
  53. other_f_theo = cat(2, f_theo_nosen, 0);
  54. F_theo(sor+1, (sen-1)*(N_Cpt+1)+1:sen*(N_Cpt+1)) = other_f_theo;
  55. end
  56. end
  57. % F_theo = [];
  58. %
  59. % for sensor = 1:N_sousCpt
  60. % F_theo = cat(2, F_theo, cat(2, max(Bound_beta(1), min(Bound_beta(2), Mu_beta+.5*randn(1,N_Cpt))), 0));
  61. % end
  62. %
  63. %
  64. % for sen = 1:N_sousCpt
  65. % f_theo = [];
  66. % for sor = 1:N_sousCpt
  67. % if sen==sor
  68. % f_theo = cat(2, f_theo, cat(2, max(Bound_alpha(1), min(Bound_alpha(2), Mu_alpha+.5*randn(1,N_Cpt))), sen==sor));
  69. % else
  70. % f_theo = cat(2, f_theo, cat(2, 0*max(Bound_alpha(1), min(Bound_alpha(2), Mu_alpha+.5*randn(1,N_Cpt))), sen==sor));
  71. % end
  72. % end
  73. % F_theo = cat(1, F_theo, f_theo);
  74. % end
  75. %% Data simulation
  76. X_theo = G_theo*F_theo; % Theoretical matrix X (see eq.(2) of [1])
  77. W = zeros(s_n,N_Cpt+1);
  78. idx_Ref = randperm(s_n);
  79. idx_Ref = idx_Ref(1:N_Ref); % Reference measurement locations
  80. W(idx_Ref,end) = 1;
  81. N_RV = round(N_Cpt*RV); % Nb. of sensors having a RendezVous
  82. idx_CptRV = randperm(N_Cpt);
  83. idx_CptRV = idx_CptRV(1:N_RV); % Selection of sensors having a RendezVous
  84. idx_RefRV = randi(N_Ref,1,N_Cpt);
  85. idx_RefRV = idx_Ref(idx_RefRV(1:N_RV)); % Selection of the references for each RendezVous
  86. for i = 1 : N_RV
  87. W(idx_RefRV(i),idx_CptRV(i)) = 1;
  88. end
  89. N_data = round((1-MV)*(N_Cpt)*(s_n-N_Ref)); % Nb. of measurements in data matrix X
  90. xCpt = 1 : s_n;
  91. xCpt(idx_Ref) = []; % Reference free locations
  92. [xx,yy] = meshgrid(xCpt,1:N_Cpt); % Possibly sensed locations
  93. idx_data = randperm((s_n-N_Ref)*N_Cpt);
  94. for i = 1 : N_data
  95. W(xx(idx_data(i)),yy(idx_data(i))) = 1; % Sensor measurement placement
  96. end
  97. W = repmat(W, 1, N_sousCpt);
  98. N = var_n*randn(s_n,N_sousCpt*(N_Cpt+1)); % Noise simulation
  99. N(:,(N_Cpt+1)*(1:N_sousCpt)) = 0;
  100. N = max(N,-X_theo);
  101. X = W.*(X_theo+N); % Data matrix X
  102. Omega_G = [ones(s_n,1),W(:,(N_Cpt+1)*(1:N_sousCpt))]; % Mask on known values in G (see eq.(14) of [1])
  103. Omega_F = zeros(N_sousCpt+1,N_sousCpt*(N_Cpt+1));
  104. Omega_F(:,(N_Cpt+1)*(1:N_sousCpt)) = 1; % Mask on known values in F (see eq.(15) of [1])
  105. Phi_G = [ones(s_n,1),X(:,(N_Cpt+1)*(1:N_sousCpt))]; % Known values in G (see eq.(14) of [1])
  106. Phi_F = F_theo .* Omega_F; % Known values in F (see eq.(15) of [1])
  107. %% Initialization
  108. Ginit = ones(s_n,1);
  109. for sensor = 1:N_sousCpt
  110. g = zeros(s_n,1);
  111. for pic = 1:n_pic
  112. mu = 2*(rand(1,2)-0.5);
  113. sig = diag([ Bound_phen((sensor-1)*2+1) + (Bound_phen((sensor-1)*2+2) - Bound_phen((sensor-1)*2+1))*abs(randn()+0.5) , ...
  114. Bound_phen((sensor-1)*2+1) + (Bound_phen((sensor-1)*2+2) - Bound_phen((sensor-1)*2+1))*abs(randn()+0.5) ]);
  115. g = g + mvnpdf(xxyy,mu,sig);
  116. end
  117. g = (Bound_phen((sensor-1)*2+2) - Bound_phen((sensor-1)*2+1))/(max(g)-min(g))*(g-min(g)) + Bound_phen((sensor-1)*2+1);
  118. % .5*(g/max(g))+1e-5
  119. Ginit = cat(2, Ginit, g);
  120. end
  121. Ginit = (1-Omega_G).*Ginit+Phi_G;
  122. % Ginit = G_theo;
  123. Finit = zeros(N_sousCpt+1, N_sousCpt*(N_Cpt+1));
  124. for sensor = 1:N_sousCpt
  125. Finit(1,(sensor-1)*(N_Cpt+1)+1:sensor*(N_Cpt+1)) = ...
  126. cat(2, max(Bound_beta((sensor-1)*2+1), min(Bound_beta((sensor-1)*2+2), ...
  127. Mu_beta(sensor)+(Bound_beta((sensor-1)*2+2)-Bound_beta((sensor-1)*2+1))*0.25*randn(1,N_Cpt))), 0);
  128. end
  129. for sen = 1:N_sousCpt
  130. finit = cat(2, max(Bound_alpha((sen-1)*2+1),...
  131. min( Bound_alpha((sen-1)*2+2), ...
  132. Mu_alpha(sen)+(Bound_alpha((sen-1)*2+2)-Bound_alpha((sen-1)*2+1))*0.25*randn(1,N_Cpt))), 1);
  133. Finit(sen+1, (sen-1)*(N_Cpt+1)+1:sen*(N_Cpt+1)) = finit;
  134. % C = (1-gamma)/gamma*(Finit(1,(sen-1)*(N_Cpt+1)+1:sen*(N_Cpt+1)-1)+Bound_phen((sen-1)*2+1)*finit(1:end-1));
  135. % list_nosen = 1:N_sousCpt;
  136. % list_nosen(sen) = [];
  137. % maxPhen_nosen = norm(Bound_phen(2*list_nosen));
  138. for sor = 1:N_sousCpt
  139. if sen~=sor
  140. % finit_nosen = rand(1,N_Cpt).*C/(sqrt(N_sousCpt)*maxPhen_nosen);
  141. % other_finit = cat(2, finit_nosen, 0);
  142. % Finit(sor+1, (sen-1)*(N_Cpt+1)+1:sen*(N_Cpt+1)) = other_finit;
  143. Finit(sor+1, (sen-1)*(N_Cpt+1)+1:sen*(N_Cpt+1)) = zeros(1,N_Cpt+1); % initialization of other dependencies at zero
  144. end
  145. end
  146. end
  147. % Finit = F_theo;
  148. end