function [NEWA,NEWMI,NEWSIGMA,Ptot, ALFA, BETA, L] = reestim (O, A, MI, SIGMA);
%
% Upravená verze pro jeden vzorek

[P,T]=size(O);
N=size(A,1);

if T<N,
 error ('Not enough obs. vectors to reestim all states');
end

[ALFA,Ptot]=GetAlfa(O,A,MI,SIGMA);

[BETA]=GetBeta(O,A,MI,SIGMA);

%%%%%%%%%%%% reestim trans %%%%%%%%%%%%%%

NEWA=GetNewA(O,A,MI,SIGMA,Ptot,ALFA,BETA);

L=zeros(N,T);
L=ALFA .* BETA / Ptot;

NEWMI=zeros(size(MI));
NEWSIGMA=zeros(size(SIGMA));
for j=2:(N-1),
  Lvec = L(j,:);
  Lmat=ones(P,1) * Lvec;
  NEWMI(:,j) = sum((Lmat .* O)')' / sum(Lvec);
  NEWSIGMA(:,j) = sum((Lmat .* ((O-NEWMI(:,j) * ones(1,T)).^2))')' / sum(Lvec);
end


