%SCRIPT_APP correction

%+
% module
% ======
%
% correction du TP
%
%
% DESCRIPTION
% ===========
%
% ++
%
% ``script_app``
%
% If ``fid_log`` is not set, log informations are printed on stdout.
%
% +++If ``fid_log`` set previous launching ``script_correc`` to more than 1,
% log informations are saved in ``script_correc.log``.
%
% EXAMPLES
% ========
%
% This script can not be launched directly.
%
% see script_correc.m_
%
% SEE ALSO
% ========
%
% script_correc.m_
%
% .. _script_correc.m : script_correc.m.html
%
%
% TODO
% ====
%
% improve description
%
% EVOLUTIONS
% ==========
%
% $Id$
%
% - fplod 2009-08-18T15:41:07Z aedon.locean-ipsl.upmc.fr (Darwin)
%
%   * add header
%   * log information either on screen (stdout) or in file associated to
%     fid_log file identifier and already opened
%
%-
%
% définition du fichier de sortie "Affichage"
% if not set, fid_log is set to 1 (stdout)
if ~ exist('fid_log','var')
 fid_log = 1;
end

% +++vérification si ouverture du fichier de sortie "Affichage" si différent 
% de stdout
fid_log_is_stdout = isequal(fid_log,1);
if fid_log_is_stdout == 0
 fullfilename = ['./', mfilename, '.log'];
 fid_log = fopen(fullfilename,'w');
 clear fullfilename;
end

archi=[20 40 60 80 100];
init=[1 2];

nets=repmat(struct('W1',[],'W2',[]),length(archi),length(init));
perf=nan*ones(length(archi),length(init));

for n=1:length(archi)
  for i=1:length(init)

    fprintf(fid_log,'\nApprentissage %d neurones cachees, initialisation #%d\n',archi(n),init(i));
    %Init du reseau
    [nets(n,i).W1 nets(n,i).W2]=MLPinit(base_app_n(:,1:end-1),base_app_n(:,end),archi(n));

    %Apprentissage du reseau
    [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), ...
                                       base_app_n(:,end),nets(n,i).W1,nets(n,i).W2,'tah','lin',[1500,1e-6],[100,1]);


    %Restitution du reseau
  tau_nn=MLPval(base_val_n(:,1:end-1),nets(n,i).W1,nets(n,i).W2);

  %Performance du reseau
  delta=(decenred(base_val_n(:,end),moy(end),et(end)) - decenred(tau_nn,moy(end),et(end))).^2;
  perf(n,i)=sqrt((1./length(delta))*sum(delta));

  end %for i
end %for n
