Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 22 additions & 0 deletions pymc3/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to round?

Also, what do you think about returning a pd.DataFrame with columns log-probability and test_point?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not think that displaying logps to high precision was helpful, particularly since we are mostly looking for nans.

The DF is a good idea! Let me try and do that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the problem with this is that the test_point for some variables is vector-valued, so it would not comport well to being displayed in a DataFrame cell.

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):
Expand Down