From: Serg on
Hi, All.

Can anyone share a working example of training NARX network with multiple input vectors?
Found some outdated code in support requests, but can't get it working in R2010a.


Thanks,
Serg
From: Zoran Jovic on
I am interested too. Also , what is the best type of NN for multivariate function approximation?
Thanks
Zoran

"Serg " <serg.buslovsky(a)gmail.com> wrote in message <hob7q9$c7t$1(a)fred.mathworks.com>...
> Hi, All.
>
> Can anyone share a working example of training NARX network with multiple input vectors?
> Found some outdated code in support requests, but can't get it working in R2010a.
>
>
> Thanks,
> Serg
From: Serg on
Here's a sample code:

function [ P,T,Pi,Ai ] = narx_forminputs( inputs_cell, num_start, num_neurons )
%NARX_FORMINPUTS Summary of this function goes here
% Detailed explanation goes here

[rows,cols] = size(inputs_cell);

% create cells
inputs = inputs_cell( :, (num_start+1):end );
output = inputs_cell( rows, (num_start+1):end );

% shift
%inputs = inputs( :, 1:(end-1) );
%output = output( 2:end );
%inputs( rows, : ) = output;

% compure starts
starts = inputs_cell( :, 1:num_start );

P = mat2cell(inputs,[size(inputs,1)-1 1],ones(size(inputs,2),1));
T = mat2cell(output,1,ones(size(output,2),1));

Pi = mat2cell(starts,[size(starts,1)-1 1],ones(size(starts,2),1));
Ai = cell(2,num_start);
for i=1:num_start Ai{1,i}=zeros(num_neurons,1); Ai{2,i}=inputs_cell(rows,i); end;

%P = P( :, (num_start+1):end );
%T = T( :, (num_start+1):end );

end

train_piece = 2200;
hidden_neurons = 40;
hidden_layers = 1;
delay = 5;
delay_in = [1:delay];
delay_out = [1:delay];
span = [-1 1];
narx_net = newnarxsp( { [ minmax(in1); minmax(in8); minmax(in6); minmax(in4) ], minmax(out1) }, delay_in, delay_out, [hidden_neurons hidden_layers], {'tansig','purelin'}, 'trainlm', 'learngdm', 'mse' );
narx_net.performFcn = 'mae';

inputs = [ in1(1:train_piece); in8(1:train_piece); in6(1:train_piece); in4(1:train_piece); out1(1:train_piece) ];
[P,T,Pi,Ai] = narx_forminputs( inputs, delay, hidden_neurons );
narx_net.trainFcn = 'trainbr';
narx_net.trainParam.show = 10;
narx_net.trainParam.epochs = 1000;
narx_net=train(narx_net,P,T,Pi);

yp = sim(narx_net,P,Pi);
%yp = sim(narx_net,P);
e = cell2mat(yp)-cell2mat(T);
plot(e)