Skip to content

Refactor Factor properties #5320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 0 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
--ignore=pymc/tests/test_updates.py
--ignore=pymc/tests/test_gp.py
--ignore=pymc/tests/test_model.py
--ignore=pymc/tests/test_model_func.py
--ignore=pymc/tests/test_ode.py
--ignore=pymc/tests/test_posdef_sym.py
--ignore=pymc/tests/test_quadpotential.py
Expand Down Expand Up @@ -82,7 +81,6 @@ jobs:
pymc/tests/test_distributions_timeseries.py
pymc/tests/test_gp.py
pymc/tests/test_model.py
pymc/tests/test_model_func.py
pymc/tests/test_model_graph.py
pymc/tests/test_ode.py
pymc/tests/test_posdef_sym.py
Expand Down Expand Up @@ -166,7 +164,6 @@ jobs:
pymc/tests/test_ode.py
- |
pymc/tests/test_model.py
pymc/tests/test_model_func.py
pymc/tests/test_modelcontext.py
pymc/tests/test_model_graph.py
pymc/tests/test_pickling.py
Expand Down
6 changes: 5 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ All of the above apply to:
- `pm.sample_prior_predictive`, `pm.sample_posterior_predictive` and `pm.sample_posterior_predictive_w` now return an `InferenceData` object by default, instead of a dictionary (see [#5073](https://github.com/pymc-devs/pymc/pull/5073)).
- `pm.sample_prior_predictive` no longer returns transformed variable values by default. Pass them by name in `var_names` if you want to obtain these draws (see [4769](https://github.com/pymc-devs/pymc/pull/4769)).
- `pm.sample(trace=...)` no longer accepts `MultiTrace` or `len(.) > 0` traces ([see 5019#](https://github.com/pymc-devs/pymc/pull/5019)).
- `logpt`, `logpt_sum`, `logp_elemwiset` and `nojac` variations were removed. Use `Model.logpt(jacobian=True/False, sum=True/False)` instead.
- `dlogp_nojact` and `d2logp_nojact` were removed. Use `Model.dlogpt` and `d2logpt` with `jacobian=False` instead.
- `logp`, `dlogp`, and `d2logp` and `nojac` variations were removed. Use `Model.compile_logp`, `compile_dlgop` and `compile_d2logp` with `jacobian` keyword instead.
- `model.makefn` is now called `Model.compile_fn`, and `model.fn` was removed.
- Methods starting with `fast_*`, such as `Model.fast_logp`, were removed. Same applies to `PointFunc` classes
- The GLM submodule was removed, please use [Bambi](https://bambinos.github.io/bambi/) instead.
- `pm.Bound` interface no longer accepts a callable class as argument, instead it requires an instantiated distribution (created via the `.dist()` API) to be passed as an argument. In addition, Bound no longer returns a class instance but works as a normal PyMC distribution. Finally, it is no longer possible to do predictive random sampling from Bounded variables. Please, consult the new documentation for details on how to use Bounded variables (see [4815](https://github.com/pymc-devs/pymc/pull/4815)).
- `pm.logpt(transformed=...)` kwarg was removed (816b5f).
- `Model(model=...)` kwarg was removed
- `Model(theano_config=...)` kwarg was removed
- `Model.size` property was removed (use `Model.ndim` instead).
Expand Down
18 changes: 16 additions & 2 deletions pymc/backends/arviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,26 @@ def _extract_log_likelihood(self, trace):
# TODO: We no longer need one function per observed variable
if self.log_likelihood is True:
cached = [
(var, self.model.fn(self.model.logp_elemwiset(var)[0]))
(
var,
self.model.compile_fn(
self.model.logpt(var, sum=False)[0],
inputs=self.model.value_vars,
on_unused_input="ignore",
),
)
for var in self.model.observed_RVs
]
else:
cached = [
(var, self.model.fn(self.model.logp_elemwiset(var)[0]))
(
var,
self.model.compile_fn(
self.model.logpt(var, sum=False)[0],
inputs=self.model.value_vars,
on_unused_input="ignore",
),
)
for var in self.model.observed_RVs
if var.name in self.log_likelihood
]
Expand Down
2 changes: 1 addition & 1 deletion pymc/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, name, model=None, vars=None, test_point=None):

self.vars = vars
self.varnames = [var.name for var in vars]
self.fn = model.fastfn(vars)
self.fn = model.compile_fn(vars, inputs=model.value_vars, on_unused_input="ignore")

# Get variable shapes. Most backends will need this
# information.
Expand Down
6 changes: 2 additions & 4 deletions pymc/distributions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
logcdf,
logp,
logp_transform,
logpt,
logpt_sum,
joint_logpt,
)

from pymc.distributions.bound import Bound
Expand Down Expand Up @@ -191,9 +190,8 @@
"Censored",
"CAR",
"PolyaGamma",
"logpt",
"joint_logpt",
"logp",
"logp_transform",
"logcdf",
"logpt_sum",
]
17 changes: 1 addition & 16 deletions pymc/distributions/logprob.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings

from collections.abc import Mapping
from functools import singledispatch
Expand Down Expand Up @@ -118,7 +117,7 @@ def _get_scaling(total_size, shape, ndim):
)


def logpt(
def joint_logpt(
var: Union[TensorVariable, List[TensorVariable]],
rv_values: Optional[Union[TensorVariable, Dict[TensorVariable, TensorVariable]]] = None,
*,
Expand Down Expand Up @@ -264,17 +263,3 @@ def logcdf(rv, value):

value = at.as_tensor_variable(value, dtype=rv.dtype)
return logcdf_aeppl(rv, value)


def logpt_sum(*args, **kwargs):
"""Return the sum of the logp values for the given observations.

Subclasses can use this to improve the speed of logp evaluations
if only the sum of the logp values is needed.
"""
warnings.warn(
"logpt_sum has been deprecated, you can use logpt instead, which now defaults"
"to the same behavior of logpt_sum",
DeprecationWarning,
)
return logpt(*args, sum=True, **kwargs)
Loading