disp('*** One-sample model ***');

P=10;
PocStavu=5;

disp('=== Reading data ===');
S1=ReadPrase(1); O1=c_matrice(S1,P,160,80);

S2=ReadPrase(2); O2=c_matrice(S2,P,160,80);
S3=ReadPrase(3); O3=c_matrice(S3,P,160,80);
S4=ReadPrase(4); O4=c_matrice(S4,P,160,80);
S5=ReadPrase(5); O5=c_matrice(S5,P,160,80);
S6=ReadPrase(6); O6=c_matrice(S6,P,160,80);
S7=ReadSoubor('osel.raw'); O7=c_matrice(S7,P,160,80);
S8=ReadSoubor('kyticka.raw'); O8=c_matrice(S8,P,160,80);

disp('=== Training model ===');
A=inittran(PocStavu);
[MI,SIGMA]=initemis(O1,PocStavu);

[NEWA,NEWMI,NEWSIGMA,Ptot,ALFA,BETA,L]=reestim(O1,A,MI,SIGMA);
for iter=1:5
  [NEWA,NEWMI,NEWSIGMA,Ptot,ALFA,BETA,L]=reestim(O1,NEWA,NEWMI,SIGMA);
end
A=NEWA;
MI=NEWMI;

disp('=== Recognizing ===');
[Pvit,X]=viterbi_log(O1,A,MI,SIGMA);
disp(strcat('Trénovací prase:   ',num2str(Pvit)));

[Pvit,X]=viterbi_log(O2,A,MI,SIGMA);
disp(strcat('Neznámé prase I:   ',num2str(Pvit)));
[Pvit,X]=viterbi_log(O3,A,MI,SIGMA);
disp(strcat('Neznámé prase II:  ',num2str(Pvit)));
[Pvit,X]=viterbi_log(O4,A,MI,SIGMA);
disp(strcat('Neznámé prase III: ',num2str(Pvit)));
[Pvit,X]=viterbi_log(O5,A,MI,SIGMA);
disp(strcat('Neznámé prase IV:  ',num2str(Pvit)));
[Pvit,X]=viterbi_log(O6,A,MI,SIGMA);
disp(strcat('Neznámé prase V:   ',num2str(Pvit)));

[Pvit,X]=viterbi_log(O7,A,MI,SIGMA);
disp(strcat('Osel: ',num2str(Pvit)));
[Pvit,X]=viterbi_log(O8,A,MI,SIGMA);
disp(strcat('Kytièka: ',num2str(Pvit)));