Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/BNT/CPDs/@gaussian_CPD/sample_node.m @ 8:b5b38998ef3b
added all that other stuff
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:54:25 +0100 |
parents | |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function y = sample_node(CPD, pev) |
matthiasm@8 | 2 % SAMPLE_NODE Draw a random sample from P(Xi | x(pi_i), theta_i) (gaussian) |
matthiasm@8 | 3 % y = sample_node(CPD, parent_evidence) |
matthiasm@8 | 4 % |
matthiasm@8 | 5 % pev{i} is the value of the i'th parent (if there are any parents) |
matthiasm@8 | 6 % y is the sampled value (a scalar or vector) |
matthiasm@8 | 7 |
matthiasm@8 | 8 if length(CPD.dps)==0 |
matthiasm@8 | 9 i = 1; |
matthiasm@8 | 10 else |
matthiasm@8 | 11 dpvals = cat(1, pev{CPD.dps}); |
matthiasm@8 | 12 i = subv2ind(CPD.sizes(CPD.dps), dpvals(:)'); |
matthiasm@8 | 13 end |
matthiasm@8 | 14 |
matthiasm@8 | 15 if length(CPD.cps) == 0 |
matthiasm@8 | 16 y = gsamp(CPD.mean(:,i), CPD.cov(:,:,i), 1); |
matthiasm@8 | 17 else |
matthiasm@8 | 18 pev = pev(:); |
matthiasm@8 | 19 x = cat(1, pev{CPD.cps}); |
matthiasm@8 | 20 y = gsamp(CPD.mean(:,i) + CPD.weights(:,:,i)*x(:), CPD.cov(:,:,i), 1); |
matthiasm@8 | 21 end |
matthiasm@8 | 22 y = y(:); |