Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.10.8 #368

Merged
merged 7 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ do
pip install \
git+https://github.com/amici-dev/amici.git@develop#egg=amici\&subdirectory=python/sdist
# install test suite
git clone --depth 1 \
https://github.com/petab-dev/petab_test_suite .tmp/petab_test_suite
pip install -e .tmp/petab_test_suite
pip install petabtests
;;

docs)
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/ci_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.8, 3.7]

steps:
- name: Check out repository
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Install dependencies
run: |
.github/workflows/ci_dependencies.sh base R
pip install -e .[R,test,code_quality]
pip install -e .[R,test]

- name: Run tests
timeout-minutes: 10
Expand All @@ -47,7 +47,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.8, 3.7]

steps:
- name: Check out repository
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.8, 3.7]

steps:
- name: Check out repository
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: [3.8]
python-version: [3.8, 3.7]

steps:
- name: Check out repository
Expand All @@ -147,7 +147,7 @@ jobs:
pip install -e .[test]

- name: Run tests
timeout-minutes: 3
timeout-minutes: 4
run: |
python -m pytest --cov=pyabc --cov-report=xml test/base/test_macos.py

Expand Down Expand Up @@ -184,7 +184,7 @@ jobs:
pip install -e .[quality]

- name: Run flake8
timeout-minutes: 1
timeout-minutes: 2
run: ./run_flake8.sh

- name: Run pyroma
Expand Down
13 changes: 12 additions & 1 deletion doc/examples/conversion_reaction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
":download:`Ordinary Differential Equations <conversion_reaction.ipynb>`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-warning\">\n",
"\n",
"**Note:** Before you use pyABC to parametrize your ODE, please be aware of potential errors introduced by inadequately representing the data generation process, see also the \"Measurement noise assessment\" notebook. For deterministic models, there are often more efficient alternatives to ABC, check out for example our tool <a href=\"https://github.com/ICB-DCM/pyPESTO\">pyPESTO</a>.\n",
"\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -456,7 +467,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
36 changes: 2 additions & 34 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,11 @@ If you use it in your work, you can cite the paper:
:caption: User's guide

what

.. toctree::
:maxdepth: 2

installation

.. toctree::
:maxdepth: 2

examples

.. toctree::
:maxdepth: 2

sampler

.. toctree::
:maxdepth: 2

sge

.. toctree::
:maxdepth: 2

export_db

.. toctree::
:maxdepth: 2

export_db
web_visualization


Expand All @@ -84,23 +60,15 @@ If you use it in your work, you can cite the paper:
:caption: About

releasenotes

.. toctree::
:maxdepth: 2

about
references


.. toctree::
:maxdepth: 2
:caption: Developer's guide

contribute


.. toctree::
:maxdepth: 2

deploy


Expand Down
36 changes: 36 additions & 0 deletions doc/references.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.. _references:

References
==========

List of publications using pyABC, so far in total amounting to 16 citations.
If you applied pyABC in your work, please consider notifying us, so we can include your work here.

2020
----

- Schälte, Yannik & Hasenauer, Jan. (2020). Efficient exact inference for dynamical systems with noisy measurements using sequential approximate Bayesian computation. Bioinformatics (Oxford, England). 36. i551-i559. `https://doi.org/10.1093/bioinformatics/btaa397`.
- Ruske, Liam & Kursawe, Jochen & Tsakiridis, Anestis & Wilson, Valerie & Fletcher, Alexander & Blythe, Richard & Schumacher, Linus. (2020). Coupled differentiation and division of embryonic stem cells inferred from clonal snapshots. Physical Biology. `https://doi.org/10.1088/1478-3975/aba041`.
- Houston, Charles & Marchand, B. & Engelbert, L. & Cantwell, Chris. (2020). Reducing complexity and unidentifiability when modelling human atrial cells. Philosophical Transactions of The Royal Society A Mathematical Physical and Engineering Sciences. 378. 20190339. `https://doi.org/10.1098/rsta.2019.0339`.
- Sid Ahmed, Samy & Bundgaard, Nils & Graw, Frederik & Fackler, Oliver. (2020). Environmental Restrictions: A New Concept Governing HIV-1 Spread Emerging from Integrated Experimental-Computational Analysis of Tissue-Like 3D Cultures. Cells. 9. 1112. `https://doi.org/10.3390/cells9051112`.
- Sendera, Marcin & Duane, Gregory & Dzwinel, Witold. (2020). Supermodeling: The Next Level of Abstraction in the Use of Data Assimilation. `https://doi.org/10.1007/978-3-030-50433-5_11`.
- Lupperger, Valerio & Marr, Carsten & Chapouton, Prisca. (2020). Aggregated spatio-temporal division patterns emerge from reoccurring divisions of neural stem cells. `https://doi.org/10.1101/2020.03.20.999748`.
- Bheda, Poonam & Aguilar-Gómez, Diana & Becker, Nils & Becker, Johannes & Stavrou, Emmanouil & Kukhtevich, Igor & Höfer, Thomas & Maerkl, Sebastian & Charvin, Gilles & Marr, Carsten & Kirmizis, Antonis & Schneider, Robert. (2020). Single-Cell Tracing Dissects Regulation of Maintenance and Inheritance of Transcriptional Reinduction Memory. Molecular Cell. 78. `https://doi.org/10.1016/j.molcel.2020.04.016`.
- Nadjahi, Kimia & Bortoli, Valentin & Durmus, Alain & Badeau, Roland & Simsekli, Umut. (2020). Approximate Bayesian Computation with the Sliced-Wasserstein Distance. 5470-5474. `https://doi.org/10.1109/ICASSP40776.2020.9054735`.

