1
我的問題特定於MatLab中BayesNetToolbox的「learn_params()」函數。在用戶手冊中,「learn_params()」僅適用於完全遵守輸入數據的情況。我用一個部分觀察的數據集對其進行了嘗試,在那裏我將未觀測到的值表示爲NaN。MatLab BayesNetToolbox參數學習
看起來像「learn_params()」可以處理NaN和數據集中不存在的節點狀態組合。當我應用dirichlet先驗來平滑0值時,我得到了所有節點的「明智的」MLE分佈。我在這裏複製了腳本。
有人可以澄清是否我在做什麼是有道理的,或者如果我缺少的東西 ,即之所以「learn_params()」不能以部分 觀測數據使用。
MATLAB的腳本,我測試這是在這裏:
% Incomplete dataset (where NaN's are unobserved)
Age = [1,2,2,NaN,3,3,2,1,NaN,2,1,1,3,NaN,2,2,1,NaN,3,1];
TNMStage = [2,4,2,3,NaN,1,NaN,3,1,4,3,NaN,2,4,3,4,1,NaN,2,4];
Treatment = [2,3,3,NaN,2,NaN,4,4,3,3,NaN,2,NaN,NaN,4,2,NaN,3,NaN,4];
Survival = [1,2,1,2,2,1,1,1,1,2,2,1,2,2,1,2,1,2,2,1];
matrixdata = [Age;TNMStage;Treatment;Survival];
node_sizes =[3,4,4,2];
% Enter the variablesmap
keys = {'Age', 'TNM','Treatment', 'Survival'};
v= 1:1:length(keys);
VariablesMap = containers.Map(keys,v);
% create the dag and the bnet
N = length(node_sizes); % Instead of entering it manually
dag2 = zeros(N,N);
dag2(VariablesMap('Treatment'),VariablesMap('Survival')) = 1;
bnet21 = mk_bnet(dag2, node_sizes);
draw_graph(bnet21.dag);
dirichletweight=1;
% define the CPD priors you want to use
bnet23.CPD{VariablesMap('Age')} = tabular_CPD(bnet23, VariablesMap('Age'), 'prior_type', 'dirichlet','dirichlet_type', 'unif', 'dirichlet_weight', dirichletweight);
bnet23.CPD{VariablesMap('TNM')} = tabular_CPD(bnet23, VariablesMap('TNM'), 'prior_type', 'dirichlet','dirichlet_type', 'unif', 'dirichlet_weight', dirichletweight);
bnet23.CPD{VariablesMap('Treatment')} = tabular_CPD(bnet23, VariablesMap('Treatment'), 'prior_type', 'dirichlet','dirichlet_type', 'unif','dirichlet_weight', dirichletweight);
bnet23.CPD{VariablesMap('Survival')} = tabular_CPD(bnet23, VariablesMap('Survival'), 'prior_type', 'dirichlet','dirichlet_type', 'unif','dirichlet_weight', dirichletweight);
% Find MLEs from incomplete data with Dirichlet prior CPDs
bnet24 = learn_params(bnet23, matrixdata);
% Look at the new CPT values after parameter estimation has been carried out
CPT24 = cell(1,N);
for i=1:N
s=struct(bnet24.CPD{i}); % violate object privacy
CPT24{i}=s.CPT;
end
@ Kaelin,非常感謝您的回答。我一定會根據你的建議比較兩者。你知道bayes_update_params()如何支持缺失值的數學答案嗎?它是否忽略它們(如learn_params()那樣)或用某些東西替換丟失的數據? [是的,我會分析這個功能。] – Rhubarb 2012-07-14 11:07:58
是的,在閱讀更多內容後,我同意這一點。當你保持缺失的值爲NaN時,MatLab會在計算不同狀態出現的最大似然估計時自動忽略這些單元。這不完全刪除,但類似的東西。 – Rhubarb 2012-07-26 15:00:23