clear all
fstr=input('input a 2D function: x1.^2+x2.^2+cos(x1) :','s');
fx=inline(fstr);
range=2;
x1=-range:0.02:range;
x2=x1;
for i=1:length(x1)
        C(i,:)=fx(x1(i),x2);
end
mesh(x1,x2,C);
hold on;
%N=200;
N= input('keyin N:');
x(1,:)=rand(1,N)*2*range-range;
x(2,:)=rand(1,N)*2*range-range;
n=rand(1,N)*0.3-0.15;
y=fx(x(1,:),x(2,:))+n;
plot3(x(2,:),x(1,:),y,'.');
g=fit_HP(x,y);

M=input('keyin M:');
[E,NetDef,W1,W2]=noisecan(x',y',M);
[Y_sim,E,PI] = nneval(NetDef,W1,W2, x, y,1);
fprintf('\n MSE for training %f\n',mean(E.^2));

x_test(1,:)=rand(1,N)*2*range-range;
x_test(2,:)=rand(1,N)*2*range-range;
n=rand(1,N)*0.3-0.15;
y_test=fx(x_test(1,:),x_test(2,:))+n;
plot3(x_test(2,:),x_test(1,:),y_test,'x');
[Y_sim,E,PI] = nneval(NetDef,W1,W2, x_test, y_test,1); 
fprintf('MSE for testing %f\n',mean(E.^2)); 