Skip to content

Commit bad236c

Browse files
committed
Add code examples in docstrings
1 parent 1f42835 commit bad236c

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pymc/func_utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,31 @@ def find_constrained_prior(
6868
-------
6969
The optimized distribution parameters as a dictionary with the parameters'
7070
name as key and the optimized value as value.
71+
72+
Examples
73+
--------
74+
.. code-block:: python
75+
76+
# get parameters obeying constraints
77+
opt_params = pm.find_constrained_prior(
78+
pm.Gamma, lower=0.1, upper=0.4, mass=0.75, init_guess={"alpha": 1, "beta": 10}
79+
)
80+
81+
# use these parameters to draw random samples
82+
samples = pm.Gamma.dist(**opt_params, size=100).eval()
83+
84+
# use these parameters in a model
85+
with pm.Model():
86+
x = pm.Gamma('x', **opt_params)
87+
88+
# specify fixed values before optimization
89+
opt_params = pm.find_constrained_prior(
90+
pm.StudentT,
91+
lower=0,
92+
upper=1,
93+
init_guess={"mu": 5, "sigma": 2},
94+
fixed_params={"nu": 7},
95+
)
7196
"""
7297
assert 0.01 <= mass <= 0.99, (
7398
"This function optimizes the mass of the given distribution +/- "

0 commit comments

Comments
 (0)