def log_current_conditional_probability(self): assert(self.current_value > 0) shape = Node.parent_node_value(self.shape) scale = Node.parent_node_value(self.scale) p = stats.invgamma.pdf(self.current_value, a=shape, scale=scale) log_p = (0 if p == 0 else math.log(p)) _log.debug("p({}={}) = {}".format(self.display_name, self.current_value, p)) return log_p
def log_current_conditional_probability(self): assert(self.current_value > 0) alpha = Node.parent_node_value(self.alpha) beta = Node.parent_node_value(self.beta) p = stats.beta.pdf(self.current_value, a=alpha, b=beta) log_p = (0 if p == 0 else math.log(p)) _log.debug("p({}={}) = {}".format(self.display_name, self.current_value, p)) return log_p
def log_current_conditional_probability(self): """ Return probability given current values of 'mean' and 'var'. (If 'mean' and 'var' are parent nodes, get their current_value.) """ mean = Node.parent_node_value(self.mean) var = Node.parent_node_value(self.var) p = stats.norm.pdf(self.current_value, mean, math.sqrt(var)) _log.debug(" p = {}".format(p)) log_p = (0 if p == 0 else math.log(p)) _log.debug("p({}={}) = {}".format(self.display_name, self.current_value, p)) return log_p
def log_current_conditional_probability(self): assert(self.current_value > 0) rate = Node.parent_node_value(self.rate) p = stats.poisson.pmf(self.current_value, mu=rate) log_p = (0 if p == 0 else math.log(p)) _log.debug("p({}={}) = {}".format(self.display_name, self.current_value, p)) return log_p
def log_current_conditional_probability(self): """ For Bernoulli/Binomial, sample directly instead of trying to use Metropolis. """ p = Node.parent_node_value(self.p) sample = 1 if random.random() <= p else 0 log_sample = (0 if sample == 0 else math.log(sample)) _log.debug("p({}={}) = {}".format(self.display_name, self.current_value, sample)) return log_sample