N=5; %pocet klasickych neuronov
Typy=[1 0 0 1 0 -1 -1 -1];
Hrany=[1 2;
    2 1;
    1 3;
    2 N+2;
    3 4;
    3 5;
    4 1;
    4 N+2;
    5 1;
    5 N+2;
    N+3 N+2;
    N+3 1;
    N+1 1;
    N+1 2;
    N+1 3;
    N+1 4
    N+1 5];

Stavy=[0 0 0 0 0 0 0 1]

ed=zeros(N+3);

for k=1:size(Hrany)
    j=Hrany(k, 1);
    i=Hrany(k, 2);
    ed(j, i)=1;
end;

%Vypocet d
for i=1:N+3
    d(i)=0;
    for j=1:N+3
        if (j~=N+1) & (ed(j, i)==1)
            d(i)=d(i)+1;
        end;
    end;
end;
d

% Vypocet vah a prahov
for i=1:N+3
    for j=1:N+3
        w(i, j)=0
    end;
    
    for j=1:N+3
        if (j~=N+1) & (ed(j, i)==1)
            w(i, j)=1;
        end;
        if Typy(i)==1
            w(i, N+1)=d(i);
            Prahy(i)=d(i)+1;
        end;
        if Typy(i)==0
            w(i, N+1)=d(i);
            Prahy(i)=1;
        end;
    end;
end;

Prahy(N+3)=1; %Start
Prahy(N+2)=1; %Vystup
Prahy(N+1)=0; %Vstup0

for j=1:N+3
    if (j~=N+1) & (ed(j, N+2)==1)
        w(N+2, j)=1;
    end;
end;
z=Stav(N, 4, 1, ed, Stavy, Prahy, w)

% du dokoncit vypocet
% urobit skumane slovo
xx=[1 0 1 1 0 0]'; %transponovany vektor
Stav(N+1)=xx(1);
for iii=1:size(xx)
    x=xx(iii);
    StavyN(N+3)=Stav(N, N+3, x, ed, Stavy, Prahy, w);
    StavyN(N+2)=Stav(N, N+2, x, ed, Stavy, Prahy, w);
    %... od 1 do N podla funkcie
    Stavy
    Stavy=StavyN;
end;
