i have simulated my data with the following codes. but seems like it is giving wrong answer. how a prediction gives like a parralal line. my data set Y=[182 325 390 480 519 620 630 609 635 700 660 615 561.15 534 589.9 703.45 651.02 674.62 661.42 652.66 646.34 642.4 664.34 660.03 683.11 664.66 688.61 697.53 693.71 680.43 751.3 ]
plt = 0; % T = simplenar_dataset;
N = length(Y) % 100
net = narnet( 1:2,[] ); % default inputs
view(net)T = tonndata(Y,false,false);[ Xs, Xsi, Asi, Ts ] = preparets( net, {}, {}, T );ts = cell2mat( Ts );plt = plt+1; figure(plt), hold onplot( 3:N, ts, 'LineWidth', 2 ) rng( 'default' )[ net tr Ys Es Af Xf ] = train( net, Xs, Ts, Xsi, Asi );% [ Ys Xf Af ] = net( Xs, Xsi, Asi )
% Es = gsubtract( Ts, Ys )
view( net )NMSEs = mse( Es ) /var( ts,1 ) % 1.8107e-08
ys = cell2mat( Ys );plot( 3:N, ys, 'ro', 'LineWidth', 2 )axis( [ 0 31 180 800 ] )legend( 'TARGET', 'OUTPUT' )title( 'OPENLOOP NARNET RESULTS' ) % 7. Now, the output feedback loop is closed and tested so that predictions can
% eventually be extended beyond the time of the known target, T.
[ netc Xci Aci ] = closeloop(net,Xsi,Asi); view(netc) [Xc,Xci,Aci,Tc] = preparets(netc,{},{},T); [ Yc Xcf Acf ] = netc(Xc,Xci,Aci); Ec = gsubtract(Tc,Yc); yc = cell2mat(Yc); tc = ts; NMSEc = mse(Ec) /var(tc,1) %3.505e-07
% Although the performance is a factor of 20 worse, it is still excellent. If it were significantly degraded, %netc would be trained starting with the weights obtained in the openloop stage (NOTE: This is not %mentioned in either %the help or doc documentation).
% 8. The removedelay function is included in both documentations. However, I see no good reason for %using it here. For example, when used with the default output feedback delay 1:2, it yields invalid zero %and/or negative %values.
%IS THIS A BUG THAT NEEDS TO BE FIXED ?
% 9. To extend the prediction beyond the end of the known series, empty cells are
% used as inputs and the final delay states Xcf and Acf are used as initial conditions. and are used
% [ Yc Xcf Acf ] = netc( Xc, Xci, Aci );
Xc2 = cell(1,N);[Yc2 Xcf2 Acf2] = netc( Xc2, Xcf, Acf ); yc2 = cell2mat(Yc2);plt = plt+1; figure(plt), hold onplot( 3:N, tc, 'LineWidth', 2 )plot( 3:N, yc, 'ro', 'LineWidth', 2 )plot( N+1:2*N, yc2, 'o', 'LineWidth', 2 )plot( N+1:2*N, yc2, 'r', 'LineWidth', 2 )axis( [ 0 N+15 180 900 ] )legend( 'TARGET','OUTPUT','PREDICTION ')title( 'CLOSED LOOP NARNET RESULTS ' )
Best Answer