Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@stab_cond_gauss_inf_engine/marginal_nodes.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function marginal = marginal_nodes(engine, query, add_ev) | |
2 % MARGINAL_NODES Compute the marginal on the specified query nodes (stab_cond_gauss) | |
3 % marginal = marginal_nodes(engine, query, add_ev) | |
4 % | |
5 % 'query' must be a singleton set. | |
6 % add_ev is an optional argument; if 1, we will "inflate" the marginal of observed nodes | |
7 % to their original size, adding 0s to the positions which contradict the evidence | |
8 | |
9 if nargin < 3, add_ev = 0; end | |
10 if isempty(engine.evidence) | |
11 hquery = query; | |
12 else | |
13 hquery = []; | |
14 for i = query | |
15 if isempty(engine.evidence{i}) | |
16 hquery = [hquery i]; | |
17 end | |
18 end | |
19 end | |
20 | |
21 bnet = bnet_from_engine(engine); | |
22 | |
23 nclq = length(engine.cliques); | |
24 clique = 0; | |
25 for i = 1:nclq | |
26 if mysubset(hquery, engine.cliques{i}) | |
27 pot = struct(engine.clpot{i}); | |
28 %if mysubset(hquery, pot.cheaddom) | mysubset(hquery, pot.ddom) | |
29 if mysubset(hquery, pot.domain) | |
30 clique = i; | |
31 break; | |
32 end | |
33 end | |
34 end | |
35 | |
36 if isempty(hquery) | |
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
38 % If all requested variables are observed, no query is necessary % | |
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
40 marginal.mu = []; | |
41 marginal.Sigma = []; | |
42 marginal.T = 1.0; | |
43 marginal.domain = query; | |
44 else | |
45 if clique == 0 | |
46 marginal = marginal_difclq_nodes(engine, hquery); | |
47 else | |
48 marginal = marginal_singleclq_nodes(engine, clique, hquery); | |
49 end | |
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
51 % Change the format of output, so that it is identical to the % | |
52 % format obtained by the same request for the junction-tree % | |
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
54 marginal.domain = query; | |
55 bnet = bnet_from_engine(engine); | |
56 dquery = myintersect(bnet.dnodes,hquery); | |
57 ns = bnet.node_sizes(dquery); | |
58 if length(ns) == 0 | |
59 marginal.T = 1; | |
60 else | |
61 if length(ns) == 1 | |
62 ns = [1 ns]; | |
63 end | |
64 marginal.T = reshape(marginal.T,ns); | |
65 end | |
66 end | |
67 if add_ev | |
68 bnet = bnet_from_engine(engine); | |
69 %marginal = add_ev_to_dmarginal(marginal, engine.evidence, bnet.node_sizes); | |
70 marginal = add_evidence_to_gmarginal(marginal, engine.evidence, bnet.node_sizes, bnet.cnodes); | |
71 end | |
72 | |
73 | |
74 | |
75 | |
76 | |
77 |