Skip to content

Commit

Permalink
Merge pull request #304 from elfi-dev/dev
Browse files Browse the repository at this point in the history
Update 0.7.3 -> 0.7.4
  • Loading branch information
hpesonen committed Mar 7, 2019
2 parents ff25fcb + 8ba3b62 commit b07ff6e
Show file tree
Hide file tree
Showing 17 changed files with 263 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ install:
- pip install -e .

script:
- ipcluster start -n 2 --daemon
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ipcluster start -n 2 --daemon ; fi
#- travis_wait 20 make test
- make test
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
Changelog
=========


0.7.4 (2019-03-07)
------------------
- Add sampler option `algorithm` for bolfi-posterior-sampling
- Add a check whether the option given for `algorithm` is one if the implemented samplers
- Add metropolis sampler `algorithm=metropolis` for bolfi-posterior-sampling
- Add option `warmup` to metropolis-sampler
- Add a small test of metropolis-sampler
- Fix bug in plot_discrepancy for more than 6 parameters
- Implement plot_gp for BayesianOptimization classes for plotting discrepancies
and pair-wise contours in case when we have arbitrary number of parameters
- Fix lint

0.7.3 (2018-08-30)
------------------
- Fix bug in plot_pairs which crashes in case of 1 parameter
Expand Down
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ FROM ubuntu:bionic
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y graphviz make python3-scipy jupyter python3-matplotlib
RUN pip3 install graphviz

WORKDIR /elfi
ADD . /elfi
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

WORKDIR /elfi0
ADD . /elfi0

RUN pip3 install -e .
RUN pip3 install -r requirements-dev.txt

# Note: The created image contains a static version of ELFI. To use the live, up-to-date version
# you should mount the elfi directory when running the container ('make docker' does it for you).
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,11 @@ install: clean ## install the package to the active Python's site-packages

dev: install ## install the development requirements to the active Python's site-packages
pip install -r requirements-dev.txt

docker-build: ## build a docker image suitable for running ELFI
docker build --rm -t elfi .

