Skip to content

Commit 82d9148

Browse files
michaelosthegeaseyboldt
authored andcommitted
PyMC rename, API and typo fixes
1 parent 1597ae4 commit 82d9148

File tree

6 files changed

+92
-90
lines changed

6 files changed

+92
-90
lines changed

README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ functions using symbolic differentiation and common subexpression elimination.
1313
In either case the functions are compiled using numba and the resulting
1414
C-function is passed to sunode, so that there is no python overhead.
1515

16-
sunode comes with a theano wrapper so that parameters of an ode can be estimated
17-
using pymc3.
16+
`sunode` comes with an Aesara wrapper so that parameters of an ODE can be estimated
17+
using PyMC.
1818

1919
### Installation
2020
sunode is available on conda-forge. Set up a conda environment to use conda-forge
@@ -28,8 +28,8 @@ conda config --set channel_priority strict
2828
conda install sunode
2929
```
3030

31-
You can also install the development version. One windows you have to make
32-
sure the correct visual studio version is install and in the PATH.
31+
You can also install the development version. On Windows you have to make
32+
sure the correct Visual Studio version is installed and in the PATH.
3333
```
3434
git clone [email protected]:aseyboldt/sunode
3535
# Or if no ssh key is configured:
@@ -40,7 +40,7 @@ conda install --only-deps sunode
4040
pip install -e .
4141
```
4242

43-
### Solve an ode outside of a pymc3 model
43+
### Solve an ODE outside a PyMC model
4444

4545
We will use the Lotka-Volterra equations as an example ODE:
4646

@@ -118,22 +118,22 @@ plt.plot(output.view(problem.state_dtype)['hares']
118118
```
119119

120120
For this example the BDF solver (which isn't the best solver for a small non-stiff
121-
example problem like this) takes ~200μs, while the scipy.integrate.solve_ivp solver
122-
take about 40ms at a tolerance of 1e-10, 1e-10. So we are faster by a factor of 200.
121+
example problem like this) takes ~200μs, while the `scipy.integrate.solve_ivp` solver
122+
takes about 40ms at a tolerance of 1e-10, 1e-10. So we are faster by a factor of 200.
123123
This advantage will get somewhat smaller for large problems however, when the
124-
python overhead of the ODE solver has a smaller impact.
124+
Python overhead of the ODE solver has a smaller impact.
125125

126-
### Usage in pymc3
126+
### Usage in PyMC
127127

128-
Let's use the same ODE, but fit the parameters using pymc3, and gradients
129-
computed using sunode.
128+
Let's use the same ODE, but fit the parameters using PyMC, and gradients
129+
computed using `sunode`.
130130

131131
We'll use some time artificial data:
132132
```python
133133
import numpy as np
134134
import sunode
135135
import sunode.wrappers.as_aesara
136-
import pymc3 as pm
136+
import pymc as pm
137137

138138
times = np.arange(1900,1921,1)
139139
lynx_data = np.array([
@@ -164,18 +164,18 @@ def lotka_volterra(t, y, p):
164164

165165

166166
with pm.Model() as model:
167-
hares_start = pm.HalfNormal('hares_start', sd=50)
168-
lynx_start = pm.HalfNormal('lynx_start', sd=50)
167+
hares_start = pm.HalfNormal('hares_start', sigma=50)
168+
lynx_start = pm.HalfNormal('lynx_start', sigma=50)
169169

170170
ratio = pm.Beta('ratio', alpha=0.5, beta=0.5)
171171

172-
fixed_hares = pm.HalfNormal('fixed_hares', sd=50)
172+
fixed_hares = pm.HalfNormal('fixed_hares', sigma=50)
173173
fixed_lynx = pm.Deterministic('fixed_lynx', ratio * fixed_hares)
174174

175-
period = pm.Gamma('period', mu=10, sd=1)
175+
period = pm.Gamma('period', mu=10, sigma=1)
176176
freq = pm.Deterministic('freq', 2 * np.pi / period)
177177

178-
log_speed_ratio = pm.Normal('log_speed_ratio', mu=0, sd=0.1)
178+
log_speed_ratio = pm.Normal('log_speed_ratio', mu=0, sigma=0.1)
179179
speed_ratio = np.exp(log_speed_ratio)
180180

181181
# Compute the parameters of the ode based on our prior parameters
@@ -217,18 +217,18 @@ with pm.Model() as model:
217217
pm.Deterministic('lynx_mu', y_hat['lynx'])
218218

219219
sd = pm.HalfNormal('sd')
220-
pm.Lognormal('hares', mu=y_hat['hares'], sd=sd, observed=hare_data)
221-
pm.Lognormal('lynx', mu=y_hat['lynx'], sd=sd, observed=lynx_data)
220+
pm.LogNormal('hares', mu=y_hat['hares'], sigma=sd, observed=hare_data)
221+
pm.LogNormal('lynx', mu=y_hat['lynx'], sigma=sd, observed=lynx_data)
222222
```
223223

224-
We can sample using pymc3 (You need `cores=1` on windows for the moment):
224+
We can sample using PyMC (You need `cores=1` on Windows for the moment):
225225
```
226226
with model:
227-
trace = pm.sample(tune=1000, draws=1000, chains=6, cores=6)
227+
idata = pm.sample(tune=1000, draws=1000, chains=6, cores=6)
228228
```
229229

230230
Many solver options can not be specified with a nice interface for now,
231-
we can call the raw sundials functions howeve:
231+
we can call the raw sundials functions however:
232232

