diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 1abc3e2315..b10deb2832 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -4,6 +4,10 @@ ## PyMC 3.5 (Unreleaased) +### New features + +- Add `check_test_point` method to `pm.Model` + ### Fixes - Fixed `KeyError` raised when only subset of variables are specified to be recorded in the trace. diff --git a/pymc3/model.py b/pymc3/model.py index 24e7b5d477..1f8603b4b4 100644 --- a/pymc3/model.py +++ b/pymc3/model.py @@ -5,6 +5,7 @@ import six import numpy as np +from pandas import Series import scipy.sparse as sps import theano.sparse as sparse from theano import theano, tensor as tt @@ -1000,6 +1001,27 @@ def flatten(self, vars=None, order=None, inputvar=None): flat_view = FlatView(inputvar, replacements, view) return flat_view + def check_test_point(self, test_point=None, round_vals=2): + """Checks log probability of test_point for all random variables in the model. + + Parameters + ---------- + test_point : Point + Point to be evaluated. + if None, then all model.test_point is used + round_vals : int + Number of decimals to round log-probabilities + + Returns + ------- + Pandas Series + """ + if test_point is None: + test_point = self.test_point + + return Series({RV.name:np.round(RV.logp(self.test_point), round_vals) for RV in self.basic_RVs}, + name='Log-probability of test_point') + def _repr_latex_(self, name=None, dist=None): tex_vars = [] for rv in itertools.chain(self.unobserved_RVs, self.observed_RVs):