docker: ## run a docker container with a live elfi directory and publish port 8888 for Jupyter
docker run --rm -v ${PWD}:/elfi -w /elfi -it -p 8888:8888 elfi
# to run Jupyter from within the container: jupyter notebook --ip 0.0.0.0 --no-browser --allow-root
# and then from host open page: http://localhost:8888
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**Version 0.7.3 released!** See the CHANGELOG and [notebooks](https://github.com/elfi-dev/notebooks).
**Version 0.7.4 released!** See the CHANGELOG and [notebooks](https://github.com/elfi-dev/notebooks).

**NOTE:** For the time being NetworkX 2 is incompatible with ELFI.

Expand Down Expand Up @@ -77,15 +77,21 @@ pip install elfi

### Docker container

A simple Dockerfile for command-line interface is also provided. This is especially suitable for running tests. Please see [Docker documentation](https://docs.docker.com/) for details.
A simple Dockerfile with Jupyter support is also provided. This is especially suitable for running tests. Please see [Docker documentation](https://docs.docker.com/) for details.

```
git clone --depth 1 https://github.com/elfi-dev/elfi.git
cd elfi
docker build -t elfi .
docker run -it elfi
make docker-build # builds the image with requirements for dev
make docker # runs a container with live elfi directory
```

To open a Jupyter notebook, run
```
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root
```
within the container and then on host open the page http://localhost:8888.

### Potential problems with installation

ELFI depends on several other Python packages, which have their own dependencies.
Expand All @@ -101,13 +107,17 @@ Resolving these may sometimes go wrong:
Citation
--------

If you wish to cite ELFI, please use the paper in [arXiv](https://arxiv.org/abs/1708.00707):
If you wish to cite ELFI, please use the paper in [JMLR](http://www.jmlr.org/papers/v19/17-374.html):

```
@misc{1708.00707,
Author = {Jarno Lintusaari and Henri Vuollekoski and Antti Kangasrääsiö and Kusti Skytén and Marko Järvenpää and Pekka Marttinen and Michael Gutmann and Aki Vehtari and Jukka Corander and Samuel Kaski},
Title = {ELFI: Engine for Likelihood Free Inference},
Year = {2018},
Eprint = {arXiv:1708.00707},
@article{JMLR:v19:17-374,
author = {Jarno Lintusaari and Henri Vuollekoski and Antti Kangasr{\"a}{\"a}si{\"o} and Kusti Skyt{\'e}n and Marko J{\"a}rvenp{\"a}{\"a} and Pekka Marttinen and Michael U. Gutmann and Aki Vehtari and Jukka Corander and Samuel Kaski},
title = {ELFI: Engine for Likelihood-Free Inference},
journal = {Journal of Machine Learning Research},
year = {2018},
volume = {19},
number = {16},
pages = {1-7},
url = {http://jmlr.org/papers/v19/17-374.html}
}
```
18 changes: 11 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ Additionally, ELFI integrates tools for visualization, model comparison, diagnos
Citation
--------

If you wish to cite ELFI, please use the paper in arXiv_:
If you wish to cite ELFI, please use the paper in JMLR_:

.. _arXiv: https://arxiv.org/abs/1708.00707
.. _JMLR: http://www.jmlr.org/papers/v19/17-374.html

.. code-block:: console
@misc{1708.00707,
Author = {Jarno Lintusaari and Henri Vuollekoski and Antti Kangasrääsiö and Kusti Skytén and Marko Järvenpää and Pekka Marttinen and Michael Gutmann and Aki Vehtari and Jukka Corander and Samuel Kaski},
Title = {ELFI: Engine for Likelihood Free Inference},
Year = {2018},
Eprint = {arXiv:1708.00707},
@article{JMLR:v19:17-374,
author = {Jarno Lintusaari and Henri Vuollekoski and Antti Kangasr{\"a}{\"a}si{\"o} and Kusti Skyt{\'e}n and Marko J{\"a}rvenp{\"a}{\"a} and Pekka Marttinen and Michael U. Gutmann and Aki Vehtari and Jukka Corander and Samuel Kaski},
title = {ELFI: Engine for Likelihood-Free Inference},
journal = {Journal of Machine Learning Research},
year = {2018},
volume = {19},
number = {16},
pages = {1-7},
url = {http://jmlr.org/papers/v19/17-374.html}
}
16 changes: 13 additions & 3 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ means the current folder.
Docker container
----------------

A simple Dockerfile for command-line interface is also provided. This is especially suitable
A simple Dockerfile with Jupyter support is also provided. This is especially suitable
for running tests. Please see `Docker documentation`_ for details.

.. _Docker documentation: https://docs.docker.com/
Expand All @@ -101,5 +101,15 @@ for running tests. Please see `Docker documentation`_ for details.
git clone --depth 1 https://github.com/elfi-dev/elfi.git
cd elfi
docker build -t elfi .
docker run -it elfi
make docker-build # builds the image with requirements for dev
make docker # runs a container with live elfi directory
To open a Jupyter notebook, run

.. code-block:: console
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root
within the container and then on host open the page `localhost:8888`_.

.. _localhost:8888: http://localhost:8888
2 changes: 1 addition & 1 deletion elfi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
__email__ = 'elfi-support@hiit.fi'

# make sure __version_ is on the last non-empty line (read by setup.py)
__version__ = '0.7.3'
__version__ = '0.7.4'
2 changes: 1 addition & 1 deletion elfi/examples/daycare.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get_model(true_params=None, seed_obs=None, **kwargs):
"""
logger = logging.getLogger()
if true_params is None:
true_params = [3.6, 0.6, 0.1]
true_params = [3.6, 0.6, 0.1]

m = elfi.ElfiModel()
y_obs = daycare(*true_params, random_state=np.random.RandomState(seed_obs), **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion elfi/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def load(cls, context, compiled_net, batch_index):
key = 'output'
seed = context.seed

if seed is 'global':
if seed == 'global':
# Get the random_state of the respective worker by delaying the evaluation
random_state = get_np_random
key = 'operation'
Expand Down
23 changes: 16 additions & 7 deletions elfi/methods/mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def _build_tree_nuts(params, momentum, log_slicevar, step, depth, log_joint0, ta
mh_ratio, n_steps, is_div, is_out


def metropolis(n_samples, params0, target, sigma_proposals, seed=0):
def metropolis(n_samples, params0, target, sigma_proposals, warmup=0, seed=0):
"""Sample the target with a Metropolis Markov Chain Monte Carlo using Gaussian proposals.
Parameters
Expand All @@ -387,6 +387,8 @@ def metropolis(n_samples, params0, target, sigma_proposals, seed=0):
The target log density to sample (possibly unnormalized).
sigma_proposals : np.array
Standard deviations for Gaussian proposals of each parameter.
warmup : int
Number of warmup samples.
seed : int, optional
Seed for pseudo-random number generator.
Expand All @@ -397,22 +399,29 @@ def metropolis(n_samples, params0, target, sigma_proposals, seed=0):
"""
random_state = np.random.RandomState(seed)

samples = np.empty((n_samples + 1, ) + params0.shape)
samples = np.empty((n_samples + warmup + 1, ) + params0.shape)
samples[0, :] = params0
target_current = target(params0)
if np.isinf(target_current):
raise ValueError(
"Metropolis: Bad initialization point {},logpdf -> -inf.".format(params0))

n_accepted = 0

for ii in range(1, n_samples + 1):
for ii in range(1, n_samples + warmup + 1):
samples[ii, :] = samples[ii - 1, :] + sigma_proposals * random_state.randn(*params0.shape)
target_prev = target_current
target_current = target(samples[ii, :])

if np.exp(target_current - target_prev) < random_state.rand(): # reject proposal
if ((np.exp(target_current - target_prev) < random_state.rand())
or np.isinf(target_current)
or np.isnan(target_current)): # reject proposal
samples[ii, :] = samples[ii - 1, :]
target_current = target_prev
else:
n_accepted += 1

logger.info(
"{}: Total acceptance ratio: {:.3f}".format(__name__, float(n_accepted) / n_samples))
return samples[1:, :]
"{}: Total acceptance ratio: {:.3f}".format(__name__,
float(n_accepted) / (n_samples+warmup)))

return samples[(1+warmup):, :]

0 comments on commit b07ff6e

Please sign in to comment.