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