source: trunk/private/script_correc.m @ 19

Last change on this file since 19 was 19, checked in by pinsard, 15 years ago

add tool to run script_correc.m and save stdout, stderr and figures

  • Property svn:keywords set to Id
File size: 7.5 KB
Line 
1%SCRIPT_CORREC correction
2
3%+
4% module
5% ======
6%
7% correction du TP
8%
9%
10% DESCRIPTION
11% ===========
12%
13% ++
14%
15% ``script_correc`` plot ans save several figures :
16%
17%  - ``script_correc_thetas.eps`` :
18%
19%   figure:: script_correc_thetas.eps
20%   :scale: 50 %
21%   :alt: script_correc_thetas.eps
22%
23%   This is the caption of the figure (a simple paragraph).
24%
25%   The legend consists of all elements after the caption.  In this
26%   case, the legend consists of this paragraph and the following
27%   table:
28
29%
30%  - ``script_correc_thetav.eps`` :
31%
32%  - ``script_correc_dphi.eps`` :
33%
34%  - ``script_correc_rho_670_.eps`` :
35%
36%  - ``script_correc_rho_765_.eps`` :
37%
38%  - ``script_correc_rho_865_.eps`` :
39%
40%  - ``script_correc_tau.eps`` :
41%
42%  - ``script_correc_diagramme_dispersion.eps`` :
43%
44%  - ``script_correc_histogramme_erreur.eps`` :
45%
46% If ``fid_log`` is not set, log informations are printed on stdout.
47%
48% If ``fid_log`` set previous launching ``script_correc`` to more than 1,
49% log informations are saved in ``script_correc.log``.
50%
51% EXAMPLES
52% ========
53%
54% To run and see log informations on screen :
55%
56% ::
57%
58% >> addpath('../toolbox')
59% >> tp_mlp_aerosols_startup
60% >> more off
61% >> script_correc
62%
63% To run and save log informations in ``script_correc.log`` :
64%
65% ::
66%
67% >> addpath('../toolbox')
68% >> tp_mlp_aerosols_startup
69% >> fid_log = 6;
70% >> more off
71% >> script_correc
72%
73%
74% SEE ALSO
75% ========
76%
77% tp_mlp_aerosols_startup.m_
78%
79% .. _tp_mlp_aerosols_startup.m : tp_mlp_aerosols_startup.m.html
80%
81% intersect_octave.m_
82%
83% .. _intersect_octave.m : intersect_octave.m.html
84%
85% script_app.m_
86%
87% .. _script_app.m : script_app.m.html
88%
89% TODO
90% ====
91%
92% improve description
93%
94% avoid overriding existing output files
95%
96% make it launchable from everywhere (path and IO directories)
97%
98% Running octave, ``more off`` is compulsary but I don't not yet why
99%
100% save output (stderr) to make comparisons possible
101%
102% If printer is set to png, one might see following warning using octave :
103% ..
104%
105% gdImageStringFT: Could not find/open font while printing string ... with font Helvetica
106%
107% And no labels are visible on figure outputfiles.
108%
109% For now, find a portable solution (setting GDFONTPATH) is too tough, so
110% printer is set to eps.
111%
112% EVOLUTIONS
113% ==========
114%
115% $Id$
116%
117% - fplod 2009-08-18T14:21:33Z aedon.locean-ipsl.upmc.fr (Darwin)
118%
119%   * log information either on screen (stdout) or in ``script_correc.log``
120%
121% - fplod 2009-08-18T09:55:12Z aedon.locean-ipsl.upmc.fr (Darwin)
122%
123%   * save figures to make comparisons possible
124%   * replace error on suptitle using octave by a warning
125%
126% - fplod 2009-08-17T12:39:51Z aedon.locean-ipsl.upmc.fr (Darwin)
127%
128%   * add header
129%   * add octave intersect_octave
130%   * add octave suptitle_octave
131%
132%-
133
134
135
136%Ajout du path
137addpath ('../toolbox');
138
139
140%% QUESTION 1
141%NOTE : C'est la partie du TP à modifier car il y a trop de choses à coder.
142
143if ~exist('LUT_NIR','var')
144 load('../LUT/LUT_NIR.dat');
145end
146
147%indices pour chacune des longeurs d'onde
148i670=find(LUT_NIR(:,6)==670);
149i765=find(LUT_NIR(:,6)==765);
150i865=find(LUT_NIR(:,6)==865);
151
152%fusion 670nm avec 765nm
153if (run_octave == 0)
154 [parambase,I1,I2]=intersect(LUT_NIR(i670,[1:5]),LUT_NIR(i765,[1:5]),'rows');
155else
156 [parambase,I1,I2]=intersect_octave(LUT_NIR(i670,[1:5]),LUT_NIR(i765,[1:5]),'rows');
157end
158base=[parambase LUT_NIR(i670(I1),7) LUT_NIR(i765(I2),7)];
159
160%fusion de base avec 670nm avec base
161if (run_octave == 0)
162 [parambase,I1,I2]=intersect(base(:,[1:5]),LUT_NIR(i865,[1:5]),'rows');
163else
164 [parambase,I1,I2]=intersect_octave(base(:,[1:5]),LUT_NIR(i865,[1:5]),'rows');
165end
166
167%base=[thetas,thetav,dphi,Rho_aer(670),Rho_aer(765),Rho_aer(865) tau]
168base=[base(I1,[3:5 6:7]) LUT_NIR(i865(I2),7) base(I1,2)];
169base_mix=mix_base(base); %%%%ALEA
170
171clear i670 i765 i865 base parambase;
172
173%% QUESTION 2
174N=size(base_mix,1);
175base_app=base_mix(1:round(0.02*N),:);
176base_val=base_mix(round(0.8*N)+1:round(0.82*N),:);
177base_test=base_mix(round(0.98*N)+1:end,:);
178
179%% QUESTION 3 : rien a faire
180
181%% QUESTION 4
182moy=mean(base_app);
183et=std(base_app);
184
185base_app_n=cenred(base_app,moy,et);
186base_val_n=cenred(base_val,moy,et);
187base_test_n=cenred(base_test,moy,et);
188
189
190stitle={'Thetas','Thetav','dphi','Rho(670)','Rho(765)','Rho(865)','Tau'};
191for j=1:size(base_mix,2)
192figure(j)
193clf
194
195subplot(3,2,1)
196hist(base_app(:,j),20);
197title('App denorm');
198
199subplot(3,2,2)
200hist(base_app_n(:,j),20);
201title('App norm');
202
203subplot(3,2,3)
204hist(base_val(:,j),20);
205title('Val denorm');
206
207subplot(3,2,4)
208hist(base_val_n(:,j),20);
209title('Val norm');
210
211subplot(3,2,5)
212hist(base_test(:,j),20);
213title('Test denorm');
214
215subplot(3,2,6)
216hist(base_test_n(:,j),20);
217title('Test norm');
218
219if (run_octave == 0)
220 suptitle(stitle{j});
221else
222 warning('www : octave can not write supertitle');
223end
224
225% save figure(j)
226printer='eps';
227print_printer=['-d', printer];
228% figure name is based on stitle{j}.
229% transformation is lower and replace ( and ) by _
230if (run_octave == 0)
231 figname=regexprep(lower(stitle{j}), '(', '_');
232else
233 figname=regexprep(lower(stitle{j}), '\(', '_');
234end
235if (run_octave == 0)
236 figname=regexprep(figname, ')', '_');
237else
238 figname=regexprep(figname, '\)', '_');
239end
240fullfilename=['./', mfilename, '_', figname , '.', printer];
241clear figname;
242clear printer;
243print(print_printer,fullfilename);
244clear print_printer;
245clear fullfilename;
246
247end
248
249%QUESTION 5
250script_app
251
252% définition du fichier de sortie "Affichage"
253% if not set, fid_log is set to 1 (stdout)
254if ~ exist('fid_log','var')
255 fid_log = 1;
256end
257
258% ouverture du fichier de sortie "Affichage" si différent de stdout
259fid_log_is_stdout = isequal(fid_log,1);
260
261if fid_log_is_stdout == 0
262 fullfilename = ['./', mfilename, '.log'];
263 fid_log = fopen(fullfilename,'w');
264 clear fullfilename;
265end
266
267%Affichage du tableau des performances
268fprintf(fid_log,'\n\t\tInit1\t\tInit2\n');
269for n=1:length(archi)
270 fprintf(fid_log,'%d neurones\t%3.2e\t%3.2e\n',archi(n),perf(n,1),perf(n,2));
271end
272
273
274%On determine l'architecture optimale
275mini=min(perf(:));
276[n,i]=find(perf==mini);
277fprintf(fid_log,'\n Architecture optimale : %d neurones (RMS=%3.2e)\n',archi(n),perf(n,i));
278
279%FACULTATIF : On prolonge l'apprentissage avec une base plus grosse
280base_app=base_mix(1:round(0.1*N),:);
281  %Apprentissage du rseau
282    [nets(n,i).W1 nets(n,i).W2]=MLPfit(base_val_n(:,1:end-1),base_val_n(:,end),base_app_n(:,1:end-1), ...
283                                       base_app_n(:,end),nets(n,i).W1,nets(n,i).W2,'tah','lin',[1500,1e-6],[100,1]);
284
285
286%QUESTION 6
287
288    %Restitution du reseau
289  tau_nn=MLPval(base_val_n(:,1:end-1),nets(n,i).W1,nets(n,i).W2);
290
291  %Performance du reseau
292  delta=decenred(tau_nn,moy(end),et(end)) - decenred(base_val_n(:,end),moy(end),et(end));
293  perf_opti=sqrt((1./length(delta))*sum(delta.^2));
294
295  fprintf(fid_log,'\nRMS finale : %3.2e\n',perf_opti);
296
297  % fermeture du ficher de sortie "Affichage" si différent de stdout
298  if fid_log_is_stdout == 0
299   fclose(fid_log);
300  end
301  clear fid_log_is_stdout;
302
303  figure
304  plot(decenred(base_val_n(:,end),moy(end),et(end)),decenred(tau_nn,moy(end),et(end)),'.');
305  hold on
306  plot([0 0.5],[0 0.5],'-k');
307  title('Diagramme de dispersion')
308  xlabel('TAU(vrai)')
309  ylabel('TAU(estime)');
310
311  % save figure
312  printer='eps';
313  print_printer=['-d', printer];
314  fullfilename=['./', mfilename, '_diagramme_dispersion', '.', printer];
315  clear printer;
316  print(print_printer,fullfilename);
317  clear print_printer;
318  clear fullfilename;
319
320  figure
321  hist(delta,50);
322  xlabel('TAU(estime)-TAU(vrai)');
323  ylabel('Nombre');
324
325  % save figure
326  printer='eps';
327  print_printer=['-d', printer];
328  fullfilename=['./', mfilename, '_histogramme_erreur', '.', printer];
329  clear printer;
330  print(print_printer,fullfilename);
331  clear print_printer;
332  clear fullfilename;
Note: See TracBrowser for help on using the repository browser.