The code in this repository was created in part as experiment for creating
a computational framework combining different tools in the Python ecosystem,
namely Luigi
,
functools
's lru_cache
and multiprocessing
.
I make no apologies for any hacks or clunky design.
This code was created to ease the numerical exploration of stochastic delay differential equations. It was motivated by the need to compute statistics over large numbers of stochastic realizations.
To facilitate the calculation of empirical statistics for stochastic equations, this package provides
- Simple definition of new models with a single line of code.
- On-disk caching of system realizations.
- Parallelized generation of realizations.
- Memory-efficient statistics over large numbers of realizations: realizations are never in memory all at once, and so can be arbitrarily many.
- Cached computation of statistics to eliminate the cost of keeping realizations after the first calculation.
- Parallelized disk access to offset the disk-access cost for the initial calculations of statistics.
In addition, models can optionally be computed using Theano (see below), allowing for automatic differentiation and translation to C code.
For the most part, this package can be installed through pip
. After navigating
to the local directory to which it was cloned, the usual command
pip install -e .
will install it along with the required packages. I assume that you will want to
make changes to the code; otherwise the -e
part of the command may be omitted.
Although not necessary, we recommend installing this package within a virtual environment.
At present this code requires two packages which are yet public because they
are tied to a manuscript in preparation (these are indicated in setup.py
.)
You can obtain these by contacting me directly at alexandre (dot) rene (at) caesar (dot) de
.
By default, when running in a notebook, we use the progress bars from
tqdm_notebook
. These provide better integration with the notebook, but require
that Jupyter Widgets be installed
(instructions found here).
If it is unavailable, you can switch to the vanilla tqdm
progress bars; to do
so, open init.py
and change the line
'tqdmimport': "from tqdm import tqdm_notebook as tqdm"
to
'tqdmimport': "from tqdm import tqdm"
Although models are computed using NumPy by default, they can be computed with Theano instead. This allows for a substantial acceleration of simulation time thanks to the automatic translation and compilation to C code. Enabling Theano can be done by adding the line
shim.load_theano()
before instantiating the model. The Comparison Theano vs Numpy
notebook demonstrates that we can get 10-fold
speed improvements this way.
Using Theano also makes available a rich library of machine learning tools for which it forms a basis. One can thus make use of this to perform automatic differentiation, maximum-likelihood, MCMC sampling, etc.
A notebooks
directory is included, which contain Jupyter notebooks. These
provide example uses of this code base and illustrate some of its features.
Currently there are two:
- Comparison Theano vs Numpy: Shows that enabling Theano can provide substantial acceleration when integrating differential equations.
- Linearized tanh: Analysis of a nonlinear SDDE with delayed sigmoidal
feedback. Illustrates the use of the
Realizations
class, along with in-memory caching of statistics.