Skip to content

Commit 3d4fe94

Browse files
authored
Merge pull request #221 from elfi-dev/dev
Fix issue #216, add arXiv info
2 parents 5801738 + 68767c2 commit 3d4fe94

File tree

6 files changed

+82
-56
lines changed

6 files changed

+82
-56
lines changed

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ CONTENT_URL := http://research.cs.aalto.fi/pml/software/elfi/docs/0.6.1/
7373

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

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

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

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

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

9090
# release: clean ## package and upload a release
9191
# python setup.py sdist upload

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,18 @@ Resolving these may sometimes go wrong:
7979
- On OS X with Anaconda virtual environment say `conda install python.app` and then use
8080
`pythonw` instead of `python`.
8181
- Note that ELFI requires Python 3.5 or greater so try `pip3 install elfi`.
82+
83+
84+
Citation
85+
--------
86+
87+
If you wish to cite ELFI, please use the paper in [arXiv](https://arxiv.org/abs/1708.00707):
88+
89+
```
90+
@misc{1708.00707,
91+
Author = {Jarno Lintusaari and Henri Vuollekoski and Antti Kangasrääsiö and Kusti Skytén and Marko Järvenpää and Michael Gutmann and Aki Vehtari and Jukka Corander and Samuel Kaski},
92+
Title = {ELFI: Engine for Likelihood Free Inference},
93+
Year = {2017},
94+
Eprint = {arXiv:1708.00707},
95+
}
96+
```

docs/description.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
ELFI is a statistical software package for likelihood-free inference (LFI) such as
22
Approximate Bayesian Computation (ABC_). The term LFI refers to a family of inference
33
methods that replace the use of the likelihood function with a data generating simulator
4-
function. ELFI features an easy to use generative modeling syntax and supports
5-
parallelized inference out of the box.
4+
function. Other names or related approaches to LFI include simulator-based inference,
5+
approximate Bayesian inference, indirect inference, etc.
6+
7+
ELFI features an easy to use syntax and supports parallelized inference out of the box.
68

79
.. _ABC: https://en.wikipedia.org/wiki/Approximate_Bayesian_computation

docs/index.rst

+13-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,18 @@ ELFI also has the following non LFI methods:
7070
.. developer/extensions
7171
7272
73+
Citation
74+
--------
7375

76+
If you wish to cite ELFI, please use the paper in arXiv_:
7477

75-
Other names or related approaches to LFI include simulator-based inference, approximate
76-
Bayesian inference, indirect inference, etc.
78+
.. _arXiv: https://arxiv.org/abs/1708.00707
79+
80+
.. code-block:: console
81+
82+
@misc{1708.00707,
83+
Author = {Jarno Lintusaari and Henri Vuollekoski and Antti Kangasrääsiö and Kusti Skytén and Marko Järvenpää and Michael Gutmann and Aki Vehtari and Jukka Corander and Samuel Kaski},
84+
Title = {ELFI: Engine for Likelihood Free Inference},
85+
Year = {2017},
86+
Eprint = {arXiv:1708.00707},
87+
}

docs/installation.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Optional dependencies
3838

3939
We recommend to install:
4040

41-
* ``graphviz`` for drawing graphical models (``pip install graphviz`` requires Graphviz_ binaries which are already available in many unix-like OS).
41+
* ``graphviz`` for drawing graphical models (``pip install graphviz`` requires Graphviz_ binaries).
4242

4343
.. _Graphviz: http://www.graphviz.org
4444

@@ -52,6 +52,7 @@ Resolving these may sometimes go wrong:
5252
* If you receive an error about `yaml.load`, install ``pyyaml``.
5353
* On OS X with Anaconda virtual environment say `conda install python.app` and then use `pythonw` instead of `python`.
5454
* Note that ELFI requires Python 3.5 or greater
55+
* In some environments ``pip`` refers to Python 2.x, and you have to use ``pip3`` to use the Python 3.x version
5556

5657
Developer installation from sources
5758
-----------------------------------

docs/usage/external.rst

+43-46
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ briefly demonstrates how to do this in three common scenarios:
1616

1717
Let's begin by importing some libraries that we will be using:
1818

19-
.. code:: python
19+
.. code:: ipython3
2020
2121
import os
2222
import numpy as np
@@ -45,7 +45,7 @@ use ``elfi.tools.external_operation`` tool to wrap executables as a
4545
Python callables (function). Let's first investigate how it works with a
4646
simple shell ``echo`` command:
4747

48-
.. code:: python
48+
.. code:: ipython3
4949
5050
# Make an external command. {0} {1} are positional arguments and {seed} a keyword argument `seed`.
5151
command = 'echo {0} {1} {seed}'
@@ -70,7 +70,7 @@ Currently ``echo_sim`` only accepts scalar arguments. In order to work
7070
in ELFI, ``echo_sim`` needs to be vectorized so that we can pass to it a
7171
vector of arguments. ELFI provides a handy tool for this as well:
7272

73-
.. code:: python
73+
.. code:: ipython3
7474
7575
# Vectorize it with elfi tools
7676
echo_sim_vec = elfi.tools.vectorize(echo_sim)
@@ -88,9 +88,9 @@ vector of arguments. ELFI provides a handy tool for this as well:
8888
8989
.. parsed-literal::
9090
91-
array([[ 4.16252911e-01, 0.00000000e+00, 3.08758378e+08],
92-
[ 9.83011677e-01, 0.00000000e+00, 3.08758378e+08],
93-
[ 8.22756066e-01, 0.00000000e+00, 3.08758378e+08]])
91+
array([[ 1.93678222e+00, 0.00000000e+00, 7.43529055e+08],
92+
[ 9.43846120e-01, 0.00000000e+00, 7.43529055e+08],
93+
[ 2.67626618e-01, 0.00000000e+00, 7.43529055e+08]])
9494
9595
9696
@@ -143,7 +143,7 @@ efficiently. We will now reproduce Figure 6(a) in `*Lintusaari at al
143143
2016* <https://doi.org/10.1093/sysbio/syw077>`__ *[2]* with ELFI. Let's
144144
start by defining some constants:
145145

146-
.. code:: python
146+
.. code:: ipython3
147147
148148
# Fixed model parameters
149149
delta = 0
@@ -156,7 +156,7 @@ start by defining some constants:
156156
Let's build the beginning of a new model for the birth rate
157157
:math:`\alpha` as the only unknown
158158

159-
.. code:: python
159+
.. code:: ipython3
160160
161161
m = elfi.ElfiModel(name='bdm')
162162
elfi.Prior('uniform', .005, 2, model=m, name='alpha')
@@ -170,29 +170,26 @@ Let's build the beginning of a new model for the birth rate
170170
171171
172172
173-
.. code:: python
173+
.. code:: ipython3
174174
175175
# Get the BDM source directory
176176
sources_path = elfi.examples.bdm.get_sources_path()
177177
178-
# Copy to resources folder and compile (unix-like systems)
179-
!cp -r $sources_path resources
180-
!make -C resources/cpp
178+
# Compile (unix-like systems)
179+
!make -C $sources_path
181180
182-
# Move the file in to the working directory
183-
!mv ./resources/cpp/bdm .
181+
# Move the executable in to the working directory
182+
!mv $sources_path/bdm .
184183
185184
186185
.. parsed-literal::
187186
188-
make: Entering directory '/l/lintusj1/elfi-dev/notebooks/resources/cpp'
189-
g++ bdm.cpp --std=c++0x -O -Wall -o bdm
190-
make: Leaving directory '/l/lintusj1/elfi-dev/notebooks/resources/cpp'
187+
g++ bdm.cpp --std=c++0x -O -Wall -o bdm
191188
192189
193190
.. note:: The source code for the BDM simulator comes with ELFI. You can get the directory with `elfi.examples.bdm.get_source_directory()`. Under unix-like systems it can be compiled with just typing `make` to console in the source directory. For windows systems, you need to have some C++ compiler available to compile it.
194191

195-
.. code:: python
192+
.. code:: ipython3
196193
197194
# Test the executable (assuming we have the executable `bdm` in the working directory)
198195
sim = elfi.tools.external_operation('./bdm {0} {1} {2} {3} --seed {seed} --mode 1')
@@ -220,7 +217,7 @@ efficient would be to write a native Python module with C++ but it's
220217
beyond the scope of this article. So let's work through files which is a
221218
fairly common situation especially with existing software.
222219

223-
.. code:: python
220+
.. code:: ipython3
224221
225222
# Assuming we have the executable `bdm` in the working directory
226223
command = './bdm {filename} --seed {seed} --mode 1 > {output_filename}'
@@ -272,7 +269,7 @@ informative filenames, we ask ELFI to provide the operation some meta
272269
information. That will be available under the ``meta`` keyword (see the
273270
``prepare_inputs`` function above):
274271

275-
.. code:: python
272+
.. code:: ipython3
276273
277274
# Create the simulator
278275
bdm_node = elfi.Simulator(bdm, m['alpha'], delta, tau, N, observed=y_obs, name='sim')
@@ -290,7 +287,7 @@ information. That will be available under the ``meta`` keyword (see the
290287

291288

292289

293-
.. code:: python
290+
.. code:: ipython3
294291
295292
# Test it
296293
data = bdm_node.generate(3)
@@ -299,9 +296,9 @@ information. That will be available under the ``meta`` keyword (see the
299296
300297
.. parsed-literal::
301298
302-
[[ 8 3 1 1 1 1 1 2 1 1 0 0 0 0 0 0 0 0 0 0]
303-
[ 8 1 1 1 1 1 1 3 1 1 1 0 0 0 0 0 0 0 0 0]
304-
[14 2 1 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]
299+
[[13 1 4 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
300+
[19 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
301+
[14 3 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]
305302
306303
307304
Completing the BDM model
@@ -312,7 +309,7 @@ We are now ready to finish up the BDM model. To reproduce Figure 6(a) in
312309
*[2]*, let's add different summaries and discrepancies to the model and
313310
run the inference for each of them:
314311

315-
.. code:: python
312+
.. code:: ipython3
316313
317314
def T1(clusters):
318315
clusters = np.atleast_2d(clusters)
@@ -340,7 +337,7 @@ run the inference for each of them:
340337
341338
342339
343-
.. code:: python
340+
.. code:: ipython3
344341
345342
elfi.draw(m)
346343
@@ -351,7 +348,7 @@ run the inference for each of them:
351348

352349

353350

354-
.. code:: python
351+
.. code:: ipython3
355352
356353
# Save parameter and simulation results in memory to speed up the later inference
357354
pool = elfi.OutputPool(['alpha', 'sim'])
@@ -370,15 +367,15 @@ run the inference for each of them:
370367
371368
.. parsed-literal::
372369
373-
CPU times: user 3.86 s, sys: 52 ms, total: 3.92 s
374-
Wall time: 4.81 s
375-
CPU times: user 32 ms, sys: 4 ms, total: 36 ms
376-
Wall time: 36.4 ms
377-
CPU times: user 40 ms, sys: 0 ns, total: 40 ms
378-
Wall time: 36.9 ms
370+
CPU times: user 3.11 s, sys: 143 ms, total: 3.26 s
371+
Wall time: 5.56 s
372+
CPU times: user 29.9 ms, sys: 1.45 ms, total: 31.3 ms
373+
Wall time: 31.2 ms
374+
CPU times: user 33.8 ms, sys: 500 µs, total: 34.3 ms
375+
Wall time: 34 ms
379376
380377
381-
.. code:: python
378+
.. code:: ipython3
382379
383380
# Load a precomputed posterior based on an analytic solution (see Lintusaari et al 2016)
384381
matdata = sio.loadmat('./resources/bdm.mat')
@@ -426,7 +423,7 @@ Here we demonstrate how to calculate the summary statistics used in the
426423
ELFI tutorial (autocovariances) using R's ``acf`` function for the MA2
427424
model.
428425

429-
.. code:: python
426+
.. code:: ipython3
430427
431428
import rpy2.robjects as robj
432429
from rpy2.robjects import numpy2ri as np2ri
@@ -441,7 +438,7 @@ model.
441438
Let's create a Python function that wraps the R commands (please see the
442439
documentation of `rpy2 <http://rpy2.readthedocs.io>`__ for details):
443440

444-
.. code:: python
441+
.. code:: ipython3
445442
446443
robj.r('''
447444
# create a function `f`
@@ -459,7 +456,7 @@ documentation of `rpy2 <http://rpy2.readthedocs.io>`__ for details):
459456
ans = apply(x, 1, f, lag=lag)
460457
return np.atleast_1d(ans)
461458
462-
.. code:: python
459+
.. code:: ipython3
463460
464461
# Test it
465462
autocovR(np.array([[1,2,3,4], [4,5,6,7]]), 1)
@@ -475,7 +472,7 @@ documentation of `rpy2 <http://rpy2.readthedocs.io>`__ for details):
475472
476473
Load a ready made MA2 model:
477474

478-
.. code:: python
475+
.. code:: ipython3
479476
480477
ma2 = elfi.examples.ma2.get_model(seed_obs=4)
481478
elfi.draw(ma2)
@@ -489,7 +486,7 @@ Load a ready made MA2 model:
489486

490487
Replace the summaries S1 and S2 with our R autocovariance function.
491488

492-
.. code:: python
489+
.. code:: ipython3
493490
494491
# Replace with R autocov
495492
S1 = elfi.Summary(autocovR, ma2['MA2'], 1)
@@ -523,20 +520,20 @@ MATLAB function using the official `MATLAB Python cd
523520
API <http://www.mathworks.com/help/matlab/matlab-engine-for-python.html>`__.
524521
(Tested with MATLAB 2016b.)
525522

526-
.. code:: python
523+
.. code:: ipython3
527524
528525
import matlab.engine
529526
530527
A MATLAB session needs to be started (and stopped) separately:
531528

532-
.. code:: python
529+
.. code:: ipython3
533530
534531
eng = matlab.engine.start_matlab() # takes a while...
535532
536533
Similarly as with R, we have to write a piece of code to interface
537534
between MATLAB and Python:
538535

539-
.. code:: python
536+
.. code:: ipython3
540537
541538
def euclidean_M(x, y):
542539
# MATLAB array initialized with Python's list
@@ -549,7 +546,7 @@ between MATLAB and Python:
549546
d = np.atleast_1d(dM).reshape(-1)
550547
return d
551548
552-
.. code:: python
549+
.. code:: ipython3
553550
554551
# Test it
555552
euclidean_M(np.array([[1,2,3], [6,7,8], [2,2,3]]), np.array([2,2,2]))
@@ -565,7 +562,7 @@ between MATLAB and Python:
565562
566563
Load a ready made MA2 model:
567564

568-
.. code:: python
565+
.. code:: ipython3
569566
570567
ma2M = elfi.examples.ma2.get_model(seed_obs=4)
571568
elfi.draw(ma2M)
@@ -579,7 +576,7 @@ Load a ready made MA2 model:
579576

580577
Replace the summaries S1 and S2 with our R autocovariance function.
581578

582-
.. code:: python
579+
.. code:: ipython3
583580
584581
# Replace with Matlab distance implementation
585582
d = elfi.Distance(euclidean_M, ma2M['S1'], ma2M['S2'])
@@ -604,7 +601,7 @@ Replace the summaries S1 and S2 with our R autocovariance function.
604601
605602
Finally, don't forget to quit the MATLAB session:
606603

607-
.. code:: python
604+
.. code:: ipython3
608605
609606
eng.quit()
610607

0 commit comments

Comments
 (0)