function CPT = learn_cpt(adjMat, child, data, nodesizes)

% learn_cpt     Compute the CPT according to the number of counts
%
% CPT = learn_cpt(adjMat, child, data, nodesizes)
%
% adjMat: adjacency matrix that stores the structure of the DBN
% child: node whose CPT is computed
% data: T*N matrix, in each row the data at time t, in each column the data
%       of a given variable
% CPT: CPT table, first the parents, later itself
%

% 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

rents = find(adjMat(:,child));
counts = compute_counts([data(1:end-1, rents) data(2:end, child)]', nodesizes([rents; child]));
CPT = mk_stochastic(counts);
