Skip to content

Implemented logprob for SpecifyShape and CheckandRaise #6538

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 201 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
201 commits
Select commit Hold shift + click to select a range
379b1e9
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
5329794
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
949032a
Fix SpecifyShape
ricardoV94 Mar 6, 2023
53e0f98
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
6a49bed
Resolved errors
Dhruvanshu-Joshi Mar 17, 2023
814efef
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
9caf789
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
0e3c9c1
Fix SpecifyShape
ricardoV94 Mar 6, 2023
9d0041f
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
e54c01d
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
f17a408
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
1db882c
Fix SpecifyShape
ricardoV94 Mar 6, 2023
9e1c429
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
e21b6cd
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
ff2b76a
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
b56c345
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
740da4c
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
55fb450
Fix SpecifyShape
ricardoV94 Mar 6, 2023
48c3710
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
cc1ed51
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
03b609f
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
a8cdee8
Fix SpecifyShape
ricardoV94 Mar 6, 2023
dca066b
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
b0f34dd
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
5824bb7
Combined the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
eede32f
Updated the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
f03a7e5
Updated and rectified the checks in logprob and the corresponding tes…
Dhruvanshu-Joshi Mar 20, 2023
d2d1c3e
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
93f9f77
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
b0efee0
Fix SpecifyShape
ricardoV94 Mar 6, 2023
b679248
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
6144396
Resolved errors
Dhruvanshu-Joshi Mar 17, 2023
24d0426
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
20125f8
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
affbd51
Fix SpecifyShape
ricardoV94 Mar 6, 2023
66e7099
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
fbe4f84
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
0e9507e
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
05cd98e
Fix SpecifyShape
ricardoV94 Mar 6, 2023
c018416
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
885cd62
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
c070723
Combined the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
8b5d00f
Updated class name
Dhruvanshu-Joshi Mar 24, 2023
38d14cb
Updated class name
Dhruvanshu-Joshi Mar 24, 2023
d74a067
Solving merge conflicts
Dhruvanshu-Joshi Mar 24, 2023
e88f823
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
dd54d46
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
5c39620
Fix SpecifyShape
ricardoV94 Mar 6, 2023
5a92248
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
06688bd
Resolved errors
Dhruvanshu-Joshi Mar 17, 2023
6791067
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
eb1c4cf
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
1b51a75
Fix SpecifyShape
ricardoV94 Mar 6, 2023
8ebfa7e
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
f349459
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
ba245d2
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
1264916
Fix SpecifyShape
ricardoV94 Mar 6, 2023
d4773cc
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
1419418
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
aea4516
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
878205b
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
ce7d5e1
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
1e1efbf
Fix SpecifyShape
ricardoV94 Mar 6, 2023
556a06a
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
ad314b1
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
e70810f
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
b28a00f
Fix SpecifyShape
ricardoV94 Mar 6, 2023
c11a8f8
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
229f61b
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
3659a5e
Combined the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
3de287f
Updated the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
07c844d
Updated and rectified the checks in logprob and the corresponding tes…
Dhruvanshu-Joshi Mar 20, 2023
20839be
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
6609ed4
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
5f0ca26
Fix SpecifyShape
ricardoV94 Mar 6, 2023
57df1a9
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
15c1403
Resolved errors
Dhruvanshu-Joshi Mar 17, 2023
1294ae8
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
d9bde80
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
4368145
Fix SpecifyShape
ricardoV94 Mar 6, 2023
0ffd52e
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
6a303a5
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
7e46130
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
c97d5ec
Fix SpecifyShape
ricardoV94 Mar 6, 2023
3410188
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
36c657f
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
e348300
Combined the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
5eddea8
Solving all merge conflicts
Dhruvanshu-Joshi Mar 24, 2023
25478a5
Reducing code redundancy
Dhruvanshu-Joshi Mar 25, 2023
546e1c0
Reducing code redundancy
Dhruvanshu-Joshi Mar 25, 2023
087b00d
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
8551fd5
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
8464cc1
Fix SpecifyShape
ricardoV94 Mar 6, 2023
1876001
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
7cab395
Resolved errors
Dhruvanshu-Joshi Mar 17, 2023
23a74fb
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
82cc153
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
d50137d
Fix SpecifyShape
ricardoV94 Mar 6, 2023
e2e2cb8
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
89305dc
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
a0b722c
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
f878cda
Fix SpecifyShape
ricardoV94 Mar 6, 2023
41f3175
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
59940d7
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
bc4110b
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
4d12c16
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
f2f109e
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
21d1f9b
Fix SpecifyShape
ricardoV94 Mar 6, 2023
430f81c
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
67c32a7
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
94edd31
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
5fe9c37
Fix SpecifyShape
ricardoV94 Mar 6, 2023
bc8b6df
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
9652d99
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
245b678
Combined the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
8732720
Updated the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
bb15eec
Updated and rectified the checks in logprob and the corresponding tes…
Dhruvanshu-Joshi Mar 20, 2023
1d5bf00
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
96ddacf
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
d676945
Fix SpecifyShape
ricardoV94 Mar 6, 2023
ff6ec56
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
cea9840
Resolved errors
Dhruvanshu-Joshi Mar 17, 2023
79c2856
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
5b1ebe0
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
9008c09
Fix SpecifyShape
ricardoV94 Mar 6, 2023
72c63ab
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
d7cc4f6
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
b0ac4cf
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
444c285
Fix SpecifyShape
ricardoV94 Mar 6, 2023
06e23cc
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
ee146f0
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
c08b819
Combined the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
7dd588b
Solving numerous commits issue
Dhruvanshu-Joshi Mar 29, 2023
ad6ec33
Updated the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
0f5d05b
Updated and rectified the checks in logprob and the corresponding tes…
Dhruvanshu-Joshi Mar 20, 2023
5f0aa4c
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
63af1b4
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
413a09a
Fix SpecifyShape
ricardoV94 Mar 6, 2023
f2c15f0
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
4642e46
Resolved errors
Dhruvanshu-Joshi Mar 17, 2023
9034fde
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
291e25c
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
c1d0e97
Fix SpecifyShape
ricardoV94 Mar 6, 2023
ffed617
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
4fe6f6d
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
c9d4d1a
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
fdf6322
Fix SpecifyShape
ricardoV94 Mar 6, 2023
53d22d4
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
a2a40cf
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
1dd12a7
Combined the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
a38b519
Updated class name
Dhruvanshu-Joshi Mar 24, 2023
216adba
Solving merge conflicts
Dhruvanshu-Joshi Mar 24, 2023
3f4463f
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
f67c36a
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
b391cd5
Fix SpecifyShape
ricardoV94 Mar 6, 2023
efb4777
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
e3df69d
Resolved errors
Dhruvanshu-Joshi Mar 17, 2023
247a715
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
a638aae
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
8cc3599
Fix SpecifyShape
ricardoV94 Mar 6, 2023
4473035
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
7a042c3
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
31e2137
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
09f74f3
Fix SpecifyShape
ricardoV94 Mar 6, 2023
13f98db
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
9d684bf
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
76627e9
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
b19db27
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
67eb279
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
fc78195
Fix SpecifyShape
ricardoV94 Mar 6, 2023
19bd626
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
dc78ebe
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
4680983
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
27d5961
Fix SpecifyShape
ricardoV94 Mar 6, 2023
c8fbd13
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
af54c39
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
da95c1f
Combined the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
439b772
Updated the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
1996bc1
Updated and rectified the checks in logprob and the corresponding tes…
Dhruvanshu-Joshi Mar 20, 2023
24282a5
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
6b632ac
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
0c7c3c1
Fix SpecifyShape
ricardoV94 Mar 6, 2023
d7bdbbf
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
3d2d250
Resolved errors
Dhruvanshu-Joshi Mar 17, 2023
f2b0e7d
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
56f7445
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
98b1a36
Fix SpecifyShape
ricardoV94 Mar 6, 2023
27d7a97
Tests for logprob for Specify_shape and check_raise_assert added
Dhruvanshu-Joshi Mar 11, 2023
6f27645
Added logprob for SpecifyShape and CheckandRaise
Dhruvanshu-Joshi Feb 20, 2023
0018dc0
Added logprob for SpecifyShape and CheckandRaise and removed errors
Dhruvanshu-Joshi Feb 20, 2023
7f3c82d
Fix SpecifyShape
ricardoV94 Mar 6, 2023
df5c846
Resolved errors in check_raise_assert
Dhruvanshu-Joshi Mar 17, 2023
e9b0928
Resolved pre-commit error
Dhruvanshu-Joshi Mar 17, 2023
dd8aee6
Combined the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
7f6884b
Solving all merge conflicts
Dhruvanshu-Joshi Mar 24, 2023
0e96cec
Reducing code redundancy
Dhruvanshu-Joshi Mar 25, 2023
a240b55
Reducing code redundancy
Dhruvanshu-Joshi Mar 25, 2023
7647bd3
Updated the checks in logprob and the corresponding tests suites
Dhruvanshu-Joshi Mar 20, 2023
86ca5cb
Updated and rectified the checks in logprob and the corresponding tes…
Dhruvanshu-Joshi Mar 20, 2023
e97b6de
Rectified test suites
Dhruvanshu-Joshi Mar 29, 2023
54eb767
update code for checks to replace logprob with_logprob_helper
Dhruvanshu-Joshi Mar 29, 2023
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
1 change: 1 addition & 0 deletions pymc/logprob/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# Add rewrites to the DBs
import pymc.logprob.censoring
import pymc.logprob.cumsum
import pymc.logprob.checks
import pymc.logprob.mixture
import pymc.logprob.scan
import pymc.logprob.tensor
Expand Down
158 changes: 158 additions & 0 deletions pymc/logprob/checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Copyright 2023 The PyMC Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#
# MIT License
#
# Copyright (c) 2021-2022 aesara-devs
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from typing import List, Optional

