MATLAB: Neural network: generated function usage

narneural networksntstool

Hello! I'm trying to play with neural networks toolbox. I've tought a network to predict values of
sin(x/1150)+1
function using 10 previous values. I used
x = 1:1:240*60
to generate targets set. Training goes just fine and ntstool asks me whether I want to test my network. I test it using values generated for
x = 1:1:480*60.
It says that MSE is 4e-12. I think it's great. I generate a matrix-only function in order to use this network. Unfortunately, when I try to test it with my own code, results are awful. The net cannot even predict the first 50 values! I think the problem is in my test code, here it is:
x = (240 * 60 - 10):1:(240*60); % keys
func = @(x) sin(x/100) + 1; % predicted function
y = func(x); % expected values
vi = []; % initial values
start = 1;
for i = drange(start:start+9)
vi = [vi [y(i)]];
end
x2 = (240 * 60+1):1:(240*60+4000);
y2 = func(x2); % we will predict these values
y1 = [];
for i = drange(x2)
[v, vi2] = myNeuralNetworkFunction(i, vi); % predit a single value
y1 = [y1 [v]]; % save it
vi = vi([ 1+1:end 1:1 ]); % shift left by 1 value
vi(10) = v; % and append predicted value to the list
end
plot(x2, y2, '-r');
hold on
plot(x2, y1, '-g');
Could anyone help me?

Best Answer

How many points are needed to uniquely specify a sinusoidal function? Since the general form for a pure sinusoid, A*cos(w*t+phi), contains 3 parameters, I think that you need at least 3 points per period.
Your period is
X = 2*pi*1150; % 7225.7
The number of points you have is
N = 240*60 % 14400
The resulting number of points per period is
PPP = Np/X % 1.9929 < 2
So, I do not think that you have enough data per period.
You say that you can model the training data without error.
Are you sure the model was not overfit and overtrained so that the training data was memorized?
How much training data? Ntrn =
How many outputs? O = 1
How many training equations? Ntrneq = Ntrn*O = Ntrn
How many inputs? I = 1
How many hidden nodes? H= ?
How many unknown weights? Nw = (I+1)*H+(H+1)*O = 3*H+1
Do you have more equations than weights? H < (Ntrn-1)/3 = ?
Hope this helps.
Greg