function samples = sample_bnet(bnet, numex)
% SAMPLE_BNET Generate some random samples from the joint distribution encoded by the Bayes net.
%
% SAMPLES = SAMPLE_BNET(BNET, NUMEX) returns a matrix of NUMEX rows.

samples = blockmatrix(numex, [], 1, bnet.blocks);
%%%samples = blockmatrix(numex, bnet.blocks);
num_nodes = length(bnet.adj_mat);
obs_nodes = bnet.observed_nodes;
for s=1:numex
  bnet.observed_nodes = obs_nodes; % reset
  for i=1:num_nodes
    x =  sample_node(bnet, i);
    bnet.values(i) = x; % so future nodes can condition on this
    samples(s,i) = x;
    bnet.observed_nodes = union(bnet.observed_nodes, i);
  end
end
