learn_params_tabular.m

来自「麻省理工学院的人工智能工具箱,很珍贵,希望对大家有用!」· M 代码 · 共 32 行

M
32
字号
function [bnet, LL, BIC_score] = learn_params_tabular(bnet, data)% LEARN_PARAMS_TABULAR Find the maximum likelihood params for a fully observed tabular model% [bnet, LL, BIC_score] = learn_params_tabular_ML(bnet, data)%% This is just a special case of learn_params, and should not be used!% It is being kept merely for backwards compatibility with BNT2tiny = exp(-700);n = length(bnet.dag);ll = zeros(1, n);nparams = zeros(1,n);ncases = size(data, 2);ns = bnet.node_sizes;for i=1:n  if adjustable_CPD(bnet.CPD{i})    ps = parents(bnet.dag, i);    dom = [ps i];    counts = compute_counts(data(dom,:), ns(dom));    CPT = mk_stochastic(counts);    bnet.CPD{i} = tabular_CPD(bnet, i, CPT);    ll(i) = sum(log(CPT(:)  + tiny) .* counts(:));    % CPT(i) = 0 iff counts(i) = 0 so it is okay to add tiny    nparams(i) = prod([ns(ps) ns(i)-1]);    %fprintf('node %d, L %6.4f, params %d\n', i, ll(i), nparams(i));    % sum-to-1 constraint reduces the effective num. vals of the node by 1  endendLL = sum(ll);D = sum(nparams);BIC_score = LL - 0.5*D*log(ncases);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?