addpath('..\..\..\methods\FunAppr\LMMLP');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% data prapration

t=0:0.02:2*pi; L=1;
traject=[3*cos(t);4*sin(t)];
plot(traject(1,:),traject(2,:),'.');
figure;hold on;
for i=1:2
    x=traject(:,1:1:length(t)-L)';
    y=traject(i,L+1:1:length(t))';
    max_x=max(max(x));max_y(i)=max(y);
    train_x=x/max_x;train_y=y/max_y(i);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Training
    if i==1
        [E1,NetDef1,W11,W12]=noisecan(train_x,train_y,20);
    else
        [E1,NetDef2,W21,W22]=noisecan(train_x,train_y,20);
    end
end
traject=[3/3*cos(t);4/3*sin(t)];
plot(traject(1,:),traject(2,:),'.');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Testing
for i=1:2
    x=traject(:,1:1:length(t)-L)';
    y=traject(i,L+1:1:length(t))';
    test_x=x'/max_x;test_y=y'/max_y(i);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if i==1
        % Testing
        [Y_sim,E,PI] = nneval(NetDef1,W11,W12,test_x,test_y,1);
    else
        % Testing
        [Y_sim,E,PI] = nneval(NetDef2,W21,W22,test_x,test_y,1);
    end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Display results and errors
    figure
    plot(1:1:length(test_y),test_y,'.');
    hold on
    plot(1:1:length(Y_sim),Y_sim,'ro');
    fprintf('\n mean square testing error %f\n',mean(E.^2));
    fprintf(' mean absolute testing error %f',mean(abs(E)));
end


