# File lib/bn4r/bn_algorithms.rb, line 74
  def rejection_sampling( x, e, n, bn = self )
  
      evidece_list = [e] if e.class != Array
      x_list = [x] if x.class != Array
           
      nodes_ordered = bn.nodes_ordered_by_dependencies
      evidence_vector = get_vector_value(evidece_list, nodes_ordered)
      x_vector = get_vector_value(x_list, nodes_ordered)
      
      total_valid = 0; total_correct = 0
      n.times do
        sample_vector  = bn.prior_sample(nodes_ordered).collect {|v| v.value}
        
        valid = true; correct = true
        for i in 0..(sample_vector.size-1) do
          correct = false if !x_vector[i].nil? and sample_vector[i] != x_vector[i]
          valid = false and break if !evidence_vector[i].nil? and sample_vector[i] != evidence_vector[i]
        end
        
        next if !valid
        total_valid += 1
        total_correct += 1 if correct  
      end
      
      p_true = total_correct.to_f/total_valid.to_f
      return [p_true, 1-p_true]
      #return [total_correct.to_f, total_valid.to_f]
  end