diff options
Diffstat (limited to 'sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine')
8 files changed, 101 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/CVS/Entries b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/CVS/Entries new file mode 100644 index 00000000..1c5d76dd --- /dev/null +++ b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/CVS/Entries @@ -0,0 +1,6 @@ +/enter_evidence.m/1.1.1.1/Mon Jun 7 19:05:42 2004// +/find_mpe.m/1.1.1.1/Wed Jun 19 21:56:32 2002// +/global_joint_inf_engine.m/1.1.1.1/Wed May 29 15:59:56 2002// +/marginal_family.m/1.1.1.1/Wed May 29 15:59:56 2002// +/marginal_nodes.m/1.1.1.1/Mon Jun 7 19:04:48 2004// +D diff --git a/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/CVS/Repository b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/CVS/Repository new file mode 100644 index 00000000..0c8fadf5 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/CVS/Repository @@ -0,0 +1 @@ +FullBNT/BNT/inference/static/@global_joint_inf_engine diff --git a/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/CVS/Root b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/CVS/Root new file mode 100644 index 00000000..f3bd14a6 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/CVS/Root @@ -0,0 +1 @@ +:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt diff --git a/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/enter_evidence.m b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/enter_evidence.m new file mode 100644 index 00000000..105894ff --- /dev/null +++ b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/enter_evidence.m @@ -0,0 +1,42 @@ +function [engine, loglik] = enter_evidence(engine, evidence, varargin) +% ENTER_EVIDENCE Add the specified evidence to the network (global_joint) +% [engine, loglik] = enter_evidence(engine, evidence, ...) +% +% evidence{i} = [] if if X(i) is hidden, and otherwise contains its observed value. +% +% Warning: Computing the log likelihood requires marginalizing all the nodes and can be slow. +% +% The list below gives optional arguments [default value in brackets]. +% +% exclude - list of nodes whose potential will not be included in the joint [ [] ] +% +% e.g., engine = enter_evidence(engine, ev, 'exclude', 3) + +exclude = []; +maximize = 0; + +if nargin >= 3 + args = varargin; + nargs = length(args); + for i=1:2:nargs + switch args{i}, + case 'exclude', exclude = args{i+1}; + case 'maximize', maximize = args{i+1}; + otherwise, + error(['invalid argument name ' args{i}]); + end + end +end + +assert(~maximize) +bnet = bnet_from_engine(engine); +N = length(bnet.node_sizes); +%[engine.jpot, loglik] = compute_joint_pot(bnet, mysetdiff(1:N, exclude), evidence, 1:N); +[engine.jpot] = compute_joint_pot(bnet, mysetdiff(1:N, exclude), evidence, 1:N); +% jpot should not be normalized, otherwise it gives wrong resutls for limids like asia_dt1 +if nargout == 2 + [m] = marginal_nodes(engine, []); + [T, lik] = normalize(m.T); + loglik = log(lik); +end +%[engine.jpot loglik] = normalize_pot(engine.jpot); diff --git a/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/find_mpe.m b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/find_mpe.m new file mode 100644 index 00000000..92915b6c --- /dev/null +++ b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/find_mpe.m @@ -0,0 +1,28 @@ +function [mpe, ll] = find_mpe(engine, evidence) +% FIND_MPE_GLOBAL Compute the most probable explanation(s) from the global joint +% [mpe, ll] = find_mpe(engine, evidence) +% +% mpe(k,i) is the most probable value of node i in the k'th global mode (cell array) +% +% We assume all nodes are discrete + +%engine = global_joint_inf_engine(bnet); +bnet = bnet_from_engine(engine); +engine = enter_evidence(engine, evidence); +S1 = struct(engine); % violate object privacy +S2 = struct(S1.jpot); % joint potential +prob = max(S2.T(:)); +modes = find(S2.T(:) == prob); + +ens = bnet.node_sizes; +onodes = find(~isemptycell(evidence)); +ens(onodes) = 1; +mpe = ind2subv(ens, modes); +for k=1:length(modes) + for i=onodes(:)' + mpe(k,i) = evidence{i}; + end +end +ll = log(prob); + +mpe = num2cell(mpe); diff --git a/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/global_joint_inf_engine.m b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/global_joint_inf_engine.m new file mode 100644 index 00000000..86bca532 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/global_joint_inf_engine.m @@ -0,0 +1,8 @@ +function engine = global_joint_inf_engine(bnet) +% GLOBAL_JOINT_INF_ENGINE Construct the global joint distribution as a potential +% engine = global_joint_inf_engine(bnet) +% +% Warning: this has size exponential in the number of discrete hidden variables + +engine.jpot = []; +engine = class(engine, 'global_joint_inf_engine', inf_engine(bnet)); diff --git a/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/marginal_family.m b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/marginal_family.m new file mode 100644 index 00000000..6931814c --- /dev/null +++ b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/marginal_family.m @@ -0,0 +1,7 @@ +function [m, pot] = marginal_family(engine, i) +% MARGINAL_FAMILY Compute the marginal on i's family (global_inf_engine) +% [m, pot] = marginal_family(engine, i) +% + +bnet = bnet_from_engine(engine); +[m, pot] = marginal_nodes(engine, family(bnet.dag, i)); diff --git a/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/marginal_nodes.m b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/marginal_nodes.m new file mode 100644 index 00000000..223e6574 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/inference/static/@global_joint_inf_engine/marginal_nodes.m @@ -0,0 +1,8 @@ +function [m, pot] = marginal_nodes(engine, query) +% MARGINAL_NODES Compute the marginal on the specified set of nodes (global_joint) +% [m, pot] = marginal_nodes(engine, query) + +pot = marginalize_pot(engine.jpot, query); +m = pot_to_marginal(pot); +%[m.T, lik] = normalize(m.T); +%loglik = log(lik); |