233233
```
234234
lib = sunode._cvodes.lib

doc/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ through AST manipulation for necessary functions and compile them using numba.
2727
This allows us to solve an ode repeatetly with almost no python overhead.
2828

2929
The original use-case for this library was better support for solving ODEs
30-
within bayesian models in PyMC3, but is useable in different contexts as well.
30+
within bayesian models in PyMC, but is useable in different contexts as well.
3131

3232
Contents
3333
--------

doc/source/quickstart_pymc.rst

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
.. _quickstart_pymc3:
1+
.. _quickstart_pymc:
22

3-
Quickstart with PyMC3
4-
=====================
3+
Quickstart with PyMC
4+
====================
55

66
sunode is available on conda-forge. You can setup an environmet to use conda-forge
77
package if you don't have that already, and install sunode:::
@@ -30,7 +30,7 @@ Sampling Bayesian models with Hamiltonian MCMC involving an ODE is where the
3030
features of sunode shine. We need to solve the ODE (ofter rather small ODEs) a
3131
large number of times, so Python overhead will hurt us a lot, and we need to
3232
compute gradients as well. Sunode provides some utility functions that make it
33-
easy to include an ODE into a PyMC3 model. If you want to use it in a
33+
easy to include an ODE into a PyMC model. If you want to use it in a
3434
different context, see :ref:`usage-basic`.
3535
We will use the Lotka-Volterra equations as example:
3636

@@ -43,7 +43,7 @@ We'll use some time artificial data:::
4343
import numpy as np
4444
import sunode
4545
import sunode.wrappers.as_aesara
46-
import pymc3 as pm
46+
import pymc as pm
4747

4848
times = np.arange(1900,1921,1)
4949
lynx_data = np.array([
@@ -72,25 +72,25 @@ We also define a function for the right-hand-side of the ODE:::
7272

7373
For more details about how this function behaves, see :ref:`rhs-function`.
7474

75-
In the next step we define priors for our parameters in PyMC3. To illustrate
76-
that the parameters do not have to be PyMC3 variables themselves, but can also
75+
In the next step we define priors for our parameters in PyMC. To illustrate
76+
that the parameters do not have to be PyMC variables themselves, but can also
7777
be derived though some computations, we put priors not on :math:`\alpha, \beta,
7878
\gamma` and :math:`\delta`, but on parameters like the frequency of the
7979
hare-lynx cycle and the steady-state ratio of hares to lynxes.::
8080

8181
with pm.Model() as model:
82-
hares_start = pm.HalfNormal('hares_start', sd=50)
83-
lynx_start = pm.HalfNormal('lynx_start', sd=50)
82+
hares_start = pm.HalfNormal('hares_start', sigma=50)
83+
lynx_start = pm.HalfNormal('lynx_start', sigma=50)
8484

8585
ratio = pm.Beta('ratio', alpha=0.5, beta=0.5)
8686

87-
fixed_hares = pm.HalfNormal('fixed_hares', sd=50)
87+
fixed_hares = pm.HalfNormal('fixed_hares', sigma=50)
8888
fixed_lynx = pm.Deterministic('fixed_lynx', ratio * fixed_hares)
8989

90-
period = pm.Gamma('period', mu=10, sd=1)
90+
period = pm.Gamma('period', mu=10, sigma=1)
9191
freq = pm.Deterministic('freq', 2 * np.pi / period)
9292

93-
log_speed_ratio = pm.Normal('log_speed_ratio', mu=0, sd=0.1)
93+
log_speed_ratio = pm.Normal('log_speed_ratio', mu=0, sigma=0.1)
9494
speed_ratio = np.exp(log_speed_ratio)
9595

9696
# Compute the parameters of the ode based on our prior parameters
@@ -143,10 +143,10 @@ We are only missing the likelihood now::
143143
pm.Deterministic('lynxes_mu', solution['lynxes'])
144144

145145
sd = pm.HalfNormal('sd')
146-
pm.Lognormal('hares', mu=solution['hares'], sd=sd, observed=hare_data)
147-
pm.Lognormal('lynxes', mu=solution['lynxes'], sd=sd, observed=lynx_data)
146+
pm.LogNormal('hares', mu=solution['hares'], sigma=sd, observed=hare_data)
147+
pm.LogNormal('lynxes', mu=solution['lynxes'], sigma=sd, observed=lynx_data)
148148

149-
We can sample from the posterior with the gradient-based PyMC3 samplers:::
149+
We can sample from the posterior with the gradient-based PyMC samplers:::
150150

151151
with model:
152152
trace = pm.sample()
@@ -161,3 +161,4 @@ This is the default on Linux, but on Mac it has to be specified manually::
161161

162162
Windows does not support this at all. You can however disable parallel sampling
163163
by setting ``cores=1`` in ``pm.sample()``.
164+
diff --git a/doc/source/quickstart_pymc3.rst b/doc/source/quickstart_pymc3.rst

doc/source/without_pymc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ current number, and die when eaten by a lynx. We get:
1212
.. math::
1313
\frac{dH}{dt} = \alpha H - \beta LH \\ \frac{dL}{dt} = \delta LH - \gamma L
1414
15-
If we want to solve this ODE without the support of theano or PyMC3, we need to
15+
If we want to solve this ODE without the support of Aesara or PyMC, we need to
1616
first declare the parameters and states we are using. We have four parameters
1717
and two states, and each one is a scalar values, so it has shape ()::
1818

0 commit comments

Comments
 (0)