run_config.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. function [RMSEs] = run_config(varargin)
  2. if nargin == 0
  3. file_name = "default_config.json";
  4. elseif nargin == 1
  5. file_name = varargin{1};
  6. else
  7. file_name = varargin{1};
  8. warning("run_config only accepts one argument. Every other argument is ignored")
  9. end
  10. config = jsondecode(fileread(file_name));
  11. methods = config.calibrationMethods;
  12. iter_max = round(config.Tmax / config.delta_measure);
  13. RMSEs = cell(length(methods),1+config.numSubSensor);
  14. times = cell(length(methods),1);
  15. for run = 1:config.numRuns
  16. % data generation
  17. [X, X_theo, W, F_theo, Omega_G, Omega_F, Phi_G, Phi_F, Ginit, Finit] = data_gen(config, run);
  18. seed = floor(rand*10000);
  19. % We want to only calibrate the sensor(s) of interest according to config.CalibratedSensor
  20. idx_to_calibrate = kron(config.CalibratedSensor'-1,(config.numSensor+1)*ones(1,config.numSensor+1))+kron(ones(1,numel(config.CalibratedSensor)),1:config.numSensor+1);
  21. X = X(:,idx_to_calibrate);
  22. X_theo = X_theo(:,idx_to_calibrate);
  23. W = W(:,idx_to_calibrate);
  24. F_theo = F_theo(:,idx_to_calibrate);
  25. Omega_F = Omega_F(:,idx_to_calibrate);
  26. Phi_F = Phi_F(:,idx_to_calibrate);
  27. Finit = Finit(:,idx_to_calibrate);
  28. % X = X(:,1:config.numSensor+1);
  29. % X_theo = X_theo(:,1:config.numSensor+1);
  30. % W = W(:,1:config.numSensor+1);
  31. % F_theo = F_theo(1:2,1:config.numSensor+1);
  32. % Omega_F = Omega_F(1:2,1:config.numSensor+1);
  33. % Phi_F = Phi_F(1:2,1:config.numSensor+1);
  34. % Finit = Finit(1:2,1:config.numSensor+1);
  35. % Omega_G = Omega_G(:,1:2);
  36. % Phi_G = Phi_G(:,1:2);
  37. % Ginit = Ginit(:,1:2);
  38. % config.numSubSensor = 1;
  39. % Testing each method for the same data
  40. for it_meth = 1:length(methods)
  41. rng(seed) % resetting the seed before starting the method
  42. fct = str2func(methods{it_meth});
  43. [T, RMSE , MERs] = fct(X, X_theo, W, F_theo, Omega_G, Omega_F, Phi_G, Phi_F, Ginit, Finit, config);
  44. times{it_meth} = T; % overwritting previous record times for simplicity's sake
  45. % figure
  46. for measure = 1:(1+config.numSubSensor)
  47. RMSEs{it_meth,measure} = cat(1, RMSEs{it_meth,measure}, RMSE(measure,:)); % saving the RMSE
  48. % % RMSEs{it_meth,1} is for the offsets, RMSEs{it_meth,>1} is
  49. % % for the gains
  50. % plot(MERs(measure,:))
  51. % hold on
  52. end
  53. end
  54. end
  55. if config.display
  56. figure
  57. colors = ['b','r','g','k','y','c','m'];
  58. for it_meth = 1:length(methods)
  59. for measure = 2 % Only the RMSE for the gain
  60. % subplot(1,config.numSubSensor+1,measure) % Only the RMSE for the gain
  61. enveloppe_min = min(RMSEs{it_meth,measure},[],1);
  62. enveloppe_max = max(RMSEs{it_meth,measure},[],1);
  63. semilogy(enveloppe_max,colors(it_meth),'HandleVisibility','off');
  64. hold on
  65. semilogy(enveloppe_min,colors(it_meth),'DisplayName',"Enveloppe "+strrep(methods{it_meth},'_','\_'));
  66. legend show
  67. end
  68. end
  69. for it_meth = 1:length(methods)
  70. for measure = 2 % Only the RMSE for the gain
  71. med = median(RMSEs{it_meth,measure});
  72. semilogy(med,"--"+colors(it_meth),'LineWidth',3,'DisplayName',"Médiane "+strrep(methods{it_meth},'_','\_'));
  73. hold on
  74. legend show
  75. end
  76. end
  77. xlabel("Time (s)")
  78. ylabel("RMSE")
  79. grid on
  80. set(gca,'FontUnits','points','FontSize',18,'FontName','Times')
  81. fig = gcf;
  82. legend('AutoUpdate','off')
  83. Lines = findall(gcf,'Type','line');
  84. nenv = numel(Lines)/3;
  85. for k = 1:nenv
  86. line1 = Lines(3*nenv-(k-1)*2);
  87. line2 = Lines(3*nenv-(k-1)*2-1);
  88. fill([line1.XData flip(line2.XData)],[line1.YData flip(line2.YData)],colors(k),'LineStyle','none')
  89. end
  90. alpha(0.25)
  91. % for it_meth = 1:length(methods)
  92. % for measure = 2 % Only the RMSE for the gain
  93. % % subplot(1,config.numSubSensor+1,measure) % Only the RMSE for the gain
  94. % for k = 1:size(RMSEs{it_meth,measure},1)
  95. % if k == size(RMSEs{it_meth,measure},1)
  96. % semilogy(RMSEs{it_meth,measure}(k,:),colors(it_meth),'DisplayName',"Enveloppe "+strrep(methods{it_meth},'_','\_'));
  97. % else
  98. % semilogy(RMSEs{it_meth,measure}(k,:),colors(it_meth),'HandleVisibility','off');
  99. % end
  100. % hold on
  101. % end
  102. % legend show
  103. % set(gca,'FontUnits','points','FontSize',12,'FontName','Times')
  104. % end
  105. % end
  106. end
  107. % if config.display
  108. % figure
  109. % for it_meth = 1:length(methods)
  110. % for measure = 1:(config.numSubSensor+1)
  111. % subplot(length(methods),config.numSubSensor+1,(it_meth-1)*(config.numSubSensor+1)+measure)
  112. % for k = 1:size(RMSEs{it_meth,measure},1)
  113. % semilogy(RMSEs{it_meth,measure}(k,:))
  114. % hold on
  115. % end
  116. % hold off
  117. % end
  118. % end
  119. % end
  120. end
  121. % set(gcf,'OuterPosition',[200 200 400 440]);
  122. % axis square
  123. % pos = get(gcf,'paperposition');
  124. % set(gcf,'paperposition',[pos(1),pos(2), 4, 4]);
  125. % print -depsc epsFig