2019
----

- Bölts, Jan & Lueckmann, Jan-Matthis & Goncalves, Pedro & Sprekeler, Henning & Macke, Jakob. (2019). Comparing neural simulations by neural density estimation. `https://doi.org/10.32470/CCN.2019.1291-0`.
- Raynal, Louis & Marin, Jean-Michel & Pudlo, Pierre & Ribatet, Mathieu & Robert, Christian & Estoup, Arnaud. (2019). Genetics and population analysis ABC random forests for Bayesian parameter inference. Bioinformatics. 35. 1720. `https://doi.org/0.1093/bioinformatics/bty867`
- Vu, Hanh & Mansour, Sarah & Kücken, Michael & Blasse, Corinna & Basquin, Cyril & Azimzadeh, Juliette & Myers, Eugene & Brusch, Lutz & Rink, Jochen. (2019). Dynamic Polarization of the Multiciliated Planarian Epidermis between Body Plan Landmarks. Developmental Cell. 51. 526-542.e6. `https://doi.org/10.1016/j.devcel.2019.10.022`.
- Imle, Andrea & Kumberger, Peter & Schnellbächer, Nikolas & Fehr, Jana & Carrillo-Bustamante, Paola & Ales, Janez & Schmidt, Philip & Ritter, Christian & Godinez, William & Müller, Barbara & Rohr, Karl & Hamprecht, Fred & Schwarz, Ulrich & Graw, Frederik & Fackler, Oliver. (2019). Experimental and computational analyses reveal that environmental restrictions shape HIV-1 spread in 3D cultures. Nature Communications. 10. `https://doi.org/10.1038/s41467-019-09879-3`.
- Raynal, Louis. Bayesian statistical inference for intractable likelihood models. Diss. Université Montpellier, 2019.
- Kumberger, Peter Johannes Manuel Eduard. Quantifying the Impact of Cell-to-Cell Transmission on Viral Spread. Diss. 2019.

2018
----

- Cantwell, Chris & Mohamied, Yumnah & Tzortzis, Konstantinos & Garasto, Stef & Houston, Charles & Chowdhury, Rasheda & Ng, Fu Siong & Bharath, Anil & Peters, Nicholas. (2019). Rethinking multiscale cardiac electrophysiology with machine learning and predictive modelling. Computers in Biology and Medicine. 104. 339-351. `https://doi.org/10.1016/j.compbiomed.2018.10.015`.
- Klinger, Emmanuel G. Approximate Bayesian Model Selection for Local Cortical Networks at Cellular Resolution. Diss. Technische Universität München, 2018.

11 changes: 11 additions & 0 deletions doc/releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ Release Notes
...........


0.10.8 (2020-11-27)
-------------------

