Skip to content
Closed

V088 #494

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
Changelog
=========

0.8.8 (2026-10-08)
------------------
- Enable `numpy >= 2.0`
- Add RobustGPyRegression model that can handle non-finite output values
- Update surrogate model initialisation to use all initial evidence
- Update BOLFI and BOLFIRE to use a shared sample class that returns individual chains in the arviz inference data
- Use kernel copy to avoid pickle issue and allow BOLFI parallelisation with non-default kernel
- Restrict matplotlib version < 3.9 for compatibility with GPy
- Add option to use additive or multiplicative adjustment in any acquisition method
- Add `arziv`-mocking to rtd-setup
- Add convenience method for obtaining elfi samples as `InferenceData`` to be used with `arviz`
- Improve `randmaxvar` batch acquisitions and initialisation by enabling sampling from prior
- Drop official Python support for 3.7 and 3.8 as GPy is not officially supported for these versions
- Enable using `maxiter` in `bo.utils.minimize`
- Fix surrogate model copy operation
- Fix typo in requirements.txt

0.8.7 (2023-09-21)
------------------
- Update available methods list
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ Ready to contribute? Here's how to set up `ELFI` for local development.
3. Make sure you have `Python 3 <https://www.python.org/>`_ and
`Anaconda Distribution <https://www.anaconda.com/>`_ installed on your
machine. Check your conda and Python versions. Currently supported Python versions
are 3.7, 3.8, 3.9, 3.10::
are 3.9, 3.10, 3.11, 3.12::

$ conda -V
$ python -V

4. Install your local copy and the development requirements into a conda
environment. You may need to replace "3.7" in the first line with the python
environment. You may need to replace "3.9" in the first line with the python
version printed in the previous step::

