Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double BayesNode::GetEventValue(BayesNode::query_value_ query_event_value) {
- int prob_index = 0;
- // Find the index of the probability from list, using binary representation
- // of observed events as dictated in assignment specification
- for(int i = 0; i < observed_list_; i++) {
- prob_index += pow(2, observed_list_[i]);
- }
- // If the value is expected, return the 'w' weighting factor
- if(query_event_value == True) {
- return probability_list_[prob_index];
- }
- else if(query_event_value == False) {
- return (double) (1 - probability_list_[prob_index]);
- }
- // Else, generate a random number to determine event outcome and return
- double event_sample_value = GenerateSampleValue();
- return (double) (event_sample_value > probability_list_[prob_index] ? 1 : 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement