clear all;
clc;
close all;
figure
eta=0.1;
max=10;
tic
% load iris.dat % Iris data as Input
% data=iris;
data=csvread('dataset_3y_adcolna.csv');% Malaria data as Input
inputpatterns = data;
[m n] = size(inputpatterns);%m = no of rows, n = no of colums
w=rand(1,(n-1))*0.1;% initial values for a
b=rand(1,(n-1));% initial values for b
% % d=rand(1,(n-1))*0.2;% initial values for c
x=inputpatterns(:,1:(n-1));
t=inputpatterns(:,n)';
for z =1:1:max % z=no of iterations
    product=ones(1,m);
    for k=1:(n-1)
        product=product.*(w(k)*x(:,k)+b(k))';% multiplicative weighted sum
    end
%     disp(product);
     a=2/(22/7); %2/pi
     y=atan(product);
    y=(t-y);%sigmoid function
    e=t-y;%error
    U=sum(e.^2);%mean square error
%     disp(U)
    % finding weight changes for a,b,d
    for j=1:m
        for i=1:(n-1)
            derivativew(j,i)=a.*product(j)./((w(i)*x(j,i)+b(i))')*x(j,i);
            derivativeb(j,i)=a.*product(j)./((w(i)*x(j,i)+b(i))');
        end
    end
    M =[derivativew,derivativeb];
    allparameters=[w,b]';
    % updating weight changes for a,b,d
    allparameters=allparameters-eta*M'*e';
    w=allparameters(1:(n-1),1)';
    b=allparameters((n):end,1)';
    product=zeros(1,m);
    for k=1:(n-1)
        product=product.*(w(k)*x(:,k)+b(k))';
    end
    y=a.*atan(product);
    e=t-y;
    V=sum(e.^2);
disp('Error:')
   disp(V)% displays the error terms
    arr(z)=V;
   plot(arr/m);
   title('Error graph')
end
toc
% checking input data
product=ones(1,m);
for k=1:(n-1)
product=product.*(w(k)*x(:,k)+b(k))';
end
computed=a.*atan(product);
inputpatternst=[inputpatterns,computed'];
% disp('error');
e=t-computed;
