To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _FullBNT / BNT / CPDs / @gaussian_CPD / learn_params.m @ 8:b5b38998ef3b
History | View | Annotate | Download (1005 Bytes)
| 1 |
function CPD = learn_params(CPD, fam, data, ns, cnodes) |
|---|---|
| 2 |
%function CPD = learn_params(CPD, fam, data, ns, cnodes) |
| 3 |
% LEARN_PARAMS Compute the maximum likelihood estimate of the params of a gaussian CPD given complete data |
| 4 |
% CPD = learn_params(CPD, fam, data, ns, cnodes) |
| 5 |
% |
| 6 |
% data(i,m) is the value of node i in case m (can be cell array). |
| 7 |
% We assume this node has a maximize_params method. |
| 8 |
|
| 9 |
ncases = size(data, 2); |
| 10 |
CPD = reset_ess(CPD); |
| 11 |
% make a fully observed joint distribution over the family |
| 12 |
fmarginal.domain = fam; |
| 13 |
fmarginal.T = 1; |
| 14 |
fmarginal.mu = []; |
| 15 |
fmarginal.Sigma = []; |
| 16 |
if ~iscell(data) |
| 17 |
cases = num2cell(data); |
| 18 |
else |
| 19 |
cases = data; |
| 20 |
end |
| 21 |
hidden_bitv = zeros(1, max(fam)); |
| 22 |
for m=1:ncases |
| 23 |
% specify (as a bit vector) which elements in the family domain are hidden |
| 24 |
hidden_bitv = zeros(1, max(fmarginal.domain)); |
| 25 |
ev = cases(:,m); |
| 26 |
hidden_bitv(find(isempty(ev)))=1; |
| 27 |
CPD = update_ess(CPD, fmarginal, ev, ns, cnodes, hidden_bitv); |
| 28 |
end |
| 29 |
CPD = maximize_params(CPD); |
| 30 |
|
| 31 |
|