function lh=mcexlh(z,y,x)
%function lh=mcexlh(z,y,x)
% z(1:2) is b; z(3:4) is log(sigma);  z(5:6) is tan((p-.5)*pi), where p is the
% vector of diagonal elements of the transition matrix H.
nz=size(z,2);
T=size(y,1);
b=z(1:2,:);sig=exp(z(3:4,:));
H=zeros(2,2,nz);
b=cat(2,b,b);sig=reshape(sig,[1,2,nz]);
z(5:6,:)=atan(z(5:6,:))/pi+.5;
H(1,1,:)=z(5,:);H(2,1,:)=1-z(5,:);H(1,2,:)=1-z(6,:);H(2,2,:)=z(6,:);
sp=zeros(T,2,nz);
lh=zeros(T,nz);
for iz=1:nz
   [lh(:,iz),sp(:,:,iz)]=mclh(y,x,sig,b,H);
end
if any(lh<=eps*100)
   lh=1e100;
else
   lh=-sum(log(lh));
end
