Skip to content

Commit

Permalink
Adding support for Discrete distribution for max logprob
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruvanshu-Joshi committed Aug 6, 2023
1 parent 813166a commit 57d0ac2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 24 deletions.
21 changes: 0 additions & 21 deletions pymc/logprob/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,17 @@ def find_measurable_max(fgraph: FunctionGraph, node: Node) -> Optional[List[Tens
if not (isinstance(base_var.owner.op, RandomVariable) and base_var.owner.op.ndim_supp == 0):
return None

<<<<<<< HEAD
# TODO: We are currently only supporting continuous rvs
if isinstance(base_var.owner.op, RandomVariable) and base_var.owner.op.dtype.startswith("int"):
return None

# univariate i.i.d. test which also rules out other distributions
for params in base_var.owner.inputs[3:]:
if params.type.ndim != 0:
return None

=======
# univariate i.i.d. test which also rules out other distributions
for params in base_var.owner.inputs[3:]:
if params.type.ndim != 0:
return None

>>>>>>> Adding support for Discrete distribution for max logprob
# Check whether axis covers all dimensions
axis = set(node.op.axis)
base_var_dims = set(range(base_var.ndim))
if axis != base_var_dims:
return None

<<<<<<< HEAD
measurable_max = MeasurableMax(list(axis))
max_rv_node = measurable_max.make_node(base_var)
max_rv = max_rv_node.outputs
=======
# logprob for discrete distribution
if isinstance(base_var.owner.op, RandomVariable) and base_var.owner.op.dtype.startswith("int"):
measurable_max = MeasurableMaxDiscrete(list(axis))
Expand All @@ -130,7 +113,6 @@ def find_measurable_max(fgraph: FunctionGraph, node: Node) -> Optional[List[Tens
measurable_max = MeasurableMax(list(axis))
max_rv_node = measurable_max.make_node(base_var)
max_rv = max_rv_node.outputs

Check warning on line 115 in pymc/logprob/order.py

View check run for this annotation

Codecov / codecov/patch

pymc/logprob/order.py#L113-L115

Added lines #L113 - L115 were not covered by tests
>>>>>>> Adding support for Discrete distribution for max logprob

return max_rv

Check warning on line 117 in pymc/logprob/order.py

View check run for this annotation

Codecov / codecov/patch

pymc/logprob/order.py#L117

Added line #L117 was not covered by tests

Expand All @@ -156,8 +138,6 @@ def max_logprob(op, values, base_rv, **kwargs):
logprob = (n - 1) * logcdf + logprob + pt.math.log(n)

return logprob
<<<<<<< HEAD
=======


@_logprob.register(MeasurableMaxDiscrete)
Expand All @@ -178,4 +158,3 @@ def max_logprob_discrete(op, values, base_rv, **kwargs):
logprob = pt.log((pt.exp(logcdf)) ** n - (pt.exp(logcdf_prev)) ** n)

Check warning on line 158 in pymc/logprob/order.py

View check run for this annotation

Codecov / codecov/patch

pymc/logprob/order.py#L158

Added line #L158 was not covered by tests

return logprob

Check warning on line 160 in pymc/logprob/order.py

View check run for this annotation

Codecov / codecov/patch

pymc/logprob/order.py#L160

Added line #L160 was not covered by tests
>>>>>>> Adding support for Discrete distribution for max logprob
3 changes: 0 additions & 3 deletions tests/logprob/test_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ def test_max_logprob(shape, value, axis):
(x_max_logprob.eval({x_max_value: test_value})),
rtol=1e-06,
)
<<<<<<< HEAD
=======


def test_max_discrete():
Expand All @@ -159,4 +157,3 @@ def test_max_discrete():
x_max_logprob = logp(x_max, x_max_value)

x_max_logprob.eval({x_max_value: 0.85})
>>>>>>> Adding support for Discrete distribution for max logprob

0 comments on commit 57d0ac2

Please sign in to comment.