$ conda create -n elfi python=3.7 numpy
$ conda create -n elfi python=3.9 numpy
$ source activate elfi
$ cd elfi
$ make dev
Expand Down Expand Up @@ -136,7 +136,7 @@ Before you submit a pull request, check that it meets these guidelines:
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a docstring, and add the
feature to the list in README.md.
3. The pull request should work for Python 3.7 and later. Check
3. The pull request should work for Python 3.9 and later. Check
https://github.com/elfi-dev/elfi/actions/workflows/pytest.yml
and make sure that the tests pass for all supported Python versions.

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
**Version 0.8.7 released!** See the [CHANGELOG](CHANGELOG.rst) and [notebooks](https://github.com/elfi-dev/notebooks).
**Version 0.8.8 released!** See the [CHANGELOG](CHANGELOG.rst) and [notebooks](https://github.com/elfi-dev/notebooks).

<img src="https://raw.githubusercontent.com/elfi-dev/elfi/dev/docs/logos/elfi_logo_text_nobg.png" width="200" />

Expand Down Expand Up @@ -44,7 +44,7 @@ is preferable.
Installation with pip
---------------------

ELFI requires Python 3.7 or greater. You can install ELFI by typing in your terminal:
ELFI requires Python 3.9 or greater. You can install ELFI by typing in your terminal:

```
pip install elfi
Expand Down Expand Up @@ -95,7 +95,7 @@ with your default Python environment and can easily use different versions of Py
in different projects. You can create a virtual environment for ELFI using anaconda with:

```
conda create -n elfi python=3.7 numpy
conda create -n elfi python=3.9 numpy
source activate elfi
pip install elfi
```
Expand Down Expand Up @@ -125,7 +125,7 @@ Resolving these may sometimes go wrong:
- If you receive an error about `yaml.load`, install `pyyaml`.
- On OS X with Anaconda virtual environment say `conda install python.app` and then use
`pythonw` instead of `python`.
- Note that ELFI requires Python 3.7 or greater so try `pip3 install elfi`.
- Note that ELFI requires Python 3.9 or greater so try `pip3 install elfi`.
- Make sure your Python installation meets the versions listed in `requirements.txt`.


Expand Down
Binary file added docs/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Below is a list of inference methods included in ELFI.
OptimizationResult
Sample
SmcSample
BolfiSample
McmcSample


**Post-processing**
Expand Down Expand Up @@ -244,7 +244,7 @@ Inference API classes
:members:
:inherited-members:

.. autoclass:: BolfiSample
.. autoclass:: McmcSample
:members:
:inherited-members:

Expand Down
6 changes: 5 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class Mock(MagicMock):
def __getattr__(cls, name):
return MagicMock()

extensions = [
'sphinx_rtd_theme',
]

on_RTD = os.environ.get('READTHEDOCS', None) == 'True'
if on_RTD:
MOCK_MODULES = [
Expand All @@ -33,7 +37,7 @@ def __getattr__(cls, name):
'scipy.sparse', 'scipy.special', 'matplotlib.pyplot', 'numpy.random', 'networkx',
'ipyparallel', 'numpy.lib', 'numpy.lib.format', 'sklearn.linear_model',
'sklearn.pipeline', 'sklearn.preprocessing', 'numdifftools', 'GPy.kern', 'GPy.models',
'sklearn.covariance', 'sklearn.exceptions'
'sklearn.covariance', 'sklearn.exceptions', 'arviz'
]
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)

Expand Down
10 changes: 5 additions & 5 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Installation
============

ELFI requires Python 3.7 or greater (see below how to install). To install ELFI, simply
ELFI requires Python 3.9 or greater (see below how to install). To install ELFI, simply
type in your terminal:

.. code-block:: console
Expand All @@ -18,16 +18,16 @@ process.
.. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/


Installing Python 3.7
Installing Python 3.9
---------------------

If you are new to Python, perhaps the simplest way to install it is with Anaconda_ that
manages different Python versions. After installing Anaconda, you can create a Python 3.7.
manages different Python versions. After installing Anaconda, you can create a Python 3.9.
environment with ELFI:

.. code-block:: console

conda create -n elfi python=3.7 numpy
conda create -n elfi python=3.9 numpy
source activate elfi
pip install elfi

Expand All @@ -51,7 +51,7 @@ Resolving these may sometimes go wrong:
* If you receive an error about missing ``numpy``, please install it first.
* If you receive an error about `yaml.load`, install ``pyyaml``.
* On OS X with Anaconda virtual environment say `conda install python.app` and then use `pythonw` instead of `python`.
* Note that ELFI requires Python 3.7 or greater
* Note that ELFI requires Python 3.9 or greater
* In some environments ``pip`` refers to Python 2.x, and you have to use ``pip3`` to use the Python 3.x version
* Make sure your Python installation meets the versions listed in requirements_.

Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Quickstart

First ensure you have
`installed <http://elfi.readthedocs.io/en/stable/installation.html>`__
Python 3.7 (or greater) and ELFI. After installation you can start using
Python 3.5 (or greater) and ELFI. After installation you can start using
ELFI:

.. code:: ipython3
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/BOLFI.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ surface is updated after each batch (especially so if the noise is 0!).
.. code:: ipython3

bolfi = elfi.BOLFI(log_d, batch_size=1, initial_evidence=20, update_interval=10,
bounds={'t1':(-2, 2), 't2':(-1, 1)}, acq_noise_var=[0.1, 0.1], seed=seed)
bounds={'t1':(-2, 2), 't2':(-1, 1)}, acq_noise_var=0.1, seed=seed)

Sometimes you may have some samples readily available. You could then
initialize the GP model with a dictionary of previous results by giving
Expand Down
36 changes: 18 additions & 18 deletions docs/usage/external.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ If your simulator or other operations are implemented in a programming
language other than Python, you can still use ELFI. This notebook
briefly demonstrates how to do this in three common scenarios:

- External executable (written e.g. in C++ or a shell script)
- R function
- MATLAB function
- External executable (written e.g. in C++ or a shell script)
- R function
- MATLAB function

Let’s begin by importing some libraries that we will be using:

Expand Down Expand Up @@ -115,14 +115,14 @@ represents a “mutation” of the disease and the count describes how many
are currently infected by that mutation. There are three rates and the
population size:

- :math:`\alpha` - (birth rate) the rate at which any infectious host
transmits the disease.
- :math:`\delta` - (death rate) the rate at which any existing
infectious hosts either recovers or dies.
- :math:`\tau` - (mutation rate) the rate at which any infectious host
develops a new unseen mutation of the disease within themselves.
- :math:`N` - (population size) the size of the simulated infectious
population
- :math:`\alpha` - (birth rate) the rate at which any infectious host
transmits the disease.
- :math:`\delta` - (death rate) the rate at which any existing
infectious hosts either recovers or dies.
- :math:`\tau` - (mutation rate) the rate at which any infectious host
develops a new unseen mutation of the disease within themselves.
- :math:`N` - (population size) the size of the simulated infectious
population

It is assumed that the susceptible population is infinite, the hosts
carry only one mutation of the disease and transmit that mutation
Expand Down Expand Up @@ -620,10 +620,10 @@ insignificant.
References
~~~~~~~~~~

- [1] Jarno Lintusaari, Michael U. Gutmann, Ritabrata Dutta, Samuel
Kaski, Jukka Corander; Fundamentals and Recent Developments in
Approximate Bayesian Computation. Syst Biol 2017; 66 (1): e66-e82.
doi: 10.1093/sysbio/syw077
- [2] Tanaka, Mark M., et al. “Using approximate Bayesian computation
to estimate tuberculosis transmission parameters from genotype data.”
Genetics 173.3 (2006): 1511-1520.
- [1] Jarno Lintusaari, Michael U. Gutmann, Ritabrata Dutta, Samuel
Kaski, Jukka Corander; Fundamentals and Recent Developments in
Approximate Bayesian Computation. Syst Biol 2017; 66 (1): e66-e82.
doi: 10.1093/sysbio/syw077
- [2] Tanaka, Mark M., et al. “Using approximate Bayesian computation to
estimate tuberculosis transmission parameters from genotype data.”
Genetics 173.3 (2006): 1511-1520.
16 changes: 8 additions & 8 deletions docs/usage/parallelization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Parallelization
Behind the scenes, ELFI can automatically parallelize the computational
inference via different clients. Currently ELFI includes three clients:

- ``elfi.clients.native`` (activated by default): does not parallelize
but makes it easy to test and debug your code.
- ``elfi.clients.multiprocessing``: basic local parallelization using
Python’s built-in multiprocessing library
- ``elfi.clients.ipyparallel``:
`ipyparallel <http://ipyparallel.readthedocs.io/>`__ based client
that can parallelize from multiple cores up to a distributed cluster.
- ``elfi.clients.native`` (activated by default): does not parallelize
but makes it easy to test and debug your code.
- ``elfi.clients.multiprocessing``: basic local parallelization using
Python’s built-in multiprocessing library
- ``elfi.clients.ipyparallel``:
`ipyparallel <http://ipyparallel.readthedocs.io/>`__ based client that
can parallelize from multiple cores up to a distributed cluster.

A client is activated by giving the name of the client to
``elfi.set_client``.
Expand Down Expand Up @@ -157,7 +157,7 @@ start a local cluster to the background using 4 CPU cores:

.. code:: ipython3

!ipcluster start -n 4 --daemonize
!ipcluster start -n 4 --daemon

# This is here just to ensure that ipcluster has enough time to start properly before continuing
import time
Expand Down
16 changes: 8 additions & 8 deletions docs/usage/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,16 @@ that are similar to the observed sequence. Although the idea may appear
inapplicable for the task at hand, you will soon see that it does work.
For more information about ABC, please see e.g. 

- `Lintusaari, J., Gutmann, M. U., Dutta, R., Kaski, S., and Corander,
J. (2016). Fundamentals and recent developments in approximate
Bayesian computation. Systematic Biology, doi:
10.1093/sysbio/syw077. <http://sysbio.oxfordjournals.org/content/early/2016/09/07/sysbio.syw077.full.pdf>`__
- `Lintusaari, J., Gutmann, M. U., Dutta, R., Kaski, S., and Corander,
J. (2016). Fundamentals and recent developments in approximate
Bayesian computation. Systematic Biology, doi:
10.1093/sysbio/syw077. <http://sysbio.oxfordjournals.org/content/early/2016/09/07/sysbio.syw077.full.pdf>`__

- `Marin, J.-M., Pudlo, P., Robert, C. P., and Ryder, R. J. (2012).
Approximate Bayesian computational methods. Statistics and Computing,
22(6):1167–1180. <http://link.springer.com/article/10.1007/s11222-011-9288-2>`__
- `Marin, J.-M., Pudlo, P., Robert, C. P., and Ryder, R. J. (2012).
Approximate Bayesian computational methods. Statistics and Computing,
22(6):1167–1180. <http://link.springer.com/article/10.1007/s11222-011-9288-2>`__

- https://en.wikipedia.org/wiki/Approximate_Bayesian_computation
- https://en.wikipedia.org/wiki/Approximate_Bayesian_computation

Defining the model
------------------
Expand Down
4 changes: 2 additions & 2 deletions elfi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
from elfi.visualization.visualization import nx_draw as draw
from elfi.visualization.visualization import plot_params_vs_node
from elfi.visualization.visualization import plot_predicted_summaries
from elfi.methods.bo.gpy_regression import GPyRegression
from elfi.methods.bo.gpy_regression import GPyRegression, RobustGPyRegression

__author__ = 'ELFI authors'
__email__ = 'elfi-support@hiit.fi'

# make sure __version_ is on the last non-empty line (read by setup.py)
__version__ = '0.8.7'
__version__ = '0.8.8'
8 changes: 4 additions & 4 deletions elfi/examples/bdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ def prepare_inputs(*inputs, **kwinputs):
"""
alpha, delta, tau, N = inputs
meta = kwinputs['meta']

# Organize the parameters to an array. The broadcasting works nicely with constant
# arguments.
param_array = np.row_stack(np.broadcast(alpha, delta, tau, N))
param_array = np.vstack(
[(a, d, t, N) for (a, d, t, N) in np.broadcast(alpha, delta, tau, N)]
)

# Prepare a unique filename for parallel settings
filename = '{model_name}_{batch_index}_{submission_index}.txt'.format(**meta)
Expand All @@ -37,7 +38,6 @@ def prepare_inputs(*inputs, **kwinputs):
# Add the filenames to kwinputs
kwinputs['filename'] = filename
kwinputs['output_filename'] = filename[:-4] + '_out.txt'

# Return new inputs that the command will receive
return inputs, kwinputs

Expand Down Expand Up @@ -71,7 +71,7 @@ def process_result(completed_process, *inputs, **kwinputs):
def T1(clusters):
"""Summary statistic for BDM."""
clusters = np.atleast_2d(clusters)
return np.sum(clusters > 0, 1) / np.sum(clusters, 1)
return np.sum(clusters > 0, axis=1) / np.sum(clusters, axis=1)


def T2(clusters, n=20):
Expand Down
2 changes: 1 addition & 1 deletion elfi/examples/bignk.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def BiGNK(A1, A2, B1, B2, g1, g2, k1, k2, rho, c=.8, n_obs=150, batch_size=1, ra
z_batches = []
for i in range(batch_size):
# Initialising a separate covariance matrix for each batch.
matrix_cov = np.array([[1, float(rho[i])], [float(rho[i]), 1]])
matrix_cov = np.array([[1, rho[i, 0]], [rho[i, 0], 1]])

z_batch = ss.multivariate_normal.rvs(cov=matrix_cov, size=n_obs, random_state=random_state)
z_batches.append(z_batch)
Expand Down
Loading
Loading