Help Testing with NARXNET Model
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Sanjana
on 24 Sep 2024
Hi,
"preparets" function is used to create input and target time series data for network simulation or training.During inference, you wouldn't need to use "preparets" function as you are trying to predict y for any given x1 and x2 values.
Please refer to the code below to predict the y values using the trained network,
%Assuming xo and xi are the inputs
%predict y value
y = func_net(xo,xi);
Hope this helps!
Regards,
Sanjana
0 Comments
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!