Skip to content

Commit b07ff6e

Browse files
authored
Merge pull request #304 from elfi-dev/dev
Update 0.7.3 -> 0.7.4
2 parents ff25fcb + 8ba3b62 commit b07ff6e

17 files changed

+263
-69
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ install:
2525
- pip install -e .
2626

2727
script:
28-
- ipcluster start -n 2 --daemon
28+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ipcluster start -n 2 --daemon ; fi
2929
#- travis_wait 20 make test
3030
- make test

CHANGELOG.rst

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
Changelog
22
=========
33

4+
5+
0.7.4 (2019-03-07)
6+
------------------
7+
- Add sampler option `algorithm` for bolfi-posterior-sampling
8+
- Add a check whether the option given for `algorithm` is one if the implemented samplers
9+
- Add metropolis sampler `algorithm=metropolis` for bolfi-posterior-sampling
10+
- Add option `warmup` to metropolis-sampler
11+
- Add a small test of metropolis-sampler
12+
- Fix bug in plot_discrepancy for more than 6 parameters
13+
- Implement plot_gp for BayesianOptimization classes for plotting discrepancies
14+
and pair-wise contours in case when we have arbitrary number of parameters
15+
- Fix lint
16+
417
0.7.3 (2018-08-30)
518
------------------
619
- Fix bug in plot_pairs which crashes in case of 1 parameter

Dockerfile

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ FROM ubuntu:bionic
33
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y graphviz make python3-scipy jupyter python3-matplotlib
44
RUN pip3 install graphviz
55

6-
WORKDIR /elfi
7-
ADD . /elfi
6+
ENV LANG C.UTF-8
7+
ENV LC_ALL C.UTF-8
8+
9+
WORKDIR /elfi0
10+
ADD . /elfi0
811

912
RUN pip3 install -e .
1013
RUN pip3 install -r requirements-dev.txt
14+
15+
# Note: The created image contains a static version of ELFI. To use the live, up-to-date version
16+
# you should mount the elfi directory when running the container ('make docker' does it for you).

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,11 @@ install: clean ## install the package to the active Python's site-packages
103103

104104
dev: install ## install the development requirements to the active Python's site-packages
105105
pip install -r requirements-dev.txt
106+
107+
docker-build: ## build a docker image suitable for running ELFI
108+
docker build --rm -t elfi .
109+
110+
docker: ## run a docker container with a live elfi directory and publish port 8888 for Jupyter
111+
docker run --rm -v ${PWD}:/elfi -w /elfi -it -p 8888:8888 elfi
112+
# to run Jupyter from within the container: jupyter notebook --ip 0.0.0.0 --no-browser --allow-root
113+
# and then from host open page: http://localhost:8888