* Allow to normalize acceptance rate plots by ESS (#346).
* Add a list of pyABC references (#348).
* Update to petabtests 0.0.0a5 (#362).
* Add stopping criterion for total number of samples (#364).
* Remove dill dependency, thus fixing a cloudpickle error, and
run selected tests also with python 3.7 (#367).


0.10.7 (2020-08-20)
-------------------

Expand Down
18 changes: 10 additions & 8 deletions pyabc/inference/smc.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,25 +539,24 @@ def _create_transition_pdf(self, t: int, transitions):
def run(self,
minimum_epsilon: float = None,
max_nr_populations: int = np.inf,
min_acceptance_rate: float = 0.) -> History:
min_acceptance_rate: float = 0.,
max_total_nr_simulations: int = np.inf) -> History:
"""
Run the ABCSMC model selection until either of the stopping
criteria is met.

Parameters
----------

minimum_epsilon: float, optional
minimum_epsilon:
Stop if epsilon is smaller than minimum epsilon specified here.
Defaults in general to 0.0, and to 1.0 for a Temperature epsilon.

max_nr_populations: int, optional (default = np.inf)
max_nr_populations:
The maximum number of populations. Stop if this number is reached.

min_acceptance_rate: float, optional (default = 0.0)
min_acceptance_rate:
Minimal allowed acceptance rate. Sampling stops if a population
has a lower rate.

max_total_nr_simulations:
Bound on the total number of evaluations.

Population after population is sampled and particles which are close
enough to the observed data are accepted and added to the next
Expand Down Expand Up @@ -672,6 +671,9 @@ def run(self,
elif acceptance_rate < min_acceptance_rate:
logger.info("Stopping: minimum acceptance rate.")
break
elif self.history.total_nr_simulations >= max_total_nr_simulations:
logger.info("Stopping: total simulations budget.")
break

# increment t
t += 1
Expand Down
2 changes: 1 addition & 1 deletion pyabc/sampler/mapping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools
import random

import dill as pickle
import cloudpickle as pickle
import numpy as np

from .base import Sampler
Expand Down
2 changes: 1 addition & 1 deletion pyabc/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.7"
__version__ = "0.10.8"
18 changes: 15 additions & 3 deletions pyabc/visualization/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ..storage import History
from .util import to_lists_or_default
from ..weighted_statistics import effective_sample_size


def plot_sample_numbers(
Expand Down Expand Up @@ -263,7 +264,8 @@ def plot_acceptance_rates_trajectory(
yscale: str = 'lin',
size: tuple = None,
ax: mpl.axes.Axes = None,
colors: List[str] = None):
colors: List[str] = None,
normalize_by_ess: bool = False):
"""
Plot of acceptance rates over all iterations, i.e. one trajectory
per history.
Expand All @@ -288,6 +290,9 @@ def plot_acceptance_rates_trajectory(
The size of the plot in inches.
ax: matplotlib.axes.Axes, optional
The axis object to use.
normalize_by_ess: bool, optional (default = False)
Indicator to use effective sample size for the acceptance rate in
place of the population size.

Returns
-------
Expand All @@ -312,9 +317,16 @@ def plot_acceptance_rates_trajectory(
# note: the first entry of time -1 is trivial and is thus ignored here
h_info = history.get_all_populations()
times.append(np.array(h_info['t'])[1:])
if normalize_by_ess:
ess = np.zeros(len(h_info['t']) - 1)
for t in np.array(h_info['t'])[1:]:
w = history.get_weighted_distances(t=t)['w']
ess[t-1] = effective_sample_size(w)
pop_sizes.append(ess)
else:
pop_sizes.append(np.array(
history.get_nr_particles_per_population().values[1:]))
samples.append(np.array(h_info['samples'])[1:])
pop_sizes.append(np.array(
history.get_nr_particles_per_population().values[1:]))

# compute acceptance rates
rates = []
Expand Down
4 changes: 3 additions & 1 deletion run_flake8.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

python3 -m flake8 pyabc test --extend-ignore='S403,S301' --per-file-ignores='*/__init__.py:F401 test/*:T001,S101'
python3 -m flake8 pyabc test \
--extend-ignore='S403,S301,C408' \
--per-file-ignores='*/__init__.py:F401 test/*:T001,S101'
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ install_requires =
flask >= 1.1.2
bokeh >= 2.1.1
redis >= 2.10.6
dill >= 0.3.2
gitpython >= 3.1.7
scikit-learn >= 0.23.1
matplotlib >= 3.3.0
Expand All @@ -77,7 +76,7 @@ packages = find:

[options.extras_require]
R =
rpy2 >= 3.2.0
rpy2 >= 3.3.6
cffi >= 1.13.1
petab =
petab >= 0.1.8
Expand Down
19 changes: 19 additions & 0 deletions test/base/test_stop_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@


def model(x):
"""Some model"""
return {"par": x["par"] + np.random.randn()}


def dist(x, y):
"""Some distance"""
return abs(x["par"] - y["par"])


def test_stop_acceptance_rate_too_low(db_path):
"""Test the acceptance rate condition."""
abc = ABCSMC(model, Distribution(par=st.uniform(0, 10)), dist, pop_size)
abc.new(db_path, {"par": .5})
history = abc.run(-1, 8, min_acceptance_rate=set_acc_rate)
Expand All @@ -28,6 +31,7 @@ def test_stop_acceptance_rate_too_low(db_path):


def test_stop_early(db_path):
"""Test early stopping inside a generation."""
mc_sampler = MulticoreEvalParallelSampler(check_max_eval=True)
sc_sampler = SingleCoreSampler(check_max_eval=True)
for sampler in [mc_sampler, sc_sampler]:
Expand All @@ -44,3 +48,18 @@ def test_stop_early(db_path):
df["particles"] / (df["samples"] - (n_procs-1))

assert df["corrected_acceptance_rate"].iloc[-1] >= set_acc_rate


def test_total_nr_simulations(db_path):
"""Test the total number of samples condition."""
abc = ABCSMC(model, Distribution(par=st.uniform(0, 10)), dist, pop_size)
abc.new(db_path, {"par": .5})
max_total_nr_sim = 142
history = abc.run(-1, 100, max_total_nr_simulations=max_total_nr_sim)
assert history.total_nr_simulations >= max_total_nr_sim
# Directly check on the history
df = history.get_all_populations()
# Make sure budget is not exceeded yet in previous iteration
assert sum(df['samples'][:-1]) < max_total_nr_sim
# Just to make sure .total_nr_simulations does what it's supposed to
assert sum(df['samples']) == history.total_nr_simulations
Loading