clear all;
close all;

randn(seed,131);
W=randn(8,3);

randn(seed,181);
B=randn(2,8);

nn=400;
aa=round(rand(nn,1));

for ii=1:nn
  if aa==1
    X=[6 6 6];

    %X=[6 6 6]+randn(3,1);
    y=1;
  else
    X=[-6 -6 -6];

    %X=[-6 -6 -6]+randn(3,1);
    y=1;
  end

  U=W*X;

  R=1./(1+exp(-U));

  P=B*R;
  p1=P(1);
  p2=P(2);
 
  p=exp(p1)/(exp(p1)+exp(p2));
  q=exp(p2)/(exp(p1)+exp(p2));

  oo(ii)=p;

  dd1=repmat(p*(1-p),1,3);
  K1=diag(dd1);

  dd2=repmat(p*(1-p),1,8);
  K2=diag(dd2);
 
  neta1=(1/(X*K1*X))*(y-p)*X;
  neta2=(1/(R*K2*R))*(y-p)*R;
 
  daba1=repmat(neta1,8,1);
  daba2=repmat(neta2,2,1);
  ee(ii)=-y*log(p)-(1-y)*log(1-p);

  W=W+0.1*daba1;
  B=B+0.1*daba2;
 
end

figure;plot(oo);grid on;
xlabel(Number of observations);ylabel(Probabilities);
figure;plot(ee);grid on;
xlabel(Number of observations);ylabel(Entropy);