import pytensor.tensor as pt

from pytensor.graph.rewriting.basic import node_rewriter
from pytensor.raise_op import CheckAndRaise, ExceptionType
from pytensor.tensor.shape import SpecifyShape

from pymc.logprob.abstract import MeasurableVariable, _logprob, _logprob_helper
from pymc.logprob.rewriting import PreserveRVMappings, measurable_ir_rewrites_db
from pymc.logprob.utils import ignore_logprob


class MeasurableSpecifyShape(SpecifyShape):
"""A placeholder used to specify a log-likelihood for a specify-shape sub-graph."""


MeasurableVariable.register(MeasurableSpecifyShape)


@_logprob.register(MeasurableSpecifyShape)
def logprob_specify_shape(op, values, inner_rv, *shapes, **kwargs):
(value,) = values
# transfer specify_shape from rv to value
value = pt.specify_shape(value, shapes)
return _logprob_helper(inner_rv, value)


@node_rewriter([SpecifyShape])
def find_measurable_specify_shapes(fgraph, node) -> Optional[List[MeasurableSpecifyShape]]:
r"""Finds `SpecifyShapeOp`\s for which a `logprob` can be computed."""

if isinstance(node.op, MeasurableSpecifyShape):
return None # pragma: no cover

rv_map_feature: Optional[PreserveRVMappings] = getattr(fgraph, "preserve_rv_mappings", None)

