% TEST_FLST tests the fixed lag sparse transition Viterbi implementation

addpath('misc')
addpath('smoothiecore')
addpath('flst')

%% setup model

mdl = hmm_dummy();
memory = 3;
d = flstMakeData(mdl, memory);

%% now make up some probabilites

obsLik = [...
    [0.5, 0.5];
    [0.8, 0.2];
    [0.4, 0.6];
    [0.8, 0.2];
    [0.8, 0.2];
    [0.2, 0.8];
    [0.3, 0.7];
    [0.9, 0.1]]';

nFrame = size(obsLik,2);


for iFrame = 1:nFrame-1
    d = flstViterbiUpdate(obsLik(:,iFrame), d);
end
d = flstViterbiUpdate(obsLik(:,iFrame), d, 1);
e = d;
d = flstMakeData(mdl, memory);
disp(e)

%% test

if all((e.path-[1 1 1 1 1 2 2 2])==0)
    fprintf(1, 'Test ok.\n');
else
    warning('Test has detected an error.')
end