Help Testing with NARXNET Model

1 view (last 30 days)
Yahya Fahmi
Yahya Fahmi on 22 Jan 2021
Edited: Yahya Fahmi on 22 Jan 2021
I am just getting into machine learning, and I am trying to create a neural network which models the following function:
y = 4*x1 + 20*sin(x1) + 30*cos(x2) + 89*(x1./x2)
I tried other networks such as feedforwardnet and fitnet, but achieved low performance, so I turned to narxnet.
I built, trained, and tested the model using the following:
% Generating input and output arrays in order to have data to train model
x1 = [-100:0.1:100];
x2 = [-100:0.1:100];
y_data = 4*x1 + 20*sin(x1) + 30*cos(x2) + 89*(x1./x2);
% Removing the point with NaN value from the dataset (x1/x2 = 0/0)
y_data(1001) = []; x1(1001) = []; x2(1001) = [];
% Creating network and assigning input attributes
func_net = narxnet(1:2,1:2);
func_net.numInputs = 2;
func_net.inputConnect = [1 1; 0 0];
% Preparing input and target data to train network
x = [x1;x2];
x_in = con2seq(x);
y_target = con2seq(y_data);
[xo,xi,~,to] = preparets(func_net,x_in,{},y_target);
% Training network using generated dataset
func_net = train(func_net,xo,to,xi);
% Testing model with inputs used for training
y = func_net(xo,xi);
perf = mse(func_net,to,y);
I am now trying to test the model one single point, and have come across many issues with preparets. I have tried the following:
% Converting network to closed loop to be able to deploy
net_closed = closeloop(func_net);
net_closed.numInputs = 2;
net_closed.inputConnect = [1 1; 0 0];
% Random Test Point
xx = [0;-10];
xx = con2seq(xx);
yy = con2seq([1]);
[XO,XI,~,TO] = preparets(net_closed,xx,{},yy);
but i get the following error:
Error using preparets (line 185)
The number of input signals does not match network's non-feedback inputs.
I'm confused because I set my test input as 2x1, and then use con2seq for proper formatting. The exact steps worked fine during training the model. Is it because it has now bee transformed to a closed loop?
All I want to do is to be able to use the model to predict a function value y for any given x1 and x2, but I am stuck and don't know where else to turn.
Any help would be greatly appreciated, thank you so much.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!