diff --git a/pints/functionaltests/__init__.py b/pints/functionaltests/__init__.py index a3e83e981..ee5981e63 100644 --- a/pints/functionaltests/__init__.py +++ b/pints/functionaltests/__init__.py @@ -1,13 +1,43 @@ # +# "Functional test" module for PINTS. +# # This file is part of PINTS (https://github.com/pints-team/pints/) which is # released under the BSD 3-clause license. See accompanying LICENSE.md for # copyright notice and full license details. # -from .differential_evolution import test_differential_evolution_on_banana -from .differential_evolution import test_differential_evolution_on_two_dim_gaussian +# Import all problem classes straight into this module, so that they can be +# addressed as e.g. pints.functionaltests.RunMcmcMethodOnAnnulus. +from ._problems import ( # noqa + RunMcmcMethodOnAnnulus, + RunMcmcMethodOnBanana, + RunMcmcMethodOnCone, + RunMcmcMethodOnCorrelatedGaussian, + RunMcmcMethodOnHighDimensionalGaussian, + RunMcmcMethodOnMultimodalGaussian, + RunMcmcMethodOnTwoDimGaussian, +) + +# Import all test modules (not methods!) directly into this method, so that +# they can be addressed as e.g. +# pints.functionaltests.dram_acmc.two_dim_gaussian(). +from . import ( # noqa + differential_evolution_mcmc, + dram_acmc, + dream_mcmc, + emcee_hammer_mcmc, + haario_acmc, + haario_bardenet_acmc, + hamiltonian_mcmc, + mala_mcmc, + metropolis_random_walk_mcmc, + monomial_gamma_hamiltonian_mcmc, + no_u_turn_mcmc, + population_mcmc, + relativistic_mcmc, + slice_stepout_mcmc, +) + -from .haario_bardenet_acmc import test_haario_bardenet_acmc_on_annulus -from .haario_bardenet_acmc import test_haario_bardenet_acmc_on_banana -from .haario_bardenet_acmc import test_haario_bardenet_acmc_on_correlated_gaussian -from .haario_bardenet_acmc import test_haario_bardenet_acmc_on_two_dim_gaussian +# Test discovery methods +from ._discovery import tests diff --git a/pints/functionaltests/_discovery.py b/pints/functionaltests/_discovery.py new file mode 100644 index 000000000..38227f85e --- /dev/null +++ b/pints/functionaltests/_discovery.py @@ -0,0 +1,40 @@ +# +# Functional test discovery methods for PINTS. +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import inspect + +import pints.functionaltests as ft + + +def tests(method=None): + """ + Returns a list of all functional tests, each represented as a tuple + ``(method, test)`` where ``method`` is the PINTS class being tested and + ``test`` is a callable that returns the test results. + + If the optional argument ``method`` is given, only tests for this method + are returned. + """ + # Get all modules imported into this module + modules = [getattr(ft, x) for x in dir(ft) if not x.startswith('_')] + modules = [x for x in modules if inspect.ismodule(x)] + + # Look for (explicitly defined) tests + tests = [] + for module in modules: + try: + m_method = module._method + m_tests = module._functional_tests + except AttributeError: + continue + + if method is None or method == m_method: + for test in m_tests: + tests.append((m_method, test)) + + return tests + diff --git a/pints/functionaltests/_problems.py b/pints/functionaltests/_problems.py index 6b7c0a444..7b0409e6c 100644 --- a/pints/functionaltests/_problems.py +++ b/pints/functionaltests/_problems.py @@ -1,15 +1,44 @@ # +# Shared problems used in functional testing. +# # This file is part of PINTS (https://github.com/pints-team/pints/) which is # released under the BSD 3-clause license. See accompanying LICENSE.md for # copyright notice and full license details. # - import numpy as np + import pints import pints.toy class RunMcmcMethodOnProblem(object): + """ + Base class for tests that run an MCMC method on a log-PDF. + + Parameters + ---------- + log_pdf : pints.LogPDF + The PDF to sample. Will be passed to a :class:`pints.MCMCController`. + x0 + One or more starting points to be passed to the + :class:`pints.MCMCController`. + sigma0 + One or more ``sigma0`` parameters to be passed to the + :class:`pints.MCMCController`. + method : pints.MCMCSampler + The method to test. Will be passed to the + :class:`pints.MCMCController`. + n_chains : int + The number of chains to run. Will be passed to the + :class:`pints.MCMCController`. + n_iterations : int + The number of iterations to run + n_warmup : int + The number of iterations to discard + method_hyper_parameters : list + A list of hyperparameter values. + + """ def __init__(self, log_pdf, x0, sigma0, method, n_chains, n_iterations, n_warmup, method_hyper_parameters): @@ -26,9 +55,11 @@ def __init__(self, log_pdf, x0, sigma0, method, n_chains, n_iterations, def estimate_kld(self): """ Estimates the Kullback-Leibler divergence. + + Raises an ``AttributeError`` if the underlying LogPDF does not have a + method ``kl_divergence()``. """ chains = np.vstack(self.chains) - return np.mean(self.log_pdf.kl_divergence(chains)) def estimate_mean_ess(self): @@ -47,15 +78,21 @@ def estimate_mean_ess(self): def estimate_distance(self): """ - Estimates a measure of distance for the `pints.AnnulusLogPDF` class. + Estimates a measure of distance between the sampled chains and the true + distribution. + + Raises an ``AttributeError`` if the underlying LogPDF does not have a + method ``distance()``. """ return self.log_pdf.distance(np.vstack(self.chains)) class RunMcmcMethodOnTwoDimGaussian(RunMcmcMethodOnProblem): """ - Tests a given MCMC method on a standard 2 dimensional Gaussian - distribution. + Tests a given MCMC method on a two-dimensional Gaussian distribution with + means ``[0, 0]`` and sigma ``[1, 1]``. + + For constructor arguments, see :class:`RunMcmcMethodOnProblem`. """ def __init__(self, method, n_chains, n_iterations, n_warmup, @@ -75,7 +112,11 @@ def __init__(self, method, n_chains, n_iterations, n_warmup, class RunMcmcMethodOnBanana(RunMcmcMethodOnProblem): """ - Tests a given MCMC method on `pints.toy.TwistedGaussianLogPDF`. + Tests a given MCMC method on a two-dimensional + :class:`pints.toy.TwistedGaussianLogPDF` distribution with means + ``[0, 0]``. + + For constructor arguments, see :class:`RunMcmcMethodOnProblem`. """ def __init__(self, method, n_chains, n_iterations, n_warmup, method_hyper_parameters=None): @@ -91,6 +132,7 @@ def __init__(self, method, n_chains, n_iterations, n_warmup, n_warmup, method_hyper_parameters) +''' class RunMcmcMethodOnSimpleEggBox(RunMcmcMethodOnProblem): """ Tests a given MCMC method on `pints.toy.SimpleEggBoxLogPDF`. @@ -105,11 +147,15 @@ def __init__(self, method, n_chains, n_iterations, n_warmup, super().__init__(log_pdf, x0, sigma0, method, n_chains, n_iterations, n_warmup, method_hyper_parameters) +''' class RunMcmcMethodOnHighDimensionalGaussian(RunMcmcMethodOnProblem): """ - Tests a given MCMC method on `pints.toy.HighDimensionalGaussianLogPDF`. + Tests a given MCMC method on a 20-dimensional + :class:`pints.toy.HighDimensionalGaussianLogPDF` centered at the origin. + + For constructor arguments, see :class:`RunMcmcMethodOnProblem`. """ def __init__(self, method, n_chains, n_iterations, n_warmup, method_hyper_parameters=None): @@ -123,13 +169,14 @@ def __init__(self, method, n_chains, n_iterations, n_warmup, class RunMcmcMethodOnCorrelatedGaussian(RunMcmcMethodOnProblem): """ - Tests a given MCMC method on `pints.toy.HighDimensionalGaussianLogPDF` - but using a 6-dimensional problem with higher correlation. + Tests a given MCMC method on a 6-dimensional, highly correlated + :class:`pints.toy.HighDimensionalGaussianLogPDF` centered at the origin. + + For constructor arguments, see :class:`RunMcmcMethodOnProblem`. """ def __init__(self, method, n_chains, n_iterations, n_warmup, method_hyper_parameters=None): - log_pdf = pints.toy.HighDimensionalGaussianLogPDF( - dimension=6, rho=0.8) + log_pdf = pints.toy.HighDimensionalGaussianLogPDF(dimension=6, rho=0.8) x0 = np.random.uniform(-4, 4, size=(n_chains, 6)) sigma0 = None @@ -139,7 +186,11 @@ def __init__(self, method, n_chains, n_iterations, n_warmup, class RunMcmcMethodOnAnnulus(RunMcmcMethodOnProblem): """ - Tests a given MCMC method on `pints.AnnulusLogPDF`. + Tests a given MCMC method on a two-dimensional + :class:`pints.toy.AnnulusLogPDF` distribution, with its highest values at + any point ``x`` with ``np.linalg.norm(x) == 10``. + + For constructor arguments, see :class:`RunMcmcMethodOnProblem`. """ def __init__(self, method, n_chains, n_iterations, n_warmup, method_hyper_parameters=None): @@ -153,17 +204,21 @@ def __init__(self, method, n_chains, n_iterations, n_warmup, class RunMcmcMethodOnMultimodalGaussian(RunMcmcMethodOnProblem): """ - Tests a given MCMC method on `MultimodalGaussianLogPDF`. + Tests a given MCMC method on a two-dimensional + :class:`pints.toy.MultimodalGaussianLogPDF` with modes at ``[0, 0]``, + ``[5, 10]``, and ``[10, 0]``. + + For constructor arguments, see :class:`RunMcmcMethodOnProblem`. """ def __init__(self, method, n_chains, n_iterations, n_warmup, method_hyper_parameters=None): + modes = [[0, 0], + [5, 10], + [10, 0]] covariances = [[[1, 0], [0, 1]], [[2, 0.8], [0.8, 3]], [[1, -0.5], [-0.5, 1]]] - log_pdf = pints.toy.MultimodalGaussianLogPDF(modes=[[0, 0], - [5, 10], - [10, 0]], - covariances=covariances) + log_pdf = pints.toy.MultimodalGaussianLogPDF(modes, covariances) x0 = log_pdf.sample(n_chains) sigma0 = None @@ -173,7 +228,10 @@ def __init__(self, method, n_chains, n_iterations, n_warmup, class RunMcmcMethodOnCone(RunMcmcMethodOnProblem): """ - Tests a given MCMC method on `MultimodalGaussianLogPDF`. + Tests a given MCMC method on a two-dimensional + :class:`pints.toy,ConeLogPDF` centered at ``[0, 0]``. + + For constructor arguments, see :class:`RunMcmcMethodOnProblem`. """ def __init__(self, method, n_chains, n_iterations, n_warmup, method_hyper_parameters=None): diff --git a/pints/functionaltests/differential_evolution.py b/pints/functionaltests/differential_evolution.py deleted file mode 100644 index 9c9a63465..000000000 --- a/pints/functionaltests/differential_evolution.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus) - - -def test_differential_evolution_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.DifferentialEvolutionMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_differential_evolution_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnBanana( - method=pints.DifferentialEvolutionMCMC, - n_chains=20, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_differential_evolution_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.DifferentialEvolutionMCMC, - n_chains=20, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_differential_evolution_on_annulus(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnAnnulus( - method=pints.DifferentialEvolutionMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/differential_evolution_mcmc.py b/pints/functionaltests/differential_evolution_mcmc.py new file mode 100644 index 000000000..35ceea820 --- /dev/null +++ b/pints/functionaltests/differential_evolution_mcmc.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# +# Functional tests for DifferentialEvolutionMCMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=10000, n_warmup=1000): + """ + Tests :class:`pints.DifferentialEvolutionMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 10, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=5000, n_warmup=1000): + """ + Tests :class:`pints.DifferentialEvolutionMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 20, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def correlated_gaussian(n_iterations=10000, n_warmup=1000): + """ + Tests :class:`pints.DifferentialEvolutionMCMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + _method, 20, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def annulus(n_iterations=10000, n_warmup=1000): + """ + Tests :class:`pints.DifferentialEvolutionMCMC` + on a two-dimensional annulus distribution with radius 10, and returns a + dictionary with entries ``distance`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. + """ + problem = ft.RunMcmcMethodOnAnnulus( + _method, 10, n_iterations, n_warmup) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.DifferentialEvolutionMCMC +_functional_tests = [ + annulus, + banana, + correlated_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/dram.py b/pints/functionaltests/dram.py deleted file mode 100644 index cdc3b133b..000000000 --- a/pints/functionaltests/dram.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnBanana) - - -def test_dram_acmc_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 8000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.DramACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=2000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_haario_acmc_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnBanana( - method=pints.DramACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_dram_acmc_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.DramACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=4000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/dram_acmc.py b/pints/functionaltests/dram_acmc.py new file mode 100644 index 000000000..2ec83eea6 --- /dev/null +++ b/pints/functionaltests/dram_acmc.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +# +# Functional tests for DramACMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=8000, n_warmup=2000): + """ + Tests :class:`pints.DramACMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=4000, n_warmup=1000): + """ + Tests :class:`pints.DramACMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def correlated_gaussian(n_iterations=8000, n_warmup=4000): + """ + Tests :class:`pints.DramACMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.DramACMC +_functional_tests = [ + banana, + correlated_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/dream.py b/pints/functionaltests/dream.py deleted file mode 100644 index 70a9a722e..000000000 --- a/pints/functionaltests/dream.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus) - - -def test_dream_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.DreamMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_dream_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnBanana( - method=pints.DreamMCMC, - n_chains=20, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_dream_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.DreamMCMC, - n_chains=20, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_dream_on_annulus(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnAnnulus( - method=pints.DreamMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/dream_mcmc.py b/pints/functionaltests/dream_mcmc.py new file mode 100644 index 000000000..ca6745a4b --- /dev/null +++ b/pints/functionaltests/dream_mcmc.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# +# Functional tests for DreamMCMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=10000, n_warmup=1000): + """ + Tests :class:`pints.DreamMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 10, n_iterations, n_warmup) + + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=5000, n_warmup=1000): + """ + Tests :class:`pints.DreamMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 20, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def correlated_gaussian(n_iterations=10000, n_warmup=1000): + """ + Tests :class:`pints.DreamMCMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + _method, 20, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def annulus(n_iterations=10000, n_warmup=1000): + """ + Tests :class:`pints.DreamMCMC` + on a two-dimensional annulus distribution with radius 10, and returns a + dictionary with entries ``distance`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. + """ + problem = ft.RunMcmcMethodOnAnnulus( + _method, 10, n_iterations, n_warmup) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.DreamMCMC +_functional_tests = [ + annulus, + banana, + correlated_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/emcee_hammer.py b/pints/functionaltests/emcee_hammer.py deleted file mode 100644 index b1ebb1c61..000000000 --- a/pints/functionaltests/emcee_hammer.py +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnCone) - - -def test_emcee_hammer_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_emcee_hammer_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnBanana( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=2000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_emcee_hammer_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=4000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_emcee_hammer_on_annulus(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnAnnulus( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=2000 - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_emcee_hammer_on_multimodal_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnMultimodalGaussian( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_emcee_hammer_on_cone(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnCone( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/emcee_hammer_mcmc.py b/pints/functionaltests/emcee_hammer_mcmc.py new file mode 100644 index 000000000..cc36eecee --- /dev/null +++ b/pints/functionaltests/emcee_hammer_mcmc.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 +# +# Functional tests for EmceeHammerMCMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=10000, n_warmup=1000): + """ + Tests :class:`pints.EmceeHammerMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 10, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=10000, n_warmup=2000): + """ + Tests :class:`pints.EmceeHammerMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 10, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def correlated_gaussian(n_iterations=8000, n_warmup=4000): + """ + Tests :class:`pints.EmceeHammerMCMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + _method, 10, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def annulus(n_iterations=4000, n_warmup=2000): + """ + Tests :class:`pints.EmceeHammerMCMC` + on a two-dimensional annulus distribution with radius 10, and returns a + dictionary with entries ``distance`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. + """ + problem = ft.RunMcmcMethodOnAnnulus( + _method, 10, n_iterations, n_warmup) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def multimodal_gaussian(n_iterations=10000, n_warmup=1000): + """ + Tests :class:`pints.EmceeHammerMCMC` + on a two-dimensional multi-modal Gaussian distribution with modes at + ``[0, 0]``, ``[5, 10]``, and ``[10, 0]``, and returns a dict with entries + "kld" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. + """ + problem = ft.RunMcmcMethodOnMultimodalGaussian( + _method, 10, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def cone(n_iterations=10000, n_warmup=1000): + """ + Tests :class:`pints.EmceeHammerMCMC` + on a two-dimensional cone distribution centered at ``[0, 0]``, and returns + a dict with entries "distance" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCone`. + """ + problem = ft.RunMcmcMethodOnCone( + _method, 10, n_iterations, n_warmup) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.EmceeHammerMCMC +_functional_tests = [ + annulus, + banana, + cone, + correlated_gaussian, + multimodal_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/haario_acmc.py b/pints/functionaltests/haario_acmc.py index 2a24497ae..b3adfeb47 100644 --- a/pints/functionaltests/haario_acmc.py +++ b/pints/functionaltests/haario_acmc.py @@ -1,62 +1,71 @@ #!/usr/bin/env python3 # +# Functional tests for HaarioACMC +# # This file is part of PINTS (https://github.com/pints-team/pints/) which is # released under the BSD 3-clause license. See accompanying LICENSE.md for # copyright notice and full license details. # - -from __future__ import division - import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian) +import pints.functionaltests as ft -def test_haario_acmc_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.HaarioACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000 - ) +def two_dim_gaussian(n_iterations=4000, n_warmup=1000): + """ + Tests :class:`pints.HaarioACMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } -def test_haario_acmc_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnBanana( - method=pints.HaarioACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000 - ) +def banana(n_iterations=4000, n_warmup=1000): + """ + Tests :class:`pints.HaarioACMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } -def test_haario_acmc_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.HaarioACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=4000 - ) +def correlated_gaussian(n_iterations=8000, n_warmup=4000): + """ + Tests :class:`pints.HaarioACMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } + + +_method = pints.HaarioACMC +_functional_tests = [ + banana, + correlated_gaussian, + two_dim_gaussian, +] + diff --git a/pints/functionaltests/haario_bardenet_acmc.py b/pints/functionaltests/haario_bardenet_acmc.py index 15b0ac090..b55dcf68e 100644 --- a/pints/functionaltests/haario_bardenet_acmc.py +++ b/pints/functionaltests/haario_bardenet_acmc.py @@ -1,79 +1,88 @@ #!/usr/bin/env python3 # +# Functional tests for HaarioBardenetACMC +# # This file is part of PINTS (https://github.com/pints-team/pints/) which is # released under the BSD 3-clause license. See accompanying LICENSE.md for # copyright notice and full license details. # - -from __future__ import division - import pints +import pints.functionaltests as ft -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus) +def two_dim_gaussian(n_iterations=4000, n_warmup=1000): + """ + Tests :class:`pints.HaarioBardenetACMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. -def test_haario_bardenet_acmc_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.HaarioBardenetACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000 - ) - + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } -def test_haario_bardenet_acmc_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnBanana( - method=pints.HaarioBardenetACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000 - ) +def banana(n_iterations=4000, n_warmup=1000): + """ + Tests :class:`pints.HaarioBardenetACMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } -def test_haario_bardenet_acmc_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.HaarioBardenetACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=4000 - ) +def correlated_gaussian(n_iterations=8000, n_warmup=4000): + """ + Tests :class:`pints.HaarioBardenetACMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } -def test_haario_bardenet_acmc_on_annulus(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnAnnulus( - method=pints.HaarioBardenetACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=2000 - ) +def annulus(n_iterations=4000, n_warmup=2000): + """ + Tests :class:`pints.HaarioBardenetACMC` + on a two-dimensional annulus distribution with radius 10, and returns a + dictionary with entries ``distance`` and ``mean-ess``. + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. + """ + problem = ft.RunMcmcMethodOnAnnulus( + _method, 4, n_iterations, n_warmup) return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() } + + +_method = pints.HaarioBardenetACMC +_functional_tests = [ + annulus, + banana, + correlated_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/hamiltonian.py b/pints/functionaltests/hamiltonian.py deleted file mode 100644 index 357d1a500..000000000 --- a/pints/functionaltests/hamiltonian.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian) - - -def test_hamiltonian_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 1000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.HamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=200, - method_hyper_parameters=[20, 1] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_hamiltonian_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnBanana( - method=pints.HamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000, - method_hyper_parameters=[20, 2] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_hamiltonian_on_high_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnHighDimensionalGaussian( - method=pints.HamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000, - method_hyper_parameters=[20, 1] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/hamiltonian_mcmc.py b/pints/functionaltests/hamiltonian_mcmc.py new file mode 100644 index 000000000..43cf4ab57 --- /dev/null +++ b/pints/functionaltests/hamiltonian_mcmc.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# +# Functional tests for HamiltonianMCMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=1000, n_warmup=200): + """ + Tests :class:`pints.HamiltonianMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=2000, n_warmup=1000): + """ + Tests :class:`pints.HamiltonianMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 2] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def high_dim_gaussian(n_iterations=4000, n_warmup=1000): + """ + Tests :class:`pints.HamiltonianMCMC` + on a 20-dimensional Gaussian distribution centered at the origin, and + returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. + """ + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.HamiltonianMCMC +_functional_tests = [ + banana, + high_dim_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/mala_mcmc.py b/pints/functionaltests/mala_mcmc.py index 7ee97b35a..5bd8c28ad 100644 --- a/pints/functionaltests/mala_mcmc.py +++ b/pints/functionaltests/mala_mcmc.py @@ -1,65 +1,73 @@ #!/usr/bin/env python3 # +# Functional tests for MALA MCMC +# # This file is part of PINTS (https://github.com/pints-team/pints/) which is # released under the BSD 3-clause license. See accompanying LICENSE.md for # copyright notice and full license details. # - -from __future__ import division - import pints +import pints.functionaltests as ft -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnCone) +def two_dim_gaussian(n_iterations=1000, n_warmup=200): + """ + Tests :class:`pints.MALAMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. -def test_mala_mcmc_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 1000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.MALAMCMC, + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + method=_method, n_chains=4, n_iterations=n_iterations, - n_warmup=200, + n_warmup=n_warmup, method_hyper_parameters=[[1.0, 1.0]] ) - return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } -def test_mala_mcmc_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnBanana( - method=pints.MALAMCMC, +def banana(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MALAMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + method=_method, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[[0.8] * 2] ) - return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } -def test_mala_mcmc_on_high_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnHighDimensionalGaussian( - method=pints.MALAMCMC, +def high_dim_gaussian(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MALAMCMC` + on a 20-dimensional Gaussian distribution centered at the origin, and + returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. + """ + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( + method=_method, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[[1.2] * 20] ) @@ -69,69 +77,103 @@ def test_mala_mcmc_on_high_dim_gaussian(n_iterations=None): } -def test_mala_mcmc_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.MALAMCMC, +def correlated_gaussian(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MALAMCMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + method=_method, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[[1.0] * 6] ) - return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } -def test_mala_mcmc_on_annulus(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnAnnulus( - method=pints.MALAMCMC, +def annulus(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MALAMCMC` + on a two-dimensional annulus distribution with radius 10, and returns a + dictionary with entries ``distance`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. + """ + problem = ft.RunMcmcMethodOnAnnulus( + method=_method, n_chains=4, n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[[1.2] * 2] + n_warmup=n_warmup, + method_hyper_parameters=[[1.2] * 2], ) - return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() } -def test_mala_mcmc_on_multimodal_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnMultimodalGaussian( - method=pints.MALAMCMC, +def multimodal_gaussian(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MALAMCMC` + on a two-dimensional multi-modal Gaussian distribution with modes at + ``[0, 0]``, ``[5, 10]``, and ``[10, 0]``, and returns a dict with entries + "kld" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. + """ + problem = ft.RunMcmcMethodOnMultimodalGaussian( + method=_method, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[[2.0] * 2] ) - return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() } -def test_mala_mcmc_on_cone(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnCone( - method=pints.MALAMCMC, +def cone(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MALAMCMC` + on a two-dimensional cone distribution centered at ``[0, 0]``, and returns + a dict with entries "distance" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCone`. + """ + problem = ft.RunMcmcMethodOnCone( + method=_method, n_chains=4, n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[[1.0, 1.0]] + n_warmup=n_warmup, + method_hyper_parameters=[[1.0, 1.0]], ) - return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() } + + +_method = pints.MALAMCMC +_functional_tests = [ + annulus, + banana, + cone, + correlated_gaussian, + high_dim_gaussian, + multimodal_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/metropolis.py b/pints/functionaltests/metropolis.py deleted file mode 100644 index f05a87ffd..000000000 --- a/pints/functionaltests/metropolis.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian) - - -def test_metropolis_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.MetropolisRandomWalkMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_metropolis_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnBanana( - method=pints.MetropolisRandomWalkMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_metropolis_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.MetropolisRandomWalkMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=4000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/metropolis_random_walk_mcmc.py b/pints/functionaltests/metropolis_random_walk_mcmc.py new file mode 100644 index 000000000..e920a3368 --- /dev/null +++ b/pints/functionaltests/metropolis_random_walk_mcmc.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +# +# Functional tests for MetropolisRandomWalkMCMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=4000, n_warmup=1000): + """ + Tests :class:`pints.MetropolisRandomWalkMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=4000, n_warmup=1000): + """ + Tests :class:`pints.MetropolisRandomWalkMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def correlated_gaussian(n_iterations=8000, n_warmup=4000): + """ + Tests :class:`pints.MetropolisRandomWalkMCMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.MetropolisRandomWalkMCMC +_functional_tests = [ + banana, + correlated_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/monomial_gamma_hamiltonian.py b/pints/functionaltests/monomial_gamma_hamiltonian.py deleted file mode 100644 index 1ef623106..000000000 --- a/pints/functionaltests/monomial_gamma_hamiltonian.py +++ /dev/null @@ -1,137 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnCone) - - -def test_monomial_gamma_hamiltonian_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 1000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.MonomialGammaHamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=200, - method_hyper_parameters=[20, 1, 0.5, 0.2, 1] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_monomial_gamma_hamiltonian_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnBanana( - method=pints.MonomialGammaHamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.5, 0.2, 1] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_monomial_gamma_hamiltonian_on_high_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnHighDimensionalGaussian( - method=pints.MonomialGammaHamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.5, 0.2, 1] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_monomial_gamma_hamiltonian_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.MonomialGammaHamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.5, 0.2, 1] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_monomial_gamma_hamiltonian_on_annulus(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnAnnulus( - method=pints.MonomialGammaHamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.5, 0.2, 1] - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_monomial_gamma_hamiltonian_on_multimodal_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnMultimodalGaussian( - method=pints.MonomialGammaHamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.5, 0.2, 1] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_monomial_gamma_hamiltonian_on_cone(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnCone( - method=pints.MonomialGammaHamiltonianMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.5, 0.2, 1] - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py new file mode 100644 index 000000000..1048a2152 --- /dev/null +++ b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py @@ -0,0 +1,178 @@ +#!/usr/bin/env python3 +# +# Functional tests for MonomialGammaHamiltonianMCMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=1000, n_warmup=200): + """ + Tests :class:`pints.MonomialGammaHamiltonianMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.5, 0.2, 1] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MonomialGammaHamiltonianMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.5, 0.2, 1] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def high_dim_gaussian(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MonomialGammaHamiltonianMCMC` + on a 20-dimensional Gaussian distribution centered at the origin, and + returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. + """ + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.5, 0.2, 1] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def correlated_gaussian(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MonomialGammaHamiltonianMCMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.5, 0.2, 1] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def annulus(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MonomialGammaHamiltonianMCMC` + on a two-dimensional annulus distribution with radius 10, and returns a + dictionary with entries ``distance`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. + """ + problem = ft.RunMcmcMethodOnAnnulus( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.5, 0.2, 1] + ) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def multimodal_gaussian(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MonomialGammaHamiltonianMCMC` + on a two-dimensional multi-modal Gaussian distribution with modes at + ``[0, 0]``, ``[5, 10]``, and ``[10, 0]``, and returns a dict with entries + "kld" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. + """ + problem = ft.RunMcmcMethodOnMultimodalGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.5, 0.2, 1] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def cone(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.MonomialGammaHamiltonianMCMC` + on a two-dimensional cone distribution centered at ``[0, 0]``, and returns + a dict with entries "distance" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCone`. + """ + problem = ft.RunMcmcMethodOnCone( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.5, 0.2, 1] + ) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.MonomialGammaHamiltonianMCMC +_functional_tests = [ + annulus, + banana, + cone, + correlated_gaussian, + high_dim_gaussian, + multimodal_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/no_u_turn_mcmc.py b/pints/functionaltests/no_u_turn_mcmc.py new file mode 100644 index 000000000..7ca868e94 --- /dev/null +++ b/pints/functionaltests/no_u_turn_mcmc.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# +# Functional tests for NoUTurnMCMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=1000, n_warmup=200): + """ + Tests :class:`pints.NoUTurnMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.NoUTurnMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def high_dim_gaussian(n_iterations=4000, n_warmup=1000): + """ + Tests :class:`pints.NoUTurnMCMC` + on a 20-dimensional Gaussian distribution centered at the origin, and + returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. + """ + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.NoUTurnMCMC +_functional_tests = [ + banana, + high_dim_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/nuts.py b/pints/functionaltests/nuts.py deleted file mode 100644 index a1fb5c409..000000000 --- a/pints/functionaltests/nuts.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian) - - -def test_nuts_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 1000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.NoUTurnMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=200 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_nuts_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnBanana( - method=pints.NoUTurnMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_nuts_on_high_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 4000 - problem = RunMcmcMethodOnHighDimensionalGaussian( - method=pints.NoUTurnMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=1000 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/population.py b/pints/functionaltests/population.py deleted file mode 100644 index cb8232edf..000000000 --- a/pints/functionaltests/population.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python3 -# -# Functional tests for Population MCMC. -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# -import pints - -from ._problems import ( - RunMcmcMethodOnBanana, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnSimpleEggBox, - RunMcmcMethodOnTwoDimGaussian, -) - - -def test_population_mcmc_on_two_dim_gaussian(n_iterations=None): - """ - Tests :class:`pints.PopulationMCMC` on a two-dimensional Gaussian with - means 0 and 0, and returns a dict with entries "kld" and "mean-ess". - - See :class:`pints - """ - if n_iterations is None: - n_iterations = 20000 - - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.PopulationMCMC, - n_chains=1, - n_iterations=n_iterations, - n_warmup=n_warmup - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_population_mcmc_on_banana(n_iterations=None): - """ - Tests :class:`pints.PopulationMCMC` on a 2-d twisted Gaussian "banana" - problem with true solution ``(0, 0)``, and returns a dict with entries - "kld" and "mean-ess". - """ - if n_iterations is None: - n_iterations = 20000 - - n_warmup = 5000 # Needs a lot of warm-up on banana! - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - - problem = RunMcmcMethodOnBanana( - method=pints.PopulationMCMC, - n_chains=1, - n_iterations=n_iterations, - n_warmup=n_warmup - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_population_mcmc_on_multimodal_gaussian( - n_iterations=None, n_temperatures=None): - """ - Tests :class:`pints.PopulationMCMC` on a multi-modal Gaussian distribution - with modes at ``[0, 0]``, ``[5, 10]``, and ``[10, 0]``, and returns a dict - with entries "kld" and "mean-ess". - """ - if n_iterations is None: - n_iterations = 20000 - - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - - method_hyper_parameters = None - if n_temperatures is not None: - method_hyper_parameters = [n_temperatures] - - problem = RunMcmcMethodOnMultimodalGaussian( - method=pints.PopulationMCMC, - n_chains=1, - n_iterations=n_iterations, - n_warmup=n_warmup, - method_hyper_parameters=method_hyper_parameters, - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - diff --git a/pints/functionaltests/population_mcmc.py b/pints/functionaltests/population_mcmc.py new file mode 100644 index 000000000..f525d40fb --- /dev/null +++ b/pints/functionaltests/population_mcmc.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +# +# Functional tests for Population MCMC. +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=20000, n_warmup=500): + """ + Tests :class:`pints.PopulationMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 1, n_iterations, n_warmup) + + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=20000, n_warmup=5000): + """ + Tests :class:`pints.PopulationMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 1, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def multimodal_gaussian( + n_iterations=20000, n_warmup=500, n_temperatures=None): + """ + Tests :class:`pints.PopulationMCMC` + on a two-dimensional multi-modal Gaussian distribution with modes at + ``[0, 0]``, ``[5, 10]``, and ``[10, 0]``, and returns a dict with entries + "kld" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. + """ + method_hyper_parameters = None + if n_temperatures is not None: + method_hyper_parameters = [n_temperatures] + + problem = ft.RunMcmcMethodOnMultimodalGaussian( + method=_method, + n_chains=1, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=method_hyper_parameters, + ) + + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.PopulationMCMC +_functional_tests = [ + banana, + multimodal_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/relativistic.py b/pints/functionaltests/relativistic.py deleted file mode 100644 index bad99e78e..000000000 --- a/pints/functionaltests/relativistic.py +++ /dev/null @@ -1,137 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnCone) - - -def test_relativistic_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 1000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.RelativisticMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=200, - method_hyper_parameters=[20, 1, 0.1, 10] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_relativistic_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnBanana( - method=pints.RelativisticMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.1, 10] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_relativistic_on_high_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnHighDimensionalGaussian( - method=pints.RelativisticMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.1, 10] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_relativistic_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.RelativisticMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.1, 10] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_relativistic_on_annulus(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnAnnulus( - method=pints.RelativisticMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.1, 10] - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_relativistic_on_multimodal_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnMultimodalGaussian( - method=pints.RelativisticMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.1, 10] - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_relativistic_on_cone(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnCone( - method=pints.RelativisticMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500, - method_hyper_parameters=[20, 1, 0.1, 10] - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/relativistic_mcmc.py b/pints/functionaltests/relativistic_mcmc.py new file mode 100644 index 000000000..bbace567d --- /dev/null +++ b/pints/functionaltests/relativistic_mcmc.py @@ -0,0 +1,178 @@ +#!/usr/bin/env python3 +# +# Functional tests for RelativisticMCMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=1000, n_warmup=200): + """ + Tests :class:`pints.RelativisticMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.1, 10] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.RelativisticMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.1, 10] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def high_dim_gaussian(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.RelativisticMCMC` + on a 20-dimensional Gaussian distribution centered at the origin, and + returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. + """ + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.1, 10] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def correlated_gaussian(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.RelativisticMCMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.1, 10] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def annulus(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.RelativisticMCMC` + on a two-dimensional annulus distribution with radius 10, and returns a + dictionary with entries ``distance`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. + """ + problem = ft.RunMcmcMethodOnAnnulus( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.1, 10] + ) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def multimodal_gaussian(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.RelativisticMCMC` + on a two-dimensional multi-modal Gaussian distribution with modes at + ``[0, 0]``, ``[5, 10]``, and ``[10, 0]``, and returns a dict with entries + "kld" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. + """ + problem = ft.RunMcmcMethodOnMultimodalGaussian( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.1, 10] + ) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def cone(n_iterations=2000, n_warmup=500): + """ + Tests :class:`pints.RelativisticMCMC` + on a two-dimensional cone distribution centered at ``[0, 0]``, and returns + a dict with entries "distance" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCone`. + """ + problem = ft.RunMcmcMethodOnCone( + method=_method, + n_chains=4, + n_iterations=n_iterations, + n_warmup=n_warmup, + method_hyper_parameters=[20, 1, 0.1, 10] + ) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.RelativisticMCMC +_functional_tests = [ + annulus, + banana, + cone, + correlated_gaussian, + high_dim_gaussian, + multimodal_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/slice_stepout.py b/pints/functionaltests/slice_stepout.py deleted file mode 100644 index 9ca5af476..000000000 --- a/pints/functionaltests/slice_stepout.py +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env python3 -# -# This file is part of PINTS (https://github.com/pints-team/pints/) which is -# released under the BSD 3-clause license. See accompanying LICENSE.md for -# copyright notice and full license details. -# - -from __future__ import division - -import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnCone) - - -def test_slice_stepout_on_two_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnTwoDimGaussian( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - -def test_slice_stepout_on_correlated_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnCorrelatedGaussian( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_slice_stepout_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnBanana( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_slice_stepout_on_high_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnHighDimensionalGaussian( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_slice_stepout_on_annulus(n_iterations=None): - if n_iterations is None: - n_iterations = 10000 - problem = RunMcmcMethodOnAnnulus( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=2000 - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_slice_stepout_on_multimodal_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnMultimodalGaussian( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500 - ) - - return { - 'kld': problem.estimate_kld(), - 'mean-ess': problem.estimate_mean_ess() - } - - -def test_slice_stepout_on_cone(n_iterations=None): - if n_iterations is None: - n_iterations = 5000 - problem = RunMcmcMethodOnCone( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=500 - ) - - return { - 'distance': problem.estimate_distance(), - 'mean-ess': problem.estimate_mean_ess() - } diff --git a/pints/functionaltests/slice_stepout_mcmc.py b/pints/functionaltests/slice_stepout_mcmc.py new file mode 100644 index 000000000..40c78b91c --- /dev/null +++ b/pints/functionaltests/slice_stepout_mcmc.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python3 +# +# Functional tests for SliceStepoutMCMC +# +# This file is part of PINTS (https://github.com/pints-team/pints/) which is +# released under the BSD 3-clause license. See accompanying LICENSE.md for +# copyright notice and full license details. +# +import pints +import pints.functionaltests as ft + + +def two_dim_gaussian(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.SliceStepoutMCMC` + on a two-dimensional Gaussian distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + problem = ft.RunMcmcMethodOnTwoDimGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def correlated_gaussian(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.SliceStepoutMCMC` + on a six-dimensional highly correlated Gaussian distribution with true + solution ``[0, 0, 0, 0, 0, 0]`` and returns a dictionary with entries + ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. + """ + problem = ft.RunMcmcMethodOnCorrelatedGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def banana(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.SliceStepoutMCMC` + on a two-dimensional "twisted Gaussian" distribution with true solution + ``[0, 0]`` and returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnBanana`. + """ + problem = ft.RunMcmcMethodOnBanana( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def high_dim_gaussian(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.SliceStepoutMCMC` + on a 20-dimensional Gaussian distribution centered at the origin, and + returns a dictionary with entries ``kld`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. + """ + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def annulus(n_iterations=10000, n_warmup=2000): + """ + Tests :class:`pints.SliceStepoutMCMC` + on a two-dimensional annulus distribution with radius 10, and returns a + dictionary with entries ``distance`` and ``mean-ess``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. + """ + problem = ft.RunMcmcMethodOnAnnulus( + _method, 4, n_iterations, n_warmup) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def multimodal_gaussian(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.SliceStepoutMCMC` + on a two-dimensional multi-modal Gaussian distribution with modes at + ``[0, 0]``, ``[5, 10]``, and ``[10, 0]``, and returns a dict with entries + "kld" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. + """ + problem = ft.RunMcmcMethodOnMultimodalGaussian( + _method, 4, n_iterations, n_warmup) + return { + 'kld': problem.estimate_kld(), + 'mean-ess': problem.estimate_mean_ess() + } + + +def cone(n_iterations=5000, n_warmup=500): + """ + Tests :class:`pints.SliceStepoutMCMC` + on a two-dimensional cone distribution centered at ``[0, 0]``, and returns + a dict with entries "distance" and "mean-ess". + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnCone`. + """ + problem = ft.RunMcmcMethodOnCone( + _method, 4, n_iterations, n_warmup) + return { + 'distance': problem.estimate_distance(), + 'mean-ess': problem.estimate_mean_ess() + } + + +_method = pints.SliceStepoutMCMC +_functional_tests = [ + annulus, + banana, + cone, + correlated_gaussian, + high_dim_gaussian, + multimodal_gaussian, + two_dim_gaussian, +]