Skip to content

Commit

Permalink
Merge pull request #271 from ICB-DCM/develop
Browse files Browse the repository at this point in the history
Release 0.10.0
  • Loading branch information
yannikschaelte authored Feb 20, 2020
2 parents 2d2bceb + 05a44c7 commit e3d4f3c
Show file tree
Hide file tree
Showing 25 changed files with 1,003 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ doc/*.log
.pytest_cache
dask-worker-space
*.lock
*tmp*
*amici_models*
16 changes: 12 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ os:
dist:
# take the latest supported LTS version
- xenial
compiler:
- gcc

# install dependencies

Expand All @@ -16,23 +18,29 @@ before_install:
- sudo add-apt-repository 'deb https://cran.rstudio.com/bin/linux/ubuntu xenial/'
- sudo apt-get update
- sudo apt-get install r-base r-base-dev r-base-core r-recommended
# from apt

addons:
apt:
update: true
packages:
- redis-server
# from pip
- libhdf5-serial-dev
- libatlas-base-dev
- swig3.0

install:
- mkdir -p ~/bin/ && ln -s /usr/bin/swig3.0 ~/bin/swig && export PATH=~/bin/:$PATH
- pip install --upgrade .
- pip install --upgrade -r .travis_pip_reqs.txt
- pip install --upgrade pytest
- pip install https://github.com/icb-dcm/petab/archive/develop.zip
- pip install -e git+https://github.com/icb-dcm/amici.git@develop#egg=amici\&subdirectory=python/sdist

# run tests

script:
- travis_wait 20 python -m pytest --cov=pyabc test/test_*
- travis_wait 5 xvfb-run -a python -m pytest --cov=pyabc --cov-append test/visualization/test_*
- travis_wait 10 python -m pytest --cov=pyabc test/test_*
- travis_wait 3 xvfb-run -a python -m pytest --cov=pyabc --cov-append test/visualization/test_*
- if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then travis_wait 15 test/run_notebooks.sh; fi

after_success:
Expand Down
2 changes: 2 additions & 0 deletions doc/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The following examples should help to get a better idea of how to use pyABC.
examples/external_simulators.ipynb
examples/data_plots.ipynb
examples/noise.ipynb
examples/petab.ipynb


Download the examples as notebooks
Expand All @@ -42,6 +43,7 @@ Download the examples as notebooks
* :download:`External Simulators <examples/external_simulators.ipynb>`
* :download:`Data plots <examples/data_plots.ipynb>`
* :download:`Measurement noise assessment <examples/noise.ipynb>`
* :download:`PEtab import <examples/petab.ipynb>`


.. warning::
Expand Down
388 changes: 388 additions & 0 deletions doc/examples/petab.ipynb

Large diffs are not rendered by default.

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


0.10 series
...........


0.10.0 (2020-02-20)
-------------------

* Exact inference via stochastic acceptor finalized and tested (developed
throughout the 0.9 series).
* Support basic PEtab functionality using AMICI ODE simulations (#268).
* Various error fixes (#265, #267).
* Log number of processes used by multiprocessing samplers (#263).
* Implement pyabc.acceptor.ScaledPDFNorm (#269).
* Implement list population size (#274, #276).
* On history loading, automatically find an id of a successful run (#273).


0.9 series
..........

Expand Down
2 changes: 1 addition & 1 deletion flake8_exclude.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
doc/conf.py,test_nondeterministic,build,test_performance,tmp
doc/conf.py,test_nondeterministic,build,test_performance,tmp,*amici_models*
6 changes: 5 additions & 1 deletion pyabc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
PercentileDistance,
RangeEstimatorDistance,
DistanceWithMeasureList,
StochasticKernel,
NormalKernel,
IndependentNormalKernel,
IndependentLaplaceKernel,
Expand Down Expand Up @@ -75,7 +76,8 @@
UniformAcceptor,
StochasticAcceptor,
pdf_norm_from_kernel,
pdf_norm_max_found)
pdf_norm_max_found,
ScaledPDFNorm)
from .model import (
Model,
SimpleModel,
Expand Down Expand Up @@ -115,6 +117,7 @@
"PercentileDistance",
"RangeEstimatorDistance",
"DistanceWithMeasureList",
"StochasticKernel",
"NormalKernel",
"IndependentNormalKernel",
"IndependentLaplaceKernel",
Expand Down Expand Up @@ -174,6 +177,7 @@
"StochasticAcceptor",
"pdf_norm_from_kernel",
"pdf_norm_max_found",
"ScaledPDFNorm",
# model
"ModelResult",
"Model",
Expand Down
2 changes: 2 additions & 0 deletions pyabc/acceptor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .pdf_norm import (
pdf_norm_from_kernel,
pdf_norm_max_found,
ScaledPDFNorm,
)


Expand All @@ -30,4 +31,5 @@
# pdf norm
'pdf_norm_from_kernel',
'pdf_norm_max_found',
'ScaledPDFNorm',
]
80 changes: 77 additions & 3 deletions pyabc/acceptor/pdf_norm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
from typing import Callable
from typing import Callable, Union
import pandas as pd


def pdf_norm_from_kernel(
Expand All @@ -13,8 +14,8 @@ def pdf_norm_from_kernel(


def pdf_norm_max_found(
prev_pdf_norm: float,
get_weighted_distances: Callable,
prev_pdf_norm: Union[float, None],
get_weighted_distances: Callable[[], pd.DataFrame],
**kwargs):
"""
Take as pdf_max the maximum over the values found so far in the history,
Expand All @@ -34,3 +35,76 @@ def pdf_norm_max_found(
pdf_norm = max(prev_pdf_norm, *pdfs)

return pdf_norm


class ScaledPDFNorm:
"""
Finds the previously found maximum density value, but then scales it
by a factor `factor**T` such that the probability of particles getting
accepted is increased by y value of up to `factor`.
Some additional rules are applied to make the scheme stable. The scaling
is in particular applied only after a minimum acceptance rate has been
violated.
Parameters
----------
factor:
The factor by which to effectively rescale the acceptance step's
normalization constant.
alpha:
The ratio by which the subsequent temperature is assumed to be
reduced relative to the current one. This is only accurate if a
pyabc.ExponentialDecayFixedRatioScheme with corresponding ratio
is employed.
min_acceptance_rate:
The scaling is applied once the acceptance rates fall below this
value for the first time.
"""

def __init__(
self,
factor: float = 10,
alpha: float = 0.5,
min_acceptance_rate: bool = 0.1):
self.factor = 10
self.alpha = alpha
self.min_acceptance_rate = min_acceptance_rate
self._hit = False

def __call__(
self,
prev_pdf_norm: Union[float, None],
get_weighted_distances: Callable[[], pd.DataFrame],
prev_temp: Union[float, None],
acceptance_rate: float,
**kwargs):
# base: the maximum found temperature
pdf_norm = pdf_norm_max_found(
prev_pdf_norm=prev_pdf_norm,
get_weighted_distances=get_weighted_distances)

# log-scale
offset = np.log(self.factor)

if acceptance_rate >= self.min_acceptance_rate and not self._hit:
# do not apply scaling yet since acceptance rates still feasible
return pdf_norm

# from now on rescale
self._hit = True

if prev_temp is None:
# can't take temperature into account, thus effectively assume T=1
next_temp = 1
else:
# note: this is only accurate if the temperature is based on a
# ExponentialDecayFixedRatioScheme with the given alpha value
next_temp = self.alpha * prev_temp

# the offset is multiplied by the next temperature so that the
# effective resulting factor in the acceptance step is as intended
scaled_norm = pdf_norm - offset * next_temp

# used_norm = max(prev_pdf_norm, used_norm)
return scaled_norm
5 changes: 1 addition & 4 deletions pyabc/parameters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from collections import UserDict


class ParameterStructure(UserDict):
class ParameterStructure(dict):
"""
Basic functionality of a structure containing parameters.
"""
Expand Down
6 changes: 6 additions & 0 deletions pyabc/petab/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .amici import AmiciPetabImporter


__all__ = [
'AmiciPetabImporter'
]
Loading

0 comments on commit e3d4f3c

Please sign in to comment.