%%% %%% File "train_net.m": neural network training and generation %%% % Caricare P e T; P = Psim(1:round(size(Psim,1)/3),:)'; T = Tsim(1:round(size(Psim,1)/3),1)'; %%% %%% Neural network parameters %%% Si = 4; % Number of neurons in the input layer Sh = 8; % Number of neurons in the hidden layer So = 1; % Number of neurons in the output layer % It is equal to the rows of the matrix T TFi = 'tansig'; % Sigmoidal tangent activation function TFh = 'tansig'; TFo = 'purelin'; % Linear activation function %BTF = 'traingdx'; % Function for the training of the % backpropagation NN, default BTF = 'trainlm'; % Levenberg-Marquardt backpropagation BLF = 'learngdm'; % Backpropagation function % weight/bias, default PF = 'mse'; % Performance function Mean Square Error % default PR = minmax(P); % Equal to: [min(P')' , max(P')'], it % determines minimal and maximal values of % inputs and output val.P = Psim(round(size(Psim,1)/3)+1:2*round(size(Psim,1)/3),:)'; % validation data val.T = Tsim(round(size(Psim,1)/3)+1:2*round(size(Psim,1)/3),:)'; test.P = Psim(2*round(size(Psim,1)/3)+1:end,:)'; % test data test.T = Tsim(2*round(size(Psim,1)/3)+1:end,:)'; %net = newff(P,T,[Si Sh So],{TFi TFh TFo},BTF,BLF,PF); % Note: it generates a NN % with 4 layers!!! net = newff(P,T,[Si Sh],{TFi TFh TFo},BTF,BLF,PF); %%% %%% Parameters for the NN training %%% net.trainParam.epochs = 300; % Number of epocs net.trainParam.goal = 1e-4; % Value of the final error net.trainParam.show = 1; % Show the plot after 1 epoch net.trainParam.lr = 0.05; % Learning rate for trainlm function net.trainParam.mc = 0.9; % Momentum constant: gradient value % during the training phase: if 0 -> % weights are changed only on the basis % of the gradient; if 1 -> gradient % function is completely neglected net = train(net,P,T,[],[],val,test); % training function Ts = 0.05; % Sampling time % NOTE: it should be equal to the sampling time used % for collecting the matrices Tsim and Psim!!! net.sampleTime = Ts; gensim(net,Ts); % It creates the neural network in Simulink return