if rv_map_feature is None:
return None # pragma: no cover

rv = node.outputs[0]

base_rv, *shape = node.inputs

if not (
base_rv.owner
and isinstance(base_rv.owner.op, MeasurableVariable)
and base_rv not in rv_map_feature.rv_values
):
return None # pragma: no cover

new_op = MeasurableSpecifyShape()
# Make base_var unmeasurable
unmeasurable_base_rv = ignore_logprob(base_rv)
new_rv = new_op.make_node(unmeasurable_base_rv, *shape).default_output()
new_rv.name = rv.name

return [new_rv]


measurable_ir_rewrites_db.register(
"find_measurable_specify_shapes",
find_measurable_specify_shapes,
"basic",
"specify_shape",
)


class MeasurableCheckAndRaise(CheckAndRaise):
"""A placeholder used to specify a log-likelihood for an assert sub-graph."""


MeasurableVariable.register(MeasurableCheckAndRaise)


@_logprob.register(MeasurableCheckAndRaise)
def logprob_assert(op, values, inner_rv, *assertion, **kwargs):
(value,) = values
# transfer assertion from rv to value
value = op(assertion, value)
return _logprob_helper(inner_rv, value)


@node_rewriter([CheckAndRaise])
def find_measurable_asserts(fgraph, node) -> Optional[List[MeasurableCheckAndRaise]]:
r"""Finds `AssertOp`\s for which a `logprob` can be computed."""

