Skip to content

Commit fc51fd3

Browse files
Chris Mannmichaelosthege
Chris Mann
authored andcommitted
Fix typos in Potential docstring
* Remove spurious minus signs from the first two code examples in the Potential function * Shorten warning about applicability of Potential only to logp-based sampling
1 parent 5603792 commit fc51fd3

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

pymc/model.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,13 +2049,7 @@ def Potential(name, var, model=None, dims=None):
20492049
20502050
Warnings
20512051
--------
2052-
Potential functions only influence logp based sampling, like the one used by ``pm.sample``.
2053-
Potentials, modify the log-probability of the model by adding a contribution to the logp which is used by sampling algorithms which rely on the information about the observed data to generate posterior samples.
2054-
Potentials are not applicable in the context of forward sampling because they don't affect the prior distribution itself, only the computation of the logp.
2055-
Forward sampling algorithms generate sample points from the prior distribution of the model, without taking into account the likelihood function.
2056-
In other words, it does not use the information about the observed data.
2057-
Hence, Potentials do not affect forward sampling, which is used by ``sample_prior_predictive`` and ``sample_posterior_predictive``.
2058-
A warning saying "The effect of Potentials on other parameters is ignored during prior predictive sampling" is always emitted to alert user of this.
2052+
Potential functions only influence logp-based sampling. Therefore, they are applicable for sampling with ``pm.sample`` but not ``pm.sample_prior_predictive`` or ``pm.sample_posterior_predictive``.
20592053
20602054
Parameters
20612055
----------
@@ -2077,7 +2071,7 @@ def Potential(name, var, model=None, dims=None):
20772071
Have a look at the following example:
20782072
20792073
In this example, we define a constraint on ``x`` to be greater or equal to 0 via the ``pm.Potential`` function.
2080-
We pass ``-pm.math.log(pm.math.switch(constraint, 1, 0))`` as second argument which will return an expression depending on if the constraint is met or not and which will be added to the likelihood of the model.
2074+
We pass ``pm.math.log(pm.math.switch(constraint, 1, 0))`` as second argument which will return an expression depending on if the constraint is met or not and which will be added to the likelihood of the model.
20812075
The probablity density that this model produces agrees strongly with the constraint that ``x`` should be greater than or equal to 0. All the cases who do not satisfy the constraint are strictly not considered.
20822076
20832077
.. code:: python
@@ -2086,9 +2080,9 @@ def Potential(name, var, model=None, dims=None):
20862080
x = pm.Normal("x", mu=0, sigma=1)
20872081
y = pm.Normal("y", mu=x, sigma=1, observed=data)
20882082
constraint = x >= 0
2089-
potential = pm.Potential("x_constraint", pm.math.log(pm.math.switch(constraint, 1, 0.0)))
2083+
potential = pm.Potential("x_constraint", pm.math.log(pm.math.switch(constraint, 1, 0)))
20902084
2091-
However, if we use ``-pm.math.log(pm.math.switch(constraint, 1, 0.5))`` the potential again penalizes the likelihood when constraint is not met but with some deviations allowed.
2085+
However, if we use ``pm.math.log(pm.math.switch(constraint, 1.0, 0.5))`` the potential again penalizes the likelihood when constraint is not met but with some deviations allowed.
20922086
Here, Potential function is used to pass a soft constraint.
20932087
A soft constraint is a constraint that is only partially satisfied.
20942088
The effect of this is that the posterior probability for the parameters decreases as they move away from the constraint, but does not become exactly zero.
@@ -2100,7 +2094,7 @@ def Potential(name, var, model=None, dims=None):
21002094
x = pm.Normal("x", mu=0.1, sigma=1)
21012095
y = pm.Normal("y", mu=x, sigma=1, observed=data)
21022096
constraint = x >= 0
2103-
potential = pm.Potential("x_constraint", pm.math.log(pm.math.switch(constraint, 1, 0.5)))
2097+
potential = pm.Potential("x_constraint", pm.math.log(pm.math.switch(constraint, 1.0, 0.5)))
21042098
21052099
In this example, Potential is used to obtain an arbitrary prior.
21062100
This prior distribution refers to the prior knowledge that the values of ``max_items`` are likely to be small rather than being large.

0 commit comments

Comments
 (0)