function res = crf1dtest(x,y,chain) D = size(x{1},1); D1 = D+1; L = size(x{1},2); % special case - all sequences are of the same length res.pred = []; res.probestflat = []; res.yflat= []; for i=1:length(x) for j=1:L x{i}(D1,:) = 1; end logLocalEv = (chain.w' * x{i}); % localEv(q,t) localEv = exp(logLocalEv); [bel, belE, logZ] = bpchainInfer(chain.infEngine, chain.pot, localEv); % bel is a numClasses x L matrix % belE is a numClasses x numClasses x (L-1) probability transition matrix % belE(i,j,k) has the probability of going from class i in % time k to class j in time k+1 % logZ is presumably the probability of the whole sequence res.probest{i} = bel'; % L x numclasses res.probtrans{i} = belE; res.logZ(i) = logZ; [a,b] = max(bel); res.pred(i,:) = b; res.probestflat = vertcat(res.probestflat,bel'); res.yflat = vertcat(res.yflat,y{i}'); end [res.mostconfflat,res.predflat] = max(res.probestflat'); [res.cm,res.nc] = getcm(res.yflat, res.predflat, 1:chain.nstates ); res.ac = res.nc / sum(sum(res.cm));