function draw_cpt(CPT, names,k)
% draw_CPT Shows the CPT tables as heat maps 
%
% draw_cpt(CPT, names)
%
% CPT(i,j,k) is prob(K=k|I=i,J=j) or
% CPT(i,j) is prob(J=j|I=i) or
% CPT(i) is prob(I=i)
%
% names{q} is the name of the q'th variable (same order as the dimensions
% of CPT)

% APRENDIZAJE AUTOMÁTICO (G. Pajares y J. M. de la Cruz, Eds.)
% Editorial: RA-MA
% Capítulo 6: Redes Bayesianas
% Autores: Diane Oyen, Eva Besada-Portas

dims = size(CPT);
nDims = length(dims);

if nDims<3
  imagesc(CPT);
  set(gca, 'DefaulttextInterpreter', 'none');
  title(strcat('Tabla de probabilidad de  ', names{1}));
  xlabel(names{1});
  ylabel(names{2});
elseif nDims==3
  for i=1:dims(nDims)
    subplot(4, dims(nDims), i+(k-1)*4), imagesc(CPT(:,:,i), [0 1]);
    set(gca, 'DefaulttextInterpreter', 'none');
    title(sprintf('#%s=%d',names{1},i));
    xlabel(sprintf('#%s',names{2}));
    axis image;
    if i==1
      ylabel(sprintf('#%s',names{3}));
    end
  end
  %text(-11,-1, strcat('Tabla de probabilidad de:   ', names{1}))
else
  error('Cannot display %i -dimensional CPT\n', nDims);
end