if isinstance(node.op, MeasurableCheckAndRaise):
return None # pragma: no cover

rv_map_feature: Optional[PreserveRVMappings] = getattr(fgraph, "preserve_rv_mappings", None)

if rv_map_feature is None:
return None # pragma: no cover

rv = node.outputs[0]

base_rv, *conds = node.inputs

if not (
base_rv.owner
and isinstance(base_rv.owner.op, MeasurableVariable)
and base_rv not in rv_map_feature.rv_values
):
return None # pragma: no cover

exception_type = ExceptionType()
new_op = MeasurableCheckAndRaise(exc_type=exception_type)
# Make base_var unmeasurable
unmeasurable_base_rv = ignore_logprob(base_rv)
new_rv = new_op.make_node(unmeasurable_base_rv, *conds).default_output()
new_rv.name = rv.name

return [new_rv]


measurable_ir_rewrites_db.register(
"find_measurable_asserts",
find_measurable_asserts,
"basic",
"assert",
)
98 changes: 98 additions & 0 deletions tests/logprob/test_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2023 The PyMC Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#
# MIT License
#
# Copyright (c) 2021-2022 aesara-devs
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import numpy as np
import pytensor
import pytensor.tensor as pt
import pytest

from pytensor.raise_op import Assert
from scipy import stats

from pymc.distributions import Dirichlet
from pymc.logprob.joint_logprob import factorized_joint_logprob
from tests.distributions.test_multivariate import dirichlet_logpdf


def test_specify_shape_logprob():
# 1. Create graph using SpecifyShape
# Use symbolic last dimension, so that SpecifyShape is not useless
last_dim = pt.scalar(name="last_dim", dtype="int64")
x_base = Dirichlet.dist(pt.ones((last_dim,)), shape=(5, last_dim))
x_base.name = "x"
x_rv = pt.specify_shape(x_base, shape=(5, 3))
x_rv.name = "x"

# 2. Request logp
x_vv = x_rv.clone()
[x_logp] = factorized_joint_logprob({x_rv: x_vv}).values()

# 3. Test logp
x_logp_fn = pytensor.function([last_dim, x_vv], x_logp)

# 3.1 Test valid logp
x_vv_test = stats.dirichlet(np.ones((3,))).rvs(size=(5,))
np.testing.assert_array_almost_equal(
x_logp_fn(last_dim=3, x=x_vv_test),
dirichlet_logpdf(x_vv_test, np.ones((3,))),
)

# 3.2 Test shape error
x_vv_test_invalid = stats.dirichlet(np.ones((1,))).rvs(size=(5,))
with pytest.raises(TypeError, match=re.escape("not compatible with the data's ((5, 1))")):
x_logp_fn(last_dim=1, x=x_vv_test_invalid)


def test_assert_logprob():
rv = pt.random.normal()
assert_op = Assert("Test assert")
# Example: Add assert that rv must be positive
assert_rv = assert_op(rv > 0, rv)
assert_rv.name = "assert_rv"

assert_vv = assert_rv.clone()
assert_logp = factorized_joint_logprob({assert_rv: assert_vv})[assert_vv]

# Check valid value is correct and doesn't raise
# Since here the value to the rv satisfies the condition, no error is raised.
valid_value = 3.0
with pytest.raises(AssertionError, match="Test assert"):
assert_logp.eval({assert_vv: valid_value})

# Check invalid value
# Since here the value to the rv is negative, an exception is raised as the condition is not met
with pytest.raises(AssertionError, match="Test assert"):
assert_logp.eval({assert_vv: -5.0})