;-------------------------------------------------------------------------------------------- ; compute naive Bayesian Terms ; ; input: ; count_yes_all - total number of yes ; count_no_all - total number of yes ; count_yes_bin - total number of yes within this bin ; count_no_bin - total number of no within this bin ; max_r - maximum allowed value of r ; prior_yes - prior probability of a yes ; ; output ; cond_yes = class conditional for yes ; cond_no = class conditional for no ; r - cond_no / cond_yes ; post_prob = posterior probability ; ;-------------------------------------------------------------------------------------------- pro compute_class_cond, nb_rank, laplace_flag, $ count_yes_all, count_no_all, $ count_yes_bin, count_no_bin, $ max_r, prior_yes, cond_yes, cond_no, r, post_prob r = 1.0 post_prob = prior_yes count_yes_bin = count_yes_bin + laplace_flag count_yes_all = count_yes_all + nb_rank * laplace_flag cond_yes = 0.0 if (count_yes_all gt 0) then begin cond_yes = float(count_yes_bin)/float(count_yes_all) endif cond_no = 0.0 if (count_no_all gt 0) then begin cond_no = float(count_no_bin)/float(count_no_all) endif ;print, 'yes = ', count_yes_all, count_yes_bin, cond_yes ;print, 'no = ', count_no_all, count_no_bin, cond_no if (cond_yes gt 0.0) then begin r = cond_no / cond_yes endif else begin r = max_r endelse post_prob = 1.0 / ( 1.0 + r/prior_yes - r) post_prob = min([1.0,max([0.0,post_prob])]) end