
% Alpha{t}{s} contains the belief state at time t in the s'th sample (if ~conditioned(i))
%  alpha{t}{s}{i}(:) contains the distrib over node i.
% Cond{t}(s,i) contains the value for node i at time t in the s'th sample (if conditioned(i))
%  cond{t}(s,i) contains the value of node i.
% Weights{t}(s) contains the weight of sample s.

clamped_nodes = union(obs_nodes, cond_nodes);
nclamped = length(clamped_nodes);
 % in general these should be block vectors
evidence = zeros(1, ss);
prev_evidence = zeros(1, ss);

for t=2:T
  s = 1;
  samples = [];
  weights = [];
  wsum = 0;
  pick = sample_discrete(normalise(Weights{t-1}), 1, max_samples);  % propagate these guys
  while (s <= max_samples & wsum < min_weight) | s <= min_samples
    prev_alpha = Alpha{t-1}{pick(s)};
    prev_cond = Cond{t-1}(pick(s), cond_nodes);
    prev_evidence(obs_nodes) = vals{t-1};
    prev_evidence(cond_nodes) = prev_cond;
    current_cond = to be sampled; % *******
    evidence(obs_nodes) = vals{t};
    evidence(cond_nodes) = current_cond;
    [alpha, w] = update_belief_state(bnet, prev_alpha, clamped_nodes, evidence(clamped_nodes), ...
	clamped_nodes, prev_evidence(clamped_nodes), t);
    Weights{t}(s) = w;
    wsum = wsum + w;
    Alpha{t}{s} = alpha;
    Cond{t}(s,:) = current_cond;
  end
end
