确定函数调用的方法

时间:2016-08-24 13:59:11

标签: matlab function bayesian-networks

我正在处理bayesnet toolbox中的代码,我正在努力查看如何判断特定函数调用调用哪个方法。

例如,电话

convert_to_pot(bnet.CPD{e}, pot_type, fam(:), evidence)

对于特定类型的CPD,有多个convert_to_pot函数(in folders here),因此我认为调用它是由对象bnet.CPD的某些属性决定的。如果CPD节点是离散的,我认为它会调用@discrete_CPD,但是有没有办法确定?或者你能从结构告诉函数调用的结果。感谢

methods(convert_to_pot)返回 undefined

一个有效的例子

    % set up graph and CPD's
    N = 4; 
    dag = zeros(N,N); 
    C = 1; S = 2; R = 3; W = 4;
    dag(C,[R S]) = 1; 
    dag(R,W) = 1;
    dag(S,W)=1;
    discrete_nodes = 1:N;
    node_sizes = 2*ones(1,N);
    bnet = mk_bnet(dag, node_sizes, 'discrete', discrete_nodes);
    bnet.CPD{C} = tabular_CPD(bnet, C, [0.5 0.5]);
    bnet.CPD{R} = tabular_CPD(bnet, R, [0.8 0.2 0.2 0.8]);
    bnet.CPD{S} = tabular_CPD(bnet, S, [0.5 0.9 0.5 0.1]);
    bnet.CPD{W} = tabular_CPD(bnet, W, [1 0.1 0.1 0.01 0 0.9 0.9 0.99]);

    %evidence node
    evidence = cell(1,N);
    evidence{W} = 2;    
    ns = bnet.node_sizes(:); [2 2 2 2]
    onodes = find(~isemptycell(evidence)); % 4
    hnodes = find(isemptycell(evidence)); % 1 2 3
    pot_type = determine_pot_type(bnet, onodes); % 'd'  :discrete
    fam = family(bnet.dag, 4); % 2 3 4

函数调用和结果

    pot = convert_to_pot(bnet.CPD{4}, pot_type, fam(:), evidence)
%     discrete potential object
%     domain: [2 3 4]
%          T: [2x2 double]
%      sizes: [2 2 1]

从评论中更新;

>> methods(bnet.CPD{e})

Methods for class tabular_CPD:

CPD_to_CPT              learn_params            maximize_params         update_ess              
bayes_update_params     log_marg_prob_node      reset_ess               update_ess_simple       
display                 log_nextcase_prob_node  set_fields              
get_field               log_prior               tabular_CPD             

>> class(bnet.CPD{e})

ans =

tabular_CPD

>> superclasses(bnet.CPD{4})

No class tabular_CPD.

@tabular_CPD没有convert_to_pot功能。

1 个答案:

答案 0 :(得分:1)

我无法从问题中得知(我没有安装此工具箱),但根据您的描述,它听起来像bnet.CPD {e}是一个类,convert_to_pot是各种类的方法它可能是类的类型。在这种情况下,也许您可​​以尝试方法(bnet.CPD {e})?