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:
x1 = [-100:0.1:100];
x2 = [-100:0.1:100];
y_data = 4*x1 + 20*sin(x1) + 30*cos(x2) + 89*(x1./x2);
y_data(1001) = []; x1(1001) = []; x2(1001) = [];
func_net = narxnet(1:2,1:2);
func_net.numInputs = 2;
func_net.inputConnect = [1 1; 0 0];
x = [x1;x2];
x_in = con2seq(x);
y_target = con2seq(y_data);
[xo,xi,~,to] = preparets(func_net,x_in,{},y_target);
func_net = train(func_net,xo,to,xi);
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:
net_closed = closeloop(func_net);
net_closed.numInputs = 2;
net_closed.inputConnect = [1 1; 0 0];
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.