INNER CODE UNIT · Python
_apply_prior_callback
JohannesBuchner/nway · nwaylib/__init__.py:415
def _apply_prior_callback(table, total, prior_callback, logger):
"""
Queries the user-provided prior_callback with the match table and
ingests the returned probabilities into the total evidence, like the
magnitude priors.
"""
logger.log('Incorporating prior_callback ...')
probs = numpy.asarray(prior_callback(table), dtype=float)
assert probs.shape == (len(table),), \
'prior_callback has to return one probability per combination (received shape %s for %d rows).' % (probs.shape, len(table))
assert numpy.isfinite(probs).all() and (probs >= 0).all(), \
'prior_callback has to return finite, non-negative probabilities.'
with numpy.errstate(divide='ignore'):
log_probs = log10(probs)
# combinations with probability 0 are excluded from the matching
table = table.assign(bias_prior_callback=probs)
total = total + log_probs
return table, total