% One output layer.

temp=load('training_data.mat');
Xd=temp.temp.X;
Yd=temp.temp.Y;


net = feedforwardnet([2 3]);
% Default optimization method:
% Levenberg-Marquardt (default, fast for small to medium problems)

% Set training function (backpropagation variant)
% net.trainFcn = 'traingdx';  

% Default transfer functions:
% Hidden layers use tansig and output layer uses linear.

net.layers{1}.transferFcn = 'logsig';
net.layers{2}.transferFcn = 'logsig';
% net.layers{3}.transferFcn = 'logsig';

% % Training-validation split:
% net.divideParam.trainRatio = 1.0;
% net.divideParam.valRatio   = 0.0;
% net.divideParam.testRatio  = 0.0;

% net.trainParam.epochs=1000;
% net.trainParam.min_grad = 1e-10;

% net = configure(net,Xd,Yd);
net = train(net,Xd,Yd);

xx=0:0.01:1;
yy=0:0.01:1;

X=zeros(length(xx),length(yy));
Y=X;
Fx=X;
Fy=X;

for i=1:length(xx)
    for j=1:length(yy)
        x1_val=xx(i);
        x2_val=yy(j);

        x=[x1_val,x2_val]';

        X(i,j)=x1_val;
        Y(i,j)=x2_val;

        F_temp=net([x1_val,x2_val]');
        Fx(i,j)=F_temp;
    end
end

contour(X,Y,Fx,[0.5 0.5],'LineWidth',3,'color','black')
hold on

N=length(Yd);
for i=1:N
        x_val=Xd(1,i);
        y_val=Xd(2,i);
        z_val=x_val+sqrt(-1)*y_val;

        if(Yd(i)>0.95)
            plot(z_val,'o','color','red')
            hold on
        else
            plot(z_val,'x','color','blue')
            hold on
        end
 end


xlabel('x_1')
ylabel('x_2')

set(gca,'fontsize',16)
grid on
axis equal
set(gca,'xtick',0:0.2:1)
set(gca,'ytick',0:0.2:1)
hold off

drawnow