开发工具:
文件大小: 2kb
下载次数: 0
上传时间: 2015-01-06
详细说明: 贝叶斯网络的K2结构学习 clear N = 4; dag = zeros(N,N); %C = 1; S = 2; R = 3; W = 4; % topological order C = 4; S = 2; R = 3; W = 1; % arbitrary order dag(C,[R S]) = 1; dag(R,W) = 1; dag(S,W)=1; false = 1; true = 2; ns = 2*ones(1,N); % binary nodes bnet = mk_bnet(dag, ns); bnet.CPD{C} = tabular_CPD(bnet, C, 'CPT', [0.5 0.5]); bnet.CPD{R} = tabular_CPD(bnet, R, 'CPT', [0.8 0.2 0.2 0.8]); bnet.CPD{S} = tabular_CPD(bnet, S, 'CPT', [0.5 0.9 0.5 0.1]); bnet.CPD{W} = tabular_CPD(bnet, W, 'CPT', [1 0.1 0.1 0.01 0 0.9 0.9 0.99]); [n ncases] = siz e(data); % set default params type = cell(1,n); params = cell(1,n); for i=1:n type{i} = 'tabular'; %params{i} = { 'prior', 1 }; params{i} = { 'prior_type', 'dirichlet', 'dirichlet_weight', 1 }; end scoring_fn = 'bayesian'; discrete = 1:n; clamped = zeros(n, ncases); max_fan_in = n; verbose = 0; dag = zeros(n,n); for i=1:n ps = []; j = order(i); u = find(clamped(j,:)==0); score = score_family(j, ps, type{j}, scoring_fn, ns, discrete, data(:,u), params{j}); if verbose, fprintf('\nnode %d, empty score %6.4f\n', j, score), end done = 0; while ~done & (length(ps) <= max_fan_in) pps = mysetdiff(order(1:i-1), ps); % potential parents nps = length(pps); pscore = zeros(1, nps); for pi=1:nps p = pps(pi); pscore(pi) = score_family(j, [ps p], type{j}, scoring_fn, ns, discrete, data(:,u), params{j}); if verbose, fprintf('considering adding %d to %d, score %6.4f\n', p, j, pscore(pi)), end end [best_pscore, best_p] = max(pscore); best_p = pps(best_p); if best_pscore > score score = best_pscore; ps = [ps best_p]; if verbose, fprintf('* adding %d to %d, score %6.4f\n', best_p, j, best_pscore),end else done = 1; end end if ~isempty(ps) % need this check for matlab 5.2 dag(ps, j) = 1; end end ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.