function [samples, weights] = lw(bnet, num_samples, evidence, obs, max_node)
% LW Likelihood Weighting: generate some random samples (row vectors) by walking down the graph
% [samples, weights] = lw(bnet, num_samples, evidence, obs, max_node)
%
% evidence is a vector of length N, where N = num. nodes
% obs(i) = 1 if node i is observed, and is 0 otherwise.
% max_node defaults to num_nodes, and be used to prevent sampling beyond a certain point in the graph.

if nargin < 5 % ~exist('max_node')
  max_node = length(bnet.adj_mat);
end
  
if bnet.useC
  [samples, weights] = C_lw(num_samples, evidence(:)-1, obs, max_node-1);
  samples = samples + 1;
else
  [samples, weights] = lw_noC(bnet, num_samples, evidence, obs, max_node);
end
