Skip to content

Commit

Permalink
Notebook doc updates (#212)
Browse files Browse the repository at this point in the history
* Notebook doc updates

* CHANGELOG

* Update documentation, README and CHANGELOG

* Rebase

* Change __init__ version

* review changes
  • Loading branch information
Jarno Lintusaari authored Jul 21, 2017
1 parent 4f72585 commit 7baa409
Show file tree
Hide file tree
Showing 9 changed files with 481 additions and 313 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Changelog
==========

dev
---
0.6.1 (2017-07-21)
------------------

- Fix elfi.Prior and NoneType error #203
- Fix a bug preventing the reuse of ArrayPool data with a new inference
Expand All @@ -16,7 +16,7 @@ dev
- Added the ability to move the pool data folder
- Sample.summary is now a method instead of a property
- SmcSample methods takes the keyword argument 'all' to show results of all populations

- Added a section about iterative advancing to documentation

0.6 (2017-07-03)
----------------
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,23 @@ docs: ## generate Sphinx HTML documentation, including API docs
$(MAKE) -C docs html
# $(BROWSER) docs/_build/html/index.html

CONTENT_URL := http://research.cs.aalto.fi/pml/software/elfi/docs/0.6/
CONTENT_URL := http://research.cs.aalto.fi/pml/software/elfi/docs/0.6.1/

notebook-docs: ## Conver notebooks to rst docs. Assumes you have them in `notebooks` directory.
jupyter nbconvert --to rst ../notebooks/quickstart.ipynb --output-dir docs
sed -i '' 's|\(quickstart_files/quickstart.*\.\)|'${CONTENT_URL}'\1|g' docs/quickstart.rst
sed -i 's|\(quickstart_files/quickstart.*\.\)|'${CONTENT_URL}'\1|g' docs/quickstart.rst

jupyter nbconvert --to rst ../notebooks/tutorial.ipynb --output-dir docs/usage
sed -i '' 's|\(tutorial_files/tutorial.*\.\)|'${CONTENT_URL}usage/'\1|g' docs/usage/tutorial.rst
sed -i 's|\(tutorial_files/tutorial.*\.\)|'${CONTENT_URL}usage/'\1|g' docs/usage/tutorial.rst

jupyter nbconvert --to rst ../notebooks/BOLFI.ipynb --output-dir docs/usage
sed -i '' 's|\(BOLFI_files/BOLFI.*\.\)|'${CONTENT_URL}usage/'\1|g' docs/usage/BOLFI.rst
sed -i 's|\(BOLFI_files/BOLFI.*\.\)|'${CONTENT_URL}usage/'\1|g' docs/usage/BOLFI.rst

jupyter nbconvert --to rst ../notebooks/parallelization.ipynb --output-dir docs/usage
sed -i '' 's|\(parallelization_files/parallelization.*\.\)|'${CONTENT_URL}usage/'\1|g' docs/usage/parallelization.rst
sed -i 's|\(parallelization_files/parallelization.*\.\)|'${CONTENT_URL}usage/'\1|g' docs/usage/parallelization.rst

jupyter nbconvert --to rst ../notebooks/non_python_operations.ipynb --output-dir docs/usage --output=external
sed -i '' 's|\(external_files/external.*\.\)|'${CONTENT_URL}usage/'\1|g' docs/usage/external.rst
sed -i 's|\(external_files/external.*\.\)|'${CONTENT_URL}usage/'\1|g' docs/usage/external.rst

# release: clean ## package and upload a release
# python setup.py sdist upload
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**Version 0.6 released!** See the CHANGELOG and [notebooks](https://github.com/elfi-dev/notebooks).
**Version 0.6.1 released!** See the CHANGELOG and [notebooks](https://github.com/elfi-dev/notebooks).

ELFI - Engine for Likelihood-Free Inference
===========================================
Expand Down Expand Up @@ -35,7 +35,7 @@ is preferable.
Installation
------------

ELFI requires and is tested with Python 3.5-3.6. You can install ELFI by typing in your terminal:
ELFI requires Python 3.5 or greater. You can install ELFI by typing in your terminal:

```
pip install elfi
Expand Down Expand Up @@ -78,5 +78,4 @@ Resolving these may sometimes go wrong:
- If you receive an error about `yaml.load`, install `pyyaml`.
- On OS X with Anaconda virtual environment say `conda install python.app` and then use
`pythonw` instead of `python`.
- Note that ELFI currently supports Python 3.5-3.6 only, although 3.x may work as well,
so try `pip3 install elfi`.
- Note that ELFI requires Python 3.5 or greater so try `pip3 install elfi`.
31 changes: 19 additions & 12 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ First ensure you have
Python 3.5 (or greater) and ELFI. After installation you can start using
ELFI:

.. code:: ipython3
.. code:: python
import elfi
ELFI includes an easy to use generative modeling syntax, where the
generative model is specified as a directed acyclic graph (DAG). Let’s
create two prior nodes:

.. code:: ipython3
.. code:: python
mu = elfi.Prior('uniform', -2, 4)
sigma = elfi.Prior('uniform', 1, 4)
Expand All @@ -30,7 +30,7 @@ summary statistics for the data. As an example, lets define the
simulator as 30 draws from a Gaussian distribution with a given mean and
standard deviation. Let's use mean and variance as our summaries:

.. code:: ipython3
.. code:: python
import scipy.stats as ss
import numpy as np
Expand All @@ -48,7 +48,7 @@ standard deviation. Let's use mean and variance as our summaries:
Let’s now assume we have some observed data ``y0`` (here we just create
some with the simulator):

.. code:: ipython3
.. code:: python
# Set the generating parameters that we will try to infer
mean0 = 1
Expand All @@ -73,7 +73,7 @@ Now we have all the components needed. Let’s complete our model by
adding the simulator, the observed data, summaries and a distance to our
model:

.. code:: ipython3
.. code:: python
# Add the simulator node and observed data to the model
sim = elfi.Simulator(simulator, mu, sigma, observed=y0)
Expand All @@ -85,23 +85,30 @@ model:
# Specify distance as euclidean between summary vectors (S1, S2) from simulated and
# observed data
d = elfi.Distance('euclidean', S1, S2)
If you have ``graphviz`` installed to your system, you can also
visualize the model:

.. code:: python
# Plot the complete model (requires graphviz)
elfi.draw(d)
.. image:: http://research.cs.aalto.fi/pml/software/elfi/docs/0.6/quickstart_files/quickstart_9_0.svg
.. image:: http://research.cs.aalto.fi/pml/software/elfi/docs/0.6.1/quickstart_files/quickstart_11_0.svg



.. Note:: The automatic naming of nodes may not work in all environments e.g. in interactive Python shells. You can alternatively provide a name argument for the nodes, e.g. ``S1 = elfi.Summary(mean, sim, name='S1')``.

We can try to infer the true generating parameters ``mean0`` and
``std0`` above with any of ELFI’s inference methods. Let’s use ABC
Rejection sampling and sample 1000 samples from the approximate
posterior using threshold value 0.5:

.. code:: ipython3
.. code:: python
rej = elfi.Rejection(d, batch_size=10000, seed=30052017)
res = rej.sample(1000, threshold=.5)
Expand All @@ -111,22 +118,22 @@ posterior using threshold value 0.5:
.. parsed-literal::
Method: Rejection
Number of posterior samples: 1000
Number of samples: 1000
Number of simulations: 120000
Threshold: 0.492
Posterior means: mu: 0.748, sigma: 3.1
Sample means: mu: 0.748, sigma: 3.1
Let's plot also the marginal distributions for the parameters:

.. code:: ipython3
.. code:: python
import matplotlib.pyplot as plt
res.plot_marginals()
plt.show()
.. image:: http://research.cs.aalto.fi/pml/software/elfi/docs/0.6/quickstart_files/quickstart_13_0.png
.. image:: http://research.cs.aalto.fi/pml/software/elfi/docs/0.6.1/quickstart_files/quickstart_16_0.png

Loading

0 comments on commit 7baa409

Please sign in to comment.