function CPT = mk_CPT_from_noisy_channel(pfail, ns)
% MK_CPT_FROM_NOISY_CHANNEL Make a CPT from a noisy channel (duh)
% CPT = mk_CPT_from_noisy_channel(pfail, ns)
%
% This is a model of U -> UN, where UN is a noisy version of U.
% pfail(j) is the prob. the channel gets stuck in state j
% ns is the cardinality of U / UN.
%
% The result is CPT(U, UN)

CPT = zeros(ns, ns);
pnofail = 1 - sum(pfail);
for i=1:ns % U
  for j=1:ns % UN
    if i==j
      CPT(i,j) = pnofail + pfail(j);
    else
      CPT(i,j) = pfail(j);
    end
  end
end
