Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@gaussian_inf_engine/enter_evidence.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 [engine, loglik] = enter_evidence(engine, evidence, varargin) | |
2 % ENTER_EVIDENCE Add the specified evidence to the network (gaussian_inf_engine) | |
3 % [engine, loglik] = enter_evidence(engine, evidence, ...) | |
4 % | |
5 % evidence{i} = [] if if X(i) is hidden, and otherwise contains its observed value (scalar or column vector) | |
6 | |
7 bnet = bnet_from_engine(engine); | |
8 ns = bnet.node_sizes; | |
9 O = find(~isemptycell(evidence)); | |
10 H = find(isemptycell(evidence)); | |
11 vals = cat(1, evidence{O}); | |
12 | |
13 % Compute Pr(H|o) | |
14 [Hmu, HSigma, loglik] = condition_gaussian(engine.mu, engine.Sigma, H, O, vals(:), ns); | |
15 | |
16 engine.Hmu = Hmu; | |
17 engine.HSigma = HSigma; | |
18 engine.hnodes = H; | |
19 | |
20 %%%%%%%% | |
21 | |
22 function [mu2, Sigma2, loglik] = condition_gaussian(mu, Sigma, X, Y, y, ns) | |
23 % CONDITION_GAUSSIAN Compute Pr(X|Y=y) where X and Y are jointly Gaussian. | |
24 % [mu2, Sigma2, ll] = condition_gaussian(mu, Sigma, X, Y, y, ns) | |
25 | |
26 if isempty(y) | |
27 mu2 = mu; | |
28 Sigma2 = Sigma; | |
29 loglik = 0; | |
30 return; | |
31 end | |
32 | |
33 use_log = 1; | |
34 | |
35 if length(Y)==length(mu) % instantiating every variable | |
36 mu2 = y; | |
37 Sigma2 = zeros(length(y)); | |
38 loglik = gaussian_prob(y, mu, Sigma, use_log); | |
39 return; | |
40 end | |
41 | |
42 [muX, muY, SXX, SXY, SYX, SYY] = partition_matrix_vec(mu, Sigma, X, Y, ns); | |
43 K = SXY*inv(SYY); | |
44 mu2 = muX + K*(y-muY); | |
45 Sigma2 = SXX - K*SYX; | |
46 loglik = gaussian_prob(y, muY, SYY, use_log); |