Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. double BayesNode::GetEventValue(BayesNode::query_value_ query_event_value) {
  2.   int prob_index = 0;
  3.   // Find the index of the probability from list, using binary representation
  4.   // of observed events as dictated in assignment specification
  5.   for(int i = 0; i < observed_list_; i++) {
  6.     prob_index += pow(2, observed_list_[i]);
  7.   }
  8.   // If the value is expected, return the 'w' weighting factor
  9.   if(query_event_value == True) {
  10.     return probability_list_[prob_index];
  11.   }
  12.   else if(query_event_value == False) {
  13.     return (double) (1 - probability_list_[prob_index]);
  14.   }
  15.   // Else, generate a random number to determine event outcome and return
  16.   double event_sample_value = GenerateSampleValue();
  17.   return (double) (event_sample_value > probability_list_[prob_index] ? 1 : 0);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement