Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aseyboldt committed Sep 17, 2020
2 parents 17878c4 + 5e83b93 commit f3c4082
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
9 changes: 5 additions & 4 deletions doc/source/quickstart_pymc3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ We'll use some time artificial data:::
hare_data = np.array([
30.0, 47.2, 70.2, 77.4, 36.3, 20.6, 18.1, 21.4, 22.0, 25.4,
27.1, 40.3, 57.0, 76.6, 52.3, 19.5, 11.2, 7.6, 14.6, 16.2, 24.7
])
We also define a function for the right-hand-side of the ODE:::

Expand Down Expand Up @@ -138,12 +139,12 @@ We are only missing the likelihood now::
with model:
# We can access the individual variables of the solution using the
# variable names.
pm.Deterministic('hares_mu', y_hat['hares'])
pm.Deterministic('lynx_mu', y_hat['lynx'])
pm.Deterministic('hares_mu', solution['hares'])
pm.Deterministic('lynxes_mu', solution['lynxes'])

sd = pm.HalfNormal('sd')
pm.Lognormal('hares', mu=y_hat['hares'], sd=sd, observed=hare_data)
pm.Lognormal('lynx', mu=y_hat['lynx'], sd=sd, observed=lynx_data)
pm.Lognormal('hares', mu=solution['hares'], sd=sd, observed=hare_data)
pm.Lognormal('lynxes', mu=solution['lynxes'], sd=sd, observed=lynx_data)

We can sample from the posterior with the gradient-based PyMC3 samplers:::

Expand Down
9 changes: 5 additions & 4 deletions doc/source/without_pymc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ODE might look like this::
dhares = p.alpha * hares - p.beta * lynxes * hares
dlynxes = p.delta * hares * lynxes - p.gamma * lynxes
return {
'log_hares': dhares / hares
'log_hares': dhares / hares,
'log_lynxes': dlynxes / lynxes,
}

Expand All @@ -88,7 +88,8 @@ After defining states, parameters and right-hand-side function we can create a
problem = sunode.SympyProblem(
params=params,
states=states,
rhs_sympy=lotka_volterra
rhs_sympy=lotka_volterra,
derivative_params=()
)

The problem provides structured numpy dtypes for states and parameters
Expand All @@ -106,7 +107,7 @@ This does not introduce runtime overhead.::

y0 = np.zeros((), dtype=problem.state_dtype)
y0['hares'] = 1
y0['lynx'] = 0.1
y0['lynxes'] = 0.1

# At which time points do we want to evalue the solution
tvals = np.linspace(0, 10)
Expand All @@ -127,4 +128,4 @@ We can convert the solution to an xarray Dataset or access the
individual states as numpy record array::

solver.as_xarray(tvals, output).solution_hares.plot()
plt.plot(output.view(problem.state_dtype)['hares']
plt.plot(output.view(tvals, problem.state_dtype)['hares'])
27 changes: 17 additions & 10 deletions sunode/build_cvodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,33 @@
cvodes.sort()

headers = common + linsolve + cvodes
include = []
library_dirs = []
extra_libs = []

if sys.platform == 'win32':
with open(os.path.join(base, "source_cvodes_win.c")) as fsource:
source_content = fsource.read()
include = [os.path.join(os.environ["CONDA_PREFIX"], "Library", "include")]
library_dirs = [
os.path.join(os.environ["CONDA_PREFIX"], "Library", "lib")
]
extra_libs = []
include += [os.path.join(os.environ["CONDA_PREFIX"], "Library", "include")]
library_dirs += [os.path.join(os.environ["CONDA_PREFIX"], "Library", "lib")]

# lapackdense is not supported by the windows build of sundials
for name in ['sunlinsol_lapackdense', 'sunlinsol_klu']:
headers = [fn for fn in headers if name not in fn]
else:
with open(os.path.join(base, "source_cvodes.c")) as fsource:
source_content = fsource.read()
include = [os.path.join(os.environ["CONDA_PREFIX"], "include")]
library_dirs = [os.path.join(os.environ["CONDA_PREFIX"], "lib")]
extra_libs = [
"blas",
"lapack",

#test if we can use conda libraries
if "CONDA_PREFIX" in os.environ:
include += [os.path.join(os.environ["CONDA_PREFIX"], "include")]
library_dirs += [os.path.join(os.environ["CONDA_PREFIX"], "lib")]
extra_libs += ["blas", "lapack"]
else:
include += ["/usr/include/suitesparse/"]
extra_libs.append("openblas")

extra_libs += [
"pthread",
"klu",
"sundials_sunlinsollapackdense",
Expand Down

0 comments on commit f3c4082

Please sign in to comment.