README.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
**Version 0.7.3 released!** See the CHANGELOG and [notebooks](https://github.com/elfi-dev/notebooks).
1+
**Version 0.7.4 released!** See the CHANGELOG and [notebooks](https://github.com/elfi-dev/notebooks).
22

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

@@ -77,15 +77,21 @@ pip install elfi
7777

7878
### Docker container
7979

80-
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.
80+
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.
8181

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

89+
To open a Jupyter notebook, run
90+
```
91+
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root
92+
```
93+
within the container and then on host open the page http://localhost:8888.
94+
8995
### Potential problems with installation
9096

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

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

106112
```
107-
@misc{1708.00707,
108-
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},
109-
Title = {ELFI: Engine for Likelihood Free Inference},
110-
Year = {2018},
111-
Eprint = {arXiv:1708.00707},
113+
@article{JMLR:v19:17-374,
114+
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},
115+
title = {ELFI: Engine for Likelihood-Free Inference},
116+
journal = {Journal of Machine Learning Research},
117+
year = {2018},
118+
volume = {19},
119+
number = {16},
120+
pages = {1-7},
121+
url = {http://jmlr.org/papers/v19/17-374.html}
112122
}
113123
```

docs/index.rst

+11-7
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,19 @@ Additionally, ELFI integrates tools for visualization, model comparison, diagnos
7575
Citation
7676
--------
7777

78-
If you wish to cite ELFI, please use the paper in arXiv_:
78+
If you wish to cite ELFI, please use the paper in JMLR_:
7979

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

8282
.. code-block:: console
8383
84-
@misc{1708.00707,
85-
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},
86-
Title = {ELFI: Engine for Likelihood Free Inference},
87-
Year = {2018},
88-
Eprint = {arXiv:1708.00707},
84+
@article{JMLR:v19:17-374,
85+
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},
86+
title = {ELFI: Engine for Likelihood-Free Inference},
87+
journal = {Journal of Machine Learning Research},
88+
year = {2018},
89+
volume = {19},
90+
number = {16},
91+
pages = {1-7},
92+
url = {http://jmlr.org/papers/v19/17-374.html}
8993
}

docs/installation.rst

+13-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ means the current folder.
9292
Docker container
9393
----------------
9494

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

9898
.. _Docker documentation: https://docs.docker.com/
@@ -101,5 +101,15 @@ for running tests. Please see `Docker documentation`_ for details.
101101
102102
git clone --depth 1 https://github.com/elfi-dev/elfi.git
103103
cd elfi
104-
docker build -t elfi .
105-
docker run -it elfi
104+
make docker-build # builds the image with requirements for dev
105+
make docker # runs a container with live elfi directory
106+
107+
To open a Jupyter notebook, run
108+
109+
.. code-block:: console
110+
111+
jupyter notebook --ip 0.0.0.0 --no-browser --allow-root
112+
113+
within the container and then on host open the page `localhost:8888`_.
114+
115+
.. _localhost:8888: http://localhost:8888

elfi/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
__email__ = 'elfi-support@hiit.fi'
2727

2828
# make sure __version_ is on the last non-empty line (read by setup.py)
29-
__version__ = '0.7.3'
29+
__version__ = '0.7.4'

elfi/examples/daycare.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def get_model(true_params=None, seed_obs=None, **kwargs):
165165
"""
166166
logger = logging.getLogger()
167167
if true_params is None:
168-
true_params = [3.6, 0.6, 0.1]
168+
true_params = [3.6, 0.6, 0.1]
169169

170170
m = elfi.ElfiModel()
171171
y_obs = daycare(*true_params, random_state=np.random.RandomState(seed_obs), **kwargs)

elfi/loader.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def load(cls, context, compiled_net, batch_index):
157157
key = 'output'
158158
seed = context.seed
159159

160-
if seed is 'global':
160+
if seed == 'global':
161161
# Get the random_state of the respective worker by delaying the evaluation
162162
random_state = get_np_random
163163
key = 'operation'

elfi/methods/mcmc.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def _build_tree_nuts(params, momentum, log_slicevar, step, depth, log_joint0, ta
374374
mh_ratio, n_steps, is_div, is_out
375375

376376

377-
def metropolis(n_samples, params0, target, sigma_proposals, seed=0):
377+
def metropolis(n_samples, params0, target, sigma_proposals, warmup=0, seed=0):
378378
"""Sample the target with a Metropolis Markov Chain Monte Carlo using Gaussian proposals.
379379
380380
Parameters
@@ -387,6 +387,8 @@ def metropolis(n_samples, params0, target, sigma_proposals, seed=0):
387387
The target log density to sample (possibly unnormalized).
388388
sigma_proposals : np.array
389389
Standard deviations for Gaussian proposals of each parameter.
390+
warmup : int
391+
Number of warmup samples.
390392
seed : int, optional
391393
Seed for pseudo-random number generator.
392394
@@ -397,22 +399,29 @@ def metropolis(n_samples, params0, target, sigma_proposals, seed=0):
397399
"""
398400
random_state = np.random.RandomState(seed)
399401

400-
samples = np.empty((n_samples + 1, ) + params0.shape)
402+
samples = np.empty((n_samples + warmup + 1, ) + params0.shape)
401403
samples[0, :] = params0
402404
target_current = target(params0)
405+
if np.isinf(target_current):
406+
raise ValueError(
407+
"Metropolis: Bad initialization point {},logpdf -> -inf.".format(params0))
408+
403409
n_accepted = 0
404410

405-
for ii in range(1, n_samples + 1):
411+
for ii in range(1, n_samples + warmup + 1):
406412
samples[ii, :] = samples[ii - 1, :] + sigma_proposals * random_state.randn(*params0.shape)
407413
target_prev = target_current
408414
target_current = target(samples[ii, :])
409-
410-
if np.exp(target_current - target_prev) < random_state.rand(): # reject proposal
415+
if ((np.exp(target_current - target_prev) < random_state.rand())
416+
or np.isinf(target_current)
417+
or np.isnan(target_current)): # reject proposal
411418
samples[ii, :] = samples[ii - 1, :]
412419
target_current = target_prev
413420
else:
414421
n_accepted += 1
415422

416423
logger.info(
417-
"{}: Total acceptance ratio: {:.3f}".format(__name__, float(n_accepted) / n_samples))
418-
return samples[1:, :]
424+
"{}: Total acceptance ratio: {:.3f}".format(__name__,
425+
float(n_accepted) / (n_samples+warmup)))
426+
427+
return samples[(1+warmup):, :]

0 commit comments

Comments
 (0)