function [LL]=DuffeeFacLL(THETA);

global Y

T=max(abs(size(Y)));

[F,Q,H,R,E]=DuffeeFac(THETA);

dimX=5;

if E==1;


QQ=Q*Q';
RR=R*R';

LL=0;

P=reshape(inv(eye(dimX*dimX)-kron(F,F))*QQ(:),dimX,dimX);
Xfilt=zeros(dimX,1); %initial value for the filtered state.

for tt=1:T
    a=Y(:,tt)-H*Xfilt;
    Omega=H*P*H'+RR;
    Omegainv=inv(Omega);
    K=F*P*H'*Omegainv;
    L=F-K*H;
    Xfilt=F*Xfilt+K*a;
    P = F*P*L' + QQ;    
    LL = LL - 0.5*(log(det(Omega)) + a'*Omegainv*a);   
end

lpostcan=LL;
else;
    LL=-9e+200
end

%We are minimizing!
LL=-LL;