matthiasm@8: function y = sample_node(CPD, pev) matthiasm@8: % SAMPLE_NODE Draw a random sample from P(Xi | x(pi_i), theta_i) (gaussian) matthiasm@8: % y = sample_node(CPD, parent_evidence) matthiasm@8: % matthiasm@8: % pev{i} is the value of the i'th parent (if there are any parents) matthiasm@8: % y is the sampled value (a scalar or vector) matthiasm@8: matthiasm@8: if length(CPD.dps)==0 matthiasm@8: i = 1; matthiasm@8: else matthiasm@8: dpvals = cat(1, pev{CPD.dps}); matthiasm@8: i = subv2ind(CPD.sizes(CPD.dps), dpvals(:)'); matthiasm@8: end matthiasm@8: matthiasm@8: if length(CPD.cps) == 0 matthiasm@8: y = gsamp(CPD.mean(:,i), CPD.cov(:,:,i), 1); matthiasm@8: else matthiasm@8: pev = pev(:); matthiasm@8: x = cat(1, pev{CPD.cps}); matthiasm@8: y = gsamp(CPD.mean(:,i) + CPD.weights(:,:,i)*x(:), CPD.cov(:,:,i), 1); matthiasm@8: end matthiasm@8: y = y(:);