@@ -10,11 +10,11 @@ If your simulator or other operations are implemented in a programming
10
10
language other than Python, you can still use ELFI. This notebook
11
11
briefly demonstrates how to do this in three common scenarios:
12
12
13
- - External executable (written e.g. in C++ or a shell script)
13
+ - External executable (written e.g. in C++ or a shell script)
14
14
- R function
15
15
- MATLAB function
16
16
17
- Let' s begin by importing some libraries that we will be using:
17
+ Let’ s begin by importing some libraries that we will be using:
18
18
19
19
.. code :: ipython3
20
20
@@ -43,7 +43,7 @@ introduced in this tutorial.
43
43
44
44
We demonstrate here how to wrap executables as ELFI nodes. We will first
45
45
use ``elfi.tools.external_operation `` tool to wrap executables as a
46
- Python callables (function). Let' s first investigate how it works with a
46
+ Python callables (function). Let’ s first investigate how it works with a
47
47
simple shell ``echo `` command:
48
48
49
49
.. code :: ipython3
@@ -64,7 +64,7 @@ simple shell ``echo`` command:
64
64
65
65
66
66
67
- The placeholders for arguments in the command string are just Python' s
67
+ The placeholders for arguments in the command string are just Python’ s
68
68
```format strings `` <https://docs.python.org/3/library/string.html#formatstrings>`__.
69
69
70
70
Currently ``echo_sim `` only accepts scalar arguments. In order to work
@@ -103,16 +103,16 @@ Complex external operations :math:`-` case BDM
103
103
----------------------------------------------
104
104
105
105
To provide a more realistic example of external operations, we will
106
- consider the Birth-Death-Mutation (BDM) model used in `* Lintusaari at al
107
- 2016* <https://doi.org/10.1093/sysbio/syw077> `__ *[1] *.
106
+ consider the Birth-Death-Mutation (BDM) model used in `Lintusaari at al
107
+ 2016 <https://doi.org/10.1093/sysbio/syw077> `__ *[1] *.
108
108
109
109
Birth-Death-Mutation process
110
110
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111
111
112
112
We will consider here the Birth-Death-Mutation process simulator
113
113
introduced in *Tanaka et al 2006 [2] * for the spread of Tuberculosis.
114
114
The simulator outputs a count vector where each of its elements
115
- represents a " mutation" of the disease and the count describes how many
115
+ represents a “ mutation” of the disease and the count describes how many
116
116
are currently infected by that mutation. There are three rates and the
117
117
population size:
118
118
@@ -128,8 +128,8 @@ population size:
128
128
It is assumed that the susceptible population is infinite, the hosts
129
129
carry only one mutation of the disease and transmit that mutation
130
130
onward. A more accurate description of the model can be found from the
131
- original paper or e.g. `* Lintusaari at al
132
- 2016* <https://doi.org/10.1093/sysbio/syw077> `__ *[1] *.
131
+ original paper or e.g. `Lintusaari at al
132
+ 2016 <https://doi.org/10.1093/sysbio/syw077> `__ *[1] *.
133
133
134
134
.. For documentation
135
135
@@ -140,8 +140,8 @@ original paper or e.g. `*Lintusaari at al
140
140
141
141
This simulator cannot be implemented effectively with vectorized
142
142
operations so we have implemented it with C++ that handles loops
143
- efficiently. We will now reproduce Figure 6(a) in `* Lintusaari at al
144
- 2016* <https://doi.org/10.1093/sysbio/syw077> `__ *[2] * with ELFI. Let' s
143
+ efficiently. We will now reproduce Figure 6(a) in `Lintusaari at al
144
+ 2016 <https://doi.org/10.1093/sysbio/syw077> `__ *[2] * with ELFI. Let’ s
145
145
start by defining some constants:
146
146
147
147
.. code :: ipython3
@@ -154,7 +154,7 @@ start by defining some constants:
154
154
# The zeros are to make the observed population vector have length N
155
155
y_obs = np.array([6, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype='int16')
156
156
157
- Let' s build the beginning of a new model for the birth rate
157
+ Let’ s build the beginning of a new model for the birth rate
158
158
:math: `\alpha ` as the only unknown
159
159
160
160
.. code :: ipython3
@@ -214,8 +214,8 @@ thousands of simulations. We will also here redirect the output to a
214
214
file and then read the file into a numpy array.
215
215
216
216
This is just one possibility among the many to implement this. The most
217
- efficient would be to write a native Python module with C++ but it' s
218
- beyond the scope of this article. So let' s work through files which is a
217
+ efficient would be to write a native Python module with C++ but it’ s
218
+ beyond the scope of this article. So let’ s work through files which is a
219
219
fairly common situation especially with existing software.
220
220
221
221
.. code :: ipython3
@@ -265,7 +265,7 @@ fairly common situation especially with existing software.
265
265
process_result=process_result,
266
266
stdout=False)
267
267
268
- Now let' s replace the echo simulator with this. To create unique but
268
+ Now let’ s replace the echo simulator with this. To create unique but
269
269
informative filenames, we ask ELFI to provide the operation some meta
270
270
information. That will be available under the ``meta `` keyword (see the
271
271
``prepare_inputs `` function above):
@@ -306,9 +306,9 @@ Completing the BDM model
306
306
~~~~~~~~~~~~~~~~~~~~~~~~
307
307
308
308
We are now ready to finish up the BDM model. To reproduce Figure 6(a) in
309
- `* Lintusaari at al 2016* <https://doi.org/10.1093/sysbio/syw077 >`__
310
- * [2] *, let' s add different summaries and discrepancies to the model and
311
- run the inference for each of them:
309
+ `Lintusaari at al 2016 <https://doi.org/10.1093/sysbio/syw077 >`__ * [2] *,
310
+ let’ s add different summaries and discrepancies to the model and run the
311
+ inference for each of them:
312
312
313
313
.. code :: ipython3
314
314
@@ -421,7 +421,7 @@ the functionality of R from within Python. You can install it with
421
421
``pip install rpy2 ``.
422
422
423
423
Here we demonstrate how to calculate the summary statistics used in the
424
- ELFI tutorial (autocovariances) using R' s ``acf `` function for the MA2
424
+ ELFI tutorial (autocovariances) using R’ s ``acf `` function for the MA2
425
425
model.
426
426
427
427
.. code :: ipython3
@@ -436,7 +436,7 @@ model.
436
436
437
437
.. _issue : https://github.com/ContinuumIO/anaconda-issues/issues/152
438
438
439
- Let' s create a Python function that wraps the R commands (please see the
439
+ Let’ s create a Python function that wraps the R commands (please see the
440
440
documentation of `rpy2 <http://rpy2.readthedocs.io >`__ for details):
441
441
442
442
.. code :: ipython3
@@ -600,7 +600,7 @@ Replace the summaries S1 and S2 with our R autocovariance function.
600
600
601
601
602
602
603
- Finally, don' t forget to quit the MATLAB session:
603
+ Finally, don’ t forget to quit the MATLAB session:
604
604
605
605
.. code :: ipython3
606
606
@@ -625,6 +625,6 @@ References
625
625
Kaski, Jukka Corander; Fundamentals and Recent Developments in
626
626
Approximate Bayesian Computation. Syst Biol 2017; 66 (1): e66-e82.
627
627
doi: 10.1093/sysbio/syw077
628
- - [2] Tanaka, Mark M., et al. " Using approximate Bayesian computation
629
- to estimate tuberculosis transmission parameters from genotype data."
628
+ - [2] Tanaka, Mark M., et al. “ Using approximate Bayesian computation
629
+ to estimate tuberculosis transmission parameters from genotype data.”
630
630
Genetics 173.3 (2006): 1511-1520.
0 commit comments