From f1f3fda5f3c3f8fd23b228a7a4fbf0e4dbc659fa Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Wed, 11 Aug 2021 10:04:46 +0100 Subject: [PATCH 01/11] Made all functional test classes modules have names that match the methods they test (underscores instead of camelcase). --- .../{differential_evolution.py => differential_evolution_mcmc.py} | 0 pints/functionaltests/{dram.py => dram_acmc.py} | 0 pints/functionaltests/{dream.py => dream_mcmc.py} | 0 pints/functionaltests/{emcee_hammer.py => emcee_hammer_mcmc.py} | 0 pints/functionaltests/{hamiltonian.py => hamiltonian_mcmc.py} | 0 .../{metropolis.py => metropolis_random_walk_mcmc.py} | 0 ...al_gamma_hamiltonian.py => monomial_gamma_hamiltonian_mcmc.py} | 0 pints/functionaltests/{nuts.py => no_u_turn_mcmc.py} | 0 pints/functionaltests/{population.py => population_mcmc.py} | 0 pints/functionaltests/{relativistic.py => relativistic_mcmc.py} | 0 pints/functionaltests/{slice_stepout.py => slice_stepout_mcmc.py} | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename pints/functionaltests/{differential_evolution.py => differential_evolution_mcmc.py} (100%) rename pints/functionaltests/{dram.py => dram_acmc.py} (100%) rename pints/functionaltests/{dream.py => dream_mcmc.py} (100%) rename pints/functionaltests/{emcee_hammer.py => emcee_hammer_mcmc.py} (100%) rename pints/functionaltests/{hamiltonian.py => hamiltonian_mcmc.py} (100%) rename pints/functionaltests/{metropolis.py => metropolis_random_walk_mcmc.py} (100%) rename pints/functionaltests/{monomial_gamma_hamiltonian.py => monomial_gamma_hamiltonian_mcmc.py} (100%) rename pints/functionaltests/{nuts.py => no_u_turn_mcmc.py} (100%) rename pints/functionaltests/{population.py => population_mcmc.py} (100%) rename pints/functionaltests/{relativistic.py => relativistic_mcmc.py} (100%) rename pints/functionaltests/{slice_stepout.py => slice_stepout_mcmc.py} (100%) diff --git a/pints/functionaltests/differential_evolution.py b/pints/functionaltests/differential_evolution_mcmc.py similarity index 100% rename from pints/functionaltests/differential_evolution.py rename to pints/functionaltests/differential_evolution_mcmc.py diff --git a/pints/functionaltests/dram.py b/pints/functionaltests/dram_acmc.py similarity index 100% rename from pints/functionaltests/dram.py rename to pints/functionaltests/dram_acmc.py diff --git a/pints/functionaltests/dream.py b/pints/functionaltests/dream_mcmc.py similarity index 100% rename from pints/functionaltests/dream.py rename to pints/functionaltests/dream_mcmc.py diff --git a/pints/functionaltests/emcee_hammer.py b/pints/functionaltests/emcee_hammer_mcmc.py similarity index 100% rename from pints/functionaltests/emcee_hammer.py rename to pints/functionaltests/emcee_hammer_mcmc.py diff --git a/pints/functionaltests/hamiltonian.py b/pints/functionaltests/hamiltonian_mcmc.py similarity index 100% rename from pints/functionaltests/hamiltonian.py rename to pints/functionaltests/hamiltonian_mcmc.py diff --git a/pints/functionaltests/metropolis.py b/pints/functionaltests/metropolis_random_walk_mcmc.py similarity index 100% rename from pints/functionaltests/metropolis.py rename to pints/functionaltests/metropolis_random_walk_mcmc.py diff --git a/pints/functionaltests/monomial_gamma_hamiltonian.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py similarity index 100% rename from pints/functionaltests/monomial_gamma_hamiltonian.py rename to pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py diff --git a/pints/functionaltests/nuts.py b/pints/functionaltests/no_u_turn_mcmc.py similarity index 100% rename from pints/functionaltests/nuts.py rename to pints/functionaltests/no_u_turn_mcmc.py diff --git a/pints/functionaltests/population.py b/pints/functionaltests/population_mcmc.py similarity index 100% rename from pints/functionaltests/population.py rename to pints/functionaltests/population_mcmc.py diff --git a/pints/functionaltests/relativistic.py b/pints/functionaltests/relativistic_mcmc.py similarity index 100% rename from pints/functionaltests/relativistic.py rename to pints/functionaltests/relativistic_mcmc.py diff --git a/pints/functionaltests/slice_stepout.py b/pints/functionaltests/slice_stepout_mcmc.py similarity index 100% rename from pints/functionaltests/slice_stepout.py rename to pints/functionaltests/slice_stepout_mcmc.py From 30d4e44e94e731e72892f7ec8067705b92e1a927 Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Wed, 11 Aug 2021 10:09:56 +0100 Subject: [PATCH 02/11] Removed 'test_method_on' prefix from all functional tests, so they can be called as e.g. 'differential_evaluation_mcmc.two_dim_gaussian()'. --- .../functionaltests/differential_evolution_mcmc.py | 8 ++++---- pints/functionaltests/dram_acmc.py | 6 +++--- pints/functionaltests/dream_mcmc.py | 8 ++++---- pints/functionaltests/emcee_hammer_mcmc.py | 12 ++++++------ pints/functionaltests/haario_acmc.py | 6 +++--- pints/functionaltests/haario_bardenet_acmc.py | 8 ++++---- pints/functionaltests/hamiltonian_mcmc.py | 6 +++--- .../functionaltests/metropolis_random_walk_mcmc.py | 6 +++--- .../monomial_gamma_hamiltonian_mcmc.py | 14 +++++++------- pints/functionaltests/no_u_turn_mcmc.py | 6 +++--- pints/functionaltests/population_mcmc.py | 6 +++--- pints/functionaltests/relativistic_mcmc.py | 14 +++++++------- pints/functionaltests/slice_stepout_mcmc.py | 14 +++++++------- 13 files changed, 57 insertions(+), 57 deletions(-) diff --git a/pints/functionaltests/differential_evolution_mcmc.py b/pints/functionaltests/differential_evolution_mcmc.py index 9c9a63465..1824050ad 100644 --- a/pints/functionaltests/differential_evolution_mcmc.py +++ b/pints/functionaltests/differential_evolution_mcmc.py @@ -15,7 +15,7 @@ RunMcmcMethodOnAnnulus) -def test_differential_evolution_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -31,7 +31,7 @@ def test_differential_evolution_on_two_dim_gaussian(n_iterations=None): } -def test_differential_evolution_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnBanana( @@ -47,7 +47,7 @@ def test_differential_evolution_on_banana(n_iterations=None): } -def test_differential_evolution_on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnCorrelatedGaussian( @@ -63,7 +63,7 @@ def test_differential_evolution_on_correlated_gaussian(n_iterations=None): } -def test_differential_evolution_on_annulus(n_iterations=None): +def annulus(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnAnnulus( diff --git a/pints/functionaltests/dram_acmc.py b/pints/functionaltests/dram_acmc.py index cdc3b133b..2439106c7 100644 --- a/pints/functionaltests/dram_acmc.py +++ b/pints/functionaltests/dram_acmc.py @@ -14,7 +14,7 @@ RunMcmcMethodOnBanana) -def test_dram_acmc_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -30,7 +30,7 @@ def test_dram_acmc_on_two_dim_gaussian(n_iterations=None): } -def test_haario_acmc_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnBanana( @@ -46,7 +46,7 @@ def test_haario_acmc_on_banana(n_iterations=None): } -def test_dram_acmc_on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 problem = RunMcmcMethodOnCorrelatedGaussian( diff --git a/pints/functionaltests/dream_mcmc.py b/pints/functionaltests/dream_mcmc.py index 70a9a722e..fce4eb758 100644 --- a/pints/functionaltests/dream_mcmc.py +++ b/pints/functionaltests/dream_mcmc.py @@ -15,7 +15,7 @@ RunMcmcMethodOnAnnulus) -def test_dream_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -31,7 +31,7 @@ def test_dream_on_two_dim_gaussian(n_iterations=None): } -def test_dream_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnBanana( @@ -47,7 +47,7 @@ def test_dream_on_banana(n_iterations=None): } -def test_dream_on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnCorrelatedGaussian( @@ -63,7 +63,7 @@ def test_dream_on_correlated_gaussian(n_iterations=None): } -def test_dream_on_annulus(n_iterations=None): +def annulus(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnAnnulus( diff --git a/pints/functionaltests/emcee_hammer_mcmc.py b/pints/functionaltests/emcee_hammer_mcmc.py index b1ebb1c61..bdf64d001 100644 --- a/pints/functionaltests/emcee_hammer_mcmc.py +++ b/pints/functionaltests/emcee_hammer_mcmc.py @@ -17,7 +17,7 @@ RunMcmcMethodOnCone) -def test_emcee_hammer_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -33,7 +33,7 @@ def test_emcee_hammer_on_two_dim_gaussian(n_iterations=None): } -def test_emcee_hammer_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnBanana( @@ -49,7 +49,7 @@ def test_emcee_hammer_on_banana(n_iterations=None): } -def test_emcee_hammer_on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 problem = RunMcmcMethodOnCorrelatedGaussian( @@ -65,7 +65,7 @@ def test_emcee_hammer_on_correlated_gaussian(n_iterations=None): } -def test_emcee_hammer_on_annulus(n_iterations=None): +def annulus(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnAnnulus( @@ -81,7 +81,7 @@ def test_emcee_hammer_on_annulus(n_iterations=None): } -def test_emcee_hammer_on_multimodal_gaussian(n_iterations=None): +def multimodal_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnMultimodalGaussian( @@ -97,7 +97,7 @@ def test_emcee_hammer_on_multimodal_gaussian(n_iterations=None): } -def test_emcee_hammer_on_cone(n_iterations=None): +def cone(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnCone( diff --git a/pints/functionaltests/haario_acmc.py b/pints/functionaltests/haario_acmc.py index 2a24497ae..ace093e18 100644 --- a/pints/functionaltests/haario_acmc.py +++ b/pints/functionaltests/haario_acmc.py @@ -14,7 +14,7 @@ RunMcmcMethodOnCorrelatedGaussian) -def test_haario_acmc_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -30,7 +30,7 @@ def test_haario_acmc_on_two_dim_gaussian(n_iterations=None): } -def test_haario_acmc_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnBanana( @@ -46,7 +46,7 @@ def test_haario_acmc_on_banana(n_iterations=None): } -def test_haario_acmc_on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 problem = RunMcmcMethodOnCorrelatedGaussian( diff --git a/pints/functionaltests/haario_bardenet_acmc.py b/pints/functionaltests/haario_bardenet_acmc.py index 15b0ac090..a76f46b03 100644 --- a/pints/functionaltests/haario_bardenet_acmc.py +++ b/pints/functionaltests/haario_bardenet_acmc.py @@ -15,7 +15,7 @@ RunMcmcMethodOnAnnulus) -def test_haario_bardenet_acmc_on_two_dim_gaussian(n_iterations=None): +def on_two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -31,7 +31,7 @@ def test_haario_bardenet_acmc_on_two_dim_gaussian(n_iterations=None): } -def test_haario_bardenet_acmc_on_banana(n_iterations=None): +def on_banana(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnBanana( @@ -47,7 +47,7 @@ def test_haario_bardenet_acmc_on_banana(n_iterations=None): } -def test_haario_bardenet_acmc_on_correlated_gaussian(n_iterations=None): +def on_correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 problem = RunMcmcMethodOnCorrelatedGaussian( @@ -63,7 +63,7 @@ def test_haario_bardenet_acmc_on_correlated_gaussian(n_iterations=None): } -def test_haario_bardenet_acmc_on_annulus(n_iterations=None): +def on_annulus(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnAnnulus( diff --git a/pints/functionaltests/hamiltonian_mcmc.py b/pints/functionaltests/hamiltonian_mcmc.py index 357d1a500..5d582f573 100644 --- a/pints/functionaltests/hamiltonian_mcmc.py +++ b/pints/functionaltests/hamiltonian_mcmc.py @@ -14,7 +14,7 @@ RunMcmcMethodOnHighDimensionalGaussian) -def test_hamiltonian_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 1000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -31,7 +31,7 @@ def test_hamiltonian_on_two_dim_gaussian(n_iterations=None): } -def test_hamiltonian_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnBanana( @@ -48,7 +48,7 @@ def test_hamiltonian_on_banana(n_iterations=None): } -def test_hamiltonian_on_high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnHighDimensionalGaussian( diff --git a/pints/functionaltests/metropolis_random_walk_mcmc.py b/pints/functionaltests/metropolis_random_walk_mcmc.py index f05a87ffd..890612375 100644 --- a/pints/functionaltests/metropolis_random_walk_mcmc.py +++ b/pints/functionaltests/metropolis_random_walk_mcmc.py @@ -14,7 +14,7 @@ RunMcmcMethodOnCorrelatedGaussian) -def test_metropolis_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -30,7 +30,7 @@ def test_metropolis_on_two_dim_gaussian(n_iterations=None): } -def test_metropolis_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnBanana( @@ -46,7 +46,7 @@ def test_metropolis_on_banana(n_iterations=None): } -def test_metropolis_on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 problem = RunMcmcMethodOnCorrelatedGaussian( diff --git a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py index 1ef623106..a60c58ca2 100644 --- a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py +++ b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py @@ -18,7 +18,7 @@ RunMcmcMethodOnCone) -def test_monomial_gamma_hamiltonian_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 1000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -35,7 +35,7 @@ def test_monomial_gamma_hamiltonian_on_two_dim_gaussian(n_iterations=None): } -def test_monomial_gamma_hamiltonian_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnBanana( @@ -52,7 +52,7 @@ def test_monomial_gamma_hamiltonian_on_banana(n_iterations=None): } -def test_monomial_gamma_hamiltonian_on_high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnHighDimensionalGaussian( @@ -69,7 +69,7 @@ def test_monomial_gamma_hamiltonian_on_high_dim_gaussian(n_iterations=None): } -def test_monomial_gamma_hamiltonian_on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnCorrelatedGaussian( @@ -86,7 +86,7 @@ def test_monomial_gamma_hamiltonian_on_correlated_gaussian(n_iterations=None): } -def test_monomial_gamma_hamiltonian_on_annulus(n_iterations=None): +def annulus(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnAnnulus( @@ -103,7 +103,7 @@ def test_monomial_gamma_hamiltonian_on_annulus(n_iterations=None): } -def test_monomial_gamma_hamiltonian_on_multimodal_gaussian(n_iterations=None): +def multimodal_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnMultimodalGaussian( @@ -120,7 +120,7 @@ def test_monomial_gamma_hamiltonian_on_multimodal_gaussian(n_iterations=None): } -def test_monomial_gamma_hamiltonian_on_cone(n_iterations=None): +def cone(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnCone( diff --git a/pints/functionaltests/no_u_turn_mcmc.py b/pints/functionaltests/no_u_turn_mcmc.py index a1fb5c409..e906f2d57 100644 --- a/pints/functionaltests/no_u_turn_mcmc.py +++ b/pints/functionaltests/no_u_turn_mcmc.py @@ -14,7 +14,7 @@ RunMcmcMethodOnHighDimensionalGaussian) -def test_nuts_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 1000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -30,7 +30,7 @@ def test_nuts_on_two_dim_gaussian(n_iterations=None): } -def test_nuts_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnBanana( @@ -46,7 +46,7 @@ def test_nuts_on_banana(n_iterations=None): } -def test_nuts_on_high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 problem = RunMcmcMethodOnHighDimensionalGaussian( diff --git a/pints/functionaltests/population_mcmc.py b/pints/functionaltests/population_mcmc.py index cb8232edf..127232a29 100644 --- a/pints/functionaltests/population_mcmc.py +++ b/pints/functionaltests/population_mcmc.py @@ -16,7 +16,7 @@ ) -def test_population_mcmc_on_two_dim_gaussian(n_iterations=None): +def 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". @@ -43,7 +43,7 @@ def test_population_mcmc_on_two_dim_gaussian(n_iterations=None): } -def test_population_mcmc_on_banana(n_iterations=None): +def 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 @@ -69,7 +69,7 @@ def test_population_mcmc_on_banana(n_iterations=None): } -def test_population_mcmc_on_multimodal_gaussian( +def multimodal_gaussian( n_iterations=None, n_temperatures=None): """ Tests :class:`pints.PopulationMCMC` on a multi-modal Gaussian distribution diff --git a/pints/functionaltests/relativistic_mcmc.py b/pints/functionaltests/relativistic_mcmc.py index bad99e78e..caff98940 100644 --- a/pints/functionaltests/relativistic_mcmc.py +++ b/pints/functionaltests/relativistic_mcmc.py @@ -18,7 +18,7 @@ RunMcmcMethodOnCone) -def test_relativistic_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 1000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -35,7 +35,7 @@ def test_relativistic_on_two_dim_gaussian(n_iterations=None): } -def test_relativistic_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnBanana( @@ -52,7 +52,7 @@ def test_relativistic_on_banana(n_iterations=None): } -def test_relativistic_on_high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnHighDimensionalGaussian( @@ -69,7 +69,7 @@ def test_relativistic_on_high_dim_gaussian(n_iterations=None): } -def test_relativistic_on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnCorrelatedGaussian( @@ -86,7 +86,7 @@ def test_relativistic_on_correlated_gaussian(n_iterations=None): } -def test_relativistic_on_annulus(n_iterations=None): +def annulus(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnAnnulus( @@ -103,7 +103,7 @@ def test_relativistic_on_annulus(n_iterations=None): } -def test_relativistic_on_multimodal_gaussian(n_iterations=None): +def multimodal_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnMultimodalGaussian( @@ -120,7 +120,7 @@ def test_relativistic_on_multimodal_gaussian(n_iterations=None): } -def test_relativistic_on_cone(n_iterations=None): +def cone(n_iterations=None): if n_iterations is None: n_iterations = 2000 problem = RunMcmcMethodOnCone( diff --git a/pints/functionaltests/slice_stepout_mcmc.py b/pints/functionaltests/slice_stepout_mcmc.py index 9ca5af476..3b12358bf 100644 --- a/pints/functionaltests/slice_stepout_mcmc.py +++ b/pints/functionaltests/slice_stepout_mcmc.py @@ -18,7 +18,7 @@ RunMcmcMethodOnCone) -def test_slice_stepout_on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnTwoDimGaussian( @@ -33,7 +33,7 @@ def test_slice_stepout_on_two_dim_gaussian(n_iterations=None): 'mean-ess': problem.estimate_mean_ess() } -def test_slice_stepout_on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnCorrelatedGaussian( @@ -49,7 +49,7 @@ def test_slice_stepout_on_correlated_gaussian(n_iterations=None): } -def test_slice_stepout_on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnBanana( @@ -65,7 +65,7 @@ def test_slice_stepout_on_banana(n_iterations=None): } -def test_slice_stepout_on_high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnHighDimensionalGaussian( @@ -81,7 +81,7 @@ def test_slice_stepout_on_high_dim_gaussian(n_iterations=None): } -def test_slice_stepout_on_annulus(n_iterations=None): +def annulus(n_iterations=None): if n_iterations is None: n_iterations = 10000 problem = RunMcmcMethodOnAnnulus( @@ -97,7 +97,7 @@ def test_slice_stepout_on_annulus(n_iterations=None): } -def test_slice_stepout_on_multimodal_gaussian(n_iterations=None): +def multimodal_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnMultimodalGaussian( @@ -113,7 +113,7 @@ def test_slice_stepout_on_multimodal_gaussian(n_iterations=None): } -def test_slice_stepout_on_cone(n_iterations=None): +def cone(n_iterations=None): if n_iterations is None: n_iterations = 5000 problem = RunMcmcMethodOnCone( From e029413bd9005a054e3e36a1232dba6a9b3cef87 Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Wed, 11 Aug 2021 10:20:17 +0100 Subject: [PATCH 03/11] Updated the way functionaltest modules and problem classes are imported. --- pints/functionaltests/__init__.py | 38 ++++++++++++++++--- .../differential_evolution_mcmc.py | 14 +++---- pints/functionaltests/dram_acmc.py | 11 ++---- pints/functionaltests/dream_mcmc.py | 14 +++---- pints/functionaltests/emcee_hammer_mcmc.py | 20 ++++------ pints/functionaltests/haario_acmc.py | 11 ++---- pints/functionaltests/haario_bardenet_acmc.py | 22 +++++------ pints/functionaltests/hamiltonian_mcmc.py | 11 ++---- .../metropolis_random_walk_mcmc.py | 11 ++---- .../monomial_gamma_hamiltonian_mcmc.py | 23 ++++------- pints/functionaltests/no_u_turn_mcmc.py | 11 ++---- pints/functionaltests/population_mcmc.py | 14 ++----- pints/functionaltests/relativistic_mcmc.py | 23 ++++------- pints/functionaltests/slice_stepout_mcmc.py | 23 ++++------- 14 files changed, 106 insertions(+), 140 deletions(-) diff --git a/pints/functionaltests/__init__.py b/pints/functionaltests/__init__.py index a3e83e981..82931b792 100644 --- a/pints/functionaltests/__init__.py +++ b/pints/functionaltests/__init__.py @@ -1,13 +1,39 @@ # +# "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 ( + 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 ( + differential_evolution_mcmc, + dram_acmc, + dream_mcmc, + emcee_hammer_mcmc, + haario_acmc, + haario_bardenet_acmc, + hamiltonian_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 diff --git a/pints/functionaltests/differential_evolution_mcmc.py b/pints/functionaltests/differential_evolution_mcmc.py index 1824050ad..ee072b0c1 100644 --- a/pints/functionaltests/differential_evolution_mcmc.py +++ b/pints/functionaltests/differential_evolution_mcmc.py @@ -8,17 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.DifferentialEvolutionMCMC, n_chains=10, n_iterations=n_iterations, @@ -34,7 +30,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.DifferentialEvolutionMCMC, n_chains=20, n_iterations=n_iterations, @@ -50,7 +46,7 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.DifferentialEvolutionMCMC, n_chains=20, n_iterations=n_iterations, @@ -66,7 +62,7 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnAnnulus( + problem = ft.RunMcmcMethodOnAnnulus( method=pints.DifferentialEvolutionMCMC, n_chains=10, n_iterations=n_iterations, diff --git a/pints/functionaltests/dram_acmc.py b/pints/functionaltests/dram_acmc.py index 2439106c7..b461dbd5e 100644 --- a/pints/functionaltests/dram_acmc.py +++ b/pints/functionaltests/dram_acmc.py @@ -8,16 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnBanana) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.DramACMC, n_chains=4, n_iterations=n_iterations, @@ -33,7 +30,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.DramACMC, n_chains=4, n_iterations=n_iterations, @@ -49,7 +46,7 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.DramACMC, n_chains=4, n_iterations=n_iterations, diff --git a/pints/functionaltests/dream_mcmc.py b/pints/functionaltests/dream_mcmc.py index fce4eb758..ed5766837 100644 --- a/pints/functionaltests/dream_mcmc.py +++ b/pints/functionaltests/dream_mcmc.py @@ -8,17 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.DreamMCMC, n_chains=10, n_iterations=n_iterations, @@ -34,7 +30,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.DreamMCMC, n_chains=20, n_iterations=n_iterations, @@ -50,7 +46,7 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.DreamMCMC, n_chains=20, n_iterations=n_iterations, @@ -66,7 +62,7 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnAnnulus( + problem = ft.RunMcmcMethodOnAnnulus( method=pints.DreamMCMC, n_chains=10, n_iterations=n_iterations, diff --git a/pints/functionaltests/emcee_hammer_mcmc.py b/pints/functionaltests/emcee_hammer_mcmc.py index bdf64d001..c36501f11 100644 --- a/pints/functionaltests/emcee_hammer_mcmc.py +++ b/pints/functionaltests/emcee_hammer_mcmc.py @@ -8,19 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnCone) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, @@ -36,7 +30,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, @@ -52,7 +46,7 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, @@ -68,7 +62,7 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnAnnulus( + problem = ft.RunMcmcMethodOnAnnulus( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, @@ -84,7 +78,7 @@ def annulus(n_iterations=None): def multimodal_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnMultimodalGaussian( + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, @@ -100,7 +94,7 @@ def multimodal_gaussian(n_iterations=None): def cone(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnCone( + problem = ft.RunMcmcMethodOnCone( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, diff --git a/pints/functionaltests/haario_acmc.py b/pints/functionaltests/haario_acmc.py index ace093e18..75b34d540 100644 --- a/pints/functionaltests/haario_acmc.py +++ b/pints/functionaltests/haario_acmc.py @@ -8,16 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.HaarioACMC, n_chains=4, n_iterations=n_iterations, @@ -33,7 +30,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.HaarioACMC, n_chains=4, n_iterations=n_iterations, @@ -49,7 +46,7 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.HaarioACMC, n_chains=4, n_iterations=n_iterations, diff --git a/pints/functionaltests/haario_bardenet_acmc.py b/pints/functionaltests/haario_bardenet_acmc.py index a76f46b03..b8f316518 100644 --- a/pints/functionaltests/haario_bardenet_acmc.py +++ b/pints/functionaltests/haario_bardenet_acmc.py @@ -8,17 +8,13 @@ from __future__ import division import pints +import pints.functionaltests as ft -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus) - -def on_two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.HaarioBardenetACMC, n_chains=4, n_iterations=n_iterations, @@ -31,10 +27,10 @@ def on_two_dim_gaussian(n_iterations=None): } -def on_banana(n_iterations=None): +def banana(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.HaarioBardenetACMC, n_chains=4, n_iterations=n_iterations, @@ -47,10 +43,10 @@ def on_banana(n_iterations=None): } -def on_correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.HaarioBardenetACMC, n_chains=4, n_iterations=n_iterations, @@ -63,10 +59,10 @@ def on_correlated_gaussian(n_iterations=None): } -def on_annulus(n_iterations=None): +def annulus(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnAnnulus( + problem = ft.RunMcmcMethodOnAnnulus( method=pints.HaarioBardenetACMC, n_chains=4, n_iterations=n_iterations, diff --git a/pints/functionaltests/hamiltonian_mcmc.py b/pints/functionaltests/hamiltonian_mcmc.py index 5d582f573..44242d625 100644 --- a/pints/functionaltests/hamiltonian_mcmc.py +++ b/pints/functionaltests/hamiltonian_mcmc.py @@ -8,16 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 1000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.HamiltonianMCMC, n_chains=4, n_iterations=n_iterations, @@ -34,7 +31,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.HamiltonianMCMC, n_chains=4, n_iterations=n_iterations, @@ -51,7 +48,7 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnHighDimensionalGaussian( + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.HamiltonianMCMC, n_chains=4, n_iterations=n_iterations, diff --git a/pints/functionaltests/metropolis_random_walk_mcmc.py b/pints/functionaltests/metropolis_random_walk_mcmc.py index 890612375..81e4806d9 100644 --- a/pints/functionaltests/metropolis_random_walk_mcmc.py +++ b/pints/functionaltests/metropolis_random_walk_mcmc.py @@ -8,16 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnCorrelatedGaussian) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.MetropolisRandomWalkMCMC, n_chains=4, n_iterations=n_iterations, @@ -33,7 +30,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.MetropolisRandomWalkMCMC, n_chains=4, n_iterations=n_iterations, @@ -49,7 +46,7 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 8000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.MetropolisRandomWalkMCMC, n_chains=4, n_iterations=n_iterations, diff --git a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py index a60c58ca2..7ee3e0fc1 100644 --- a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py +++ b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py @@ -8,20 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnCone) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 1000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, @@ -38,7 +31,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, @@ -55,7 +48,7 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnHighDimensionalGaussian( + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, @@ -72,7 +65,7 @@ def high_dim_gaussian(n_iterations=None): def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, @@ -89,7 +82,7 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnAnnulus( + problem = ft.RunMcmcMethodOnAnnulus( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, @@ -106,7 +99,7 @@ def annulus(n_iterations=None): def multimodal_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnMultimodalGaussian( + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, @@ -123,7 +116,7 @@ def multimodal_gaussian(n_iterations=None): def cone(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnCone( + problem = ft.RunMcmcMethodOnCone( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, diff --git a/pints/functionaltests/no_u_turn_mcmc.py b/pints/functionaltests/no_u_turn_mcmc.py index e906f2d57..ffaa3c33d 100644 --- a/pints/functionaltests/no_u_turn_mcmc.py +++ b/pints/functionaltests/no_u_turn_mcmc.py @@ -8,16 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 1000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.NoUTurnMCMC, n_chains=4, n_iterations=n_iterations, @@ -33,7 +30,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.NoUTurnMCMC, n_chains=4, n_iterations=n_iterations, @@ -49,7 +46,7 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 4000 - problem = RunMcmcMethodOnHighDimensionalGaussian( + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.NoUTurnMCMC, n_chains=4, n_iterations=n_iterations, diff --git a/pints/functionaltests/population_mcmc.py b/pints/functionaltests/population_mcmc.py index 127232a29..7609cddec 100644 --- a/pints/functionaltests/population_mcmc.py +++ b/pints/functionaltests/population_mcmc.py @@ -7,13 +7,7 @@ # copyright notice and full license details. # import pints - -from ._problems import ( - RunMcmcMethodOnBanana, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnSimpleEggBox, - RunMcmcMethodOnTwoDimGaussian, -) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): @@ -30,7 +24,7 @@ def two_dim_gaussian(n_iterations=None): if n_warmup > n_iterations // 2: n_warmup = n_iterations // 10 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.PopulationMCMC, n_chains=1, n_iterations=n_iterations, @@ -56,7 +50,7 @@ def banana(n_iterations=None): if n_warmup > n_iterations // 2: n_warmup = n_iterations // 10 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.PopulationMCMC, n_chains=1, n_iterations=n_iterations, @@ -87,7 +81,7 @@ def multimodal_gaussian( if n_temperatures is not None: method_hyper_parameters = [n_temperatures] - problem = RunMcmcMethodOnMultimodalGaussian( + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.PopulationMCMC, n_chains=1, n_iterations=n_iterations, diff --git a/pints/functionaltests/relativistic_mcmc.py b/pints/functionaltests/relativistic_mcmc.py index caff98940..7b9fe3f4f 100644 --- a/pints/functionaltests/relativistic_mcmc.py +++ b/pints/functionaltests/relativistic_mcmc.py @@ -8,20 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnCone) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 1000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, @@ -38,7 +31,7 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, @@ -55,7 +48,7 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnHighDimensionalGaussian( + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, @@ -72,7 +65,7 @@ def high_dim_gaussian(n_iterations=None): def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, @@ -89,7 +82,7 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnAnnulus( + problem = ft.RunMcmcMethodOnAnnulus( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, @@ -106,7 +99,7 @@ def annulus(n_iterations=None): def multimodal_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnMultimodalGaussian( + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, @@ -123,7 +116,7 @@ def multimodal_gaussian(n_iterations=None): def cone(n_iterations=None): if n_iterations is None: n_iterations = 2000 - problem = RunMcmcMethodOnCone( + problem = ft.RunMcmcMethodOnCone( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, diff --git a/pints/functionaltests/slice_stepout_mcmc.py b/pints/functionaltests/slice_stepout_mcmc.py index 3b12358bf..9e54663a3 100644 --- a/pints/functionaltests/slice_stepout_mcmc.py +++ b/pints/functionaltests/slice_stepout_mcmc.py @@ -8,20 +8,13 @@ from __future__ import division import pints - -from ._problems import (RunMcmcMethodOnTwoDimGaussian, - RunMcmcMethodOnBanana, - RunMcmcMethodOnHighDimensionalGaussian, - RunMcmcMethodOnCorrelatedGaussian, - RunMcmcMethodOnAnnulus, - RunMcmcMethodOnMultimodalGaussian, - RunMcmcMethodOnCone) +import pints.functionaltests as ft def two_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnTwoDimGaussian( + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, @@ -36,7 +29,7 @@ def two_dim_gaussian(n_iterations=None): def correlated_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnCorrelatedGaussian( + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, @@ -52,7 +45,7 @@ def correlated_gaussian(n_iterations=None): def banana(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnBanana( + problem = ft.RunMcmcMethodOnBanana( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, @@ -68,7 +61,7 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnHighDimensionalGaussian( + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, @@ -84,7 +77,7 @@ def high_dim_gaussian(n_iterations=None): def annulus(n_iterations=None): if n_iterations is None: n_iterations = 10000 - problem = RunMcmcMethodOnAnnulus( + problem = ft.RunMcmcMethodOnAnnulus( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, @@ -100,7 +93,7 @@ def annulus(n_iterations=None): def multimodal_gaussian(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnMultimodalGaussian( + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, @@ -116,7 +109,7 @@ def multimodal_gaussian(n_iterations=None): def cone(n_iterations=None): if n_iterations is None: n_iterations = 5000 - problem = RunMcmcMethodOnCone( + problem = ft.RunMcmcMethodOnCone( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, From c83bfc3c44b7f3ae693073c5a0a7552d71ec47ed Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Wed, 11 Aug 2021 10:21:32 +0100 Subject: [PATCH 04/11] Removed 'from __future__' imports. --- pints/functionaltests/differential_evolution_mcmc.py | 3 --- pints/functionaltests/dram_acmc.py | 3 --- pints/functionaltests/dream_mcmc.py | 3 --- pints/functionaltests/emcee_hammer_mcmc.py | 3 --- pints/functionaltests/haario_acmc.py | 3 --- pints/functionaltests/haario_bardenet_acmc.py | 3 --- pints/functionaltests/hamiltonian_mcmc.py | 3 --- pints/functionaltests/metropolis_random_walk_mcmc.py | 3 --- pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py | 3 --- pints/functionaltests/no_u_turn_mcmc.py | 3 --- pints/functionaltests/relativistic_mcmc.py | 3 --- pints/functionaltests/slice_stepout_mcmc.py | 3 --- 12 files changed, 36 deletions(-) diff --git a/pints/functionaltests/differential_evolution_mcmc.py b/pints/functionaltests/differential_evolution_mcmc.py index ee072b0c1..c9b90e7db 100644 --- a/pints/functionaltests/differential_evolution_mcmc.py +++ b/pints/functionaltests/differential_evolution_mcmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/dram_acmc.py b/pints/functionaltests/dram_acmc.py index b461dbd5e..927a53d32 100644 --- a/pints/functionaltests/dram_acmc.py +++ b/pints/functionaltests/dram_acmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/dream_mcmc.py b/pints/functionaltests/dream_mcmc.py index ed5766837..b8e397e7e 100644 --- a/pints/functionaltests/dream_mcmc.py +++ b/pints/functionaltests/dream_mcmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/emcee_hammer_mcmc.py b/pints/functionaltests/emcee_hammer_mcmc.py index c36501f11..23f6aa5b5 100644 --- a/pints/functionaltests/emcee_hammer_mcmc.py +++ b/pints/functionaltests/emcee_hammer_mcmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/haario_acmc.py b/pints/functionaltests/haario_acmc.py index 75b34d540..aeda0e9ad 100644 --- a/pints/functionaltests/haario_acmc.py +++ b/pints/functionaltests/haario_acmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/haario_bardenet_acmc.py b/pints/functionaltests/haario_bardenet_acmc.py index b8f316518..84cbc7080 100644 --- a/pints/functionaltests/haario_bardenet_acmc.py +++ b/pints/functionaltests/haario_bardenet_acmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/hamiltonian_mcmc.py b/pints/functionaltests/hamiltonian_mcmc.py index 44242d625..5fe7435be 100644 --- a/pints/functionaltests/hamiltonian_mcmc.py +++ b/pints/functionaltests/hamiltonian_mcmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/metropolis_random_walk_mcmc.py b/pints/functionaltests/metropolis_random_walk_mcmc.py index 81e4806d9..a03fbacb7 100644 --- a/pints/functionaltests/metropolis_random_walk_mcmc.py +++ b/pints/functionaltests/metropolis_random_walk_mcmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py index 7ee3e0fc1..f99edf9a9 100644 --- a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py +++ b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/no_u_turn_mcmc.py b/pints/functionaltests/no_u_turn_mcmc.py index ffaa3c33d..772a3ad94 100644 --- a/pints/functionaltests/no_u_turn_mcmc.py +++ b/pints/functionaltests/no_u_turn_mcmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/relativistic_mcmc.py b/pints/functionaltests/relativistic_mcmc.py index 7b9fe3f4f..a45428e6c 100644 --- a/pints/functionaltests/relativistic_mcmc.py +++ b/pints/functionaltests/relativistic_mcmc.py @@ -4,9 +4,6 @@ # 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 diff --git a/pints/functionaltests/slice_stepout_mcmc.py b/pints/functionaltests/slice_stepout_mcmc.py index 9e54663a3..5d7268239 100644 --- a/pints/functionaltests/slice_stepout_mcmc.py +++ b/pints/functionaltests/slice_stepout_mcmc.py @@ -4,9 +4,6 @@ # 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 3edbeb1021be5b78d7422329f853289d5a22ad88 Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Wed, 11 Aug 2021 12:10:07 +0100 Subject: [PATCH 05/11] Added docstrings to functional tests. --- pints/functionaltests/_problems.py | 94 +++++++++++++++---- .../differential_evolution_mcmc.py | 35 +++++++ pints/functionaltests/dram_acmc.py | 29 +++++- pints/functionaltests/dream_mcmc.py | 35 +++++++ pints/functionaltests/emcee_hammer_mcmc.py | 52 ++++++++++ pints/functionaltests/haario_acmc.py | 27 ++++++ pints/functionaltests/haario_bardenet_acmc.py | 35 +++++++ pints/functionaltests/hamiltonian_mcmc.py | 26 +++++ .../metropolis_random_walk_mcmc.py | 27 ++++++ .../monomial_gamma_hamiltonian_mcmc.py | 60 ++++++++++++ pints/functionaltests/no_u_turn_mcmc.py | 26 +++++ pints/functionaltests/population_mcmc.py | 31 +++--- pints/functionaltests/relativistic_mcmc.py | 60 ++++++++++++ pints/functionaltests/slice_stepout_mcmc.py | 60 ++++++++++++ 14 files changed, 567 insertions(+), 30 deletions(-) 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_mcmc.py b/pints/functionaltests/differential_evolution_mcmc.py index c9b90e7db..cd15f36a2 100644 --- a/pints/functionaltests/differential_evolution_mcmc.py +++ b/pints/functionaltests/differential_evolution_mcmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -25,6 +35,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnBanana( @@ -41,6 +59,15 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( @@ -57,6 +84,14 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnAnnulus( diff --git a/pints/functionaltests/dram_acmc.py b/pints/functionaltests/dram_acmc.py index 927a53d32..61faa771c 100644 --- a/pints/functionaltests/dram_acmc.py +++ b/pints/functionaltests/dram_acmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,15 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ + if n_iterations is None: n_iterations = 8000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -25,7 +36,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): - if n_iterations is None: + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnBanana( method=pints.DramACMC, @@ -41,6 +59,15 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 8000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( diff --git a/pints/functionaltests/dream_mcmc.py b/pints/functionaltests/dream_mcmc.py index b8e397e7e..db2c5afe2 100644 --- a/pints/functionaltests/dream_mcmc.py +++ b/pints/functionaltests/dream_mcmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -25,6 +35,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnBanana( @@ -41,6 +59,15 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( @@ -57,6 +84,14 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnAnnulus( diff --git a/pints/functionaltests/emcee_hammer_mcmc.py b/pints/functionaltests/emcee_hammer_mcmc.py index 23f6aa5b5..25570d862 100644 --- a/pints/functionaltests/emcee_hammer_mcmc.py +++ b/pints/functionaltests/emcee_hammer_mcmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -25,6 +35,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnBanana( @@ -41,6 +59,15 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 8000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( @@ -57,6 +84,14 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnAnnulus( @@ -73,6 +108,15 @@ def annulus(n_iterations=None): def multimodal_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnMultimodalGaussian( @@ -89,6 +133,14 @@ def multimodal_gaussian(n_iterations=None): def cone(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnCone( diff --git a/pints/functionaltests/haario_acmc.py b/pints/functionaltests/haario_acmc.py index aeda0e9ad..7808bc113 100644 --- a/pints/functionaltests/haario_acmc.py +++ b/pints/functionaltests/haario_acmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -25,6 +35,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnBanana( @@ -41,6 +59,15 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 8000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( diff --git a/pints/functionaltests/haario_bardenet_acmc.py b/pints/functionaltests/haario_bardenet_acmc.py index 84cbc7080..5aed19f84 100644 --- a/pints/functionaltests/haario_bardenet_acmc.py +++ b/pints/functionaltests/haario_bardenet_acmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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``. + + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -25,6 +35,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnBanana( @@ -41,6 +59,15 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 8000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( @@ -57,6 +84,14 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnAnnulus( diff --git a/pints/functionaltests/hamiltonian_mcmc.py b/pints/functionaltests/hamiltonian_mcmc.py index 5fe7435be..f987a37e3 100644 --- a/pints/functionaltests/hamiltonian_mcmc.py +++ b/pints/functionaltests/hamiltonian_mcmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 1000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -26,6 +36,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnBanana( @@ -43,6 +61,14 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnHighDimensionalGaussian( diff --git a/pints/functionaltests/metropolis_random_walk_mcmc.py b/pints/functionaltests/metropolis_random_walk_mcmc.py index a03fbacb7..7f89340ab 100644 --- a/pints/functionaltests/metropolis_random_walk_mcmc.py +++ b/pints/functionaltests/metropolis_random_walk_mcmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -25,6 +35,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnBanana( @@ -41,6 +59,15 @@ def banana(n_iterations=None): def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 8000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( diff --git a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py index f99edf9a9..c8424921a 100644 --- a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py +++ b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 1000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -26,6 +36,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnBanana( @@ -43,6 +61,14 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnHighDimensionalGaussian( @@ -60,6 +86,15 @@ def high_dim_gaussian(n_iterations=None): def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( @@ -77,6 +112,14 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnAnnulus( @@ -94,6 +137,15 @@ def annulus(n_iterations=None): def multimodal_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnMultimodalGaussian( @@ -111,6 +163,14 @@ def multimodal_gaussian(n_iterations=None): def cone(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnCone( diff --git a/pints/functionaltests/no_u_turn_mcmc.py b/pints/functionaltests/no_u_turn_mcmc.py index 772a3ad94..57b4da914 100644 --- a/pints/functionaltests/no_u_turn_mcmc.py +++ b/pints/functionaltests/no_u_turn_mcmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 1000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -25,6 +35,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnBanana( @@ -41,6 +59,14 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 4000 problem = ft.RunMcmcMethodOnHighDimensionalGaussian( diff --git a/pints/functionaltests/population_mcmc.py b/pints/functionaltests/population_mcmc.py index 7609cddec..ce7d34203 100644 --- a/pints/functionaltests/population_mcmc.py +++ b/pints/functionaltests/population_mcmc.py @@ -12,10 +12,12 @@ def 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". + 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``. - See :class:`pints + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ if n_iterations is None: n_iterations = 20000 @@ -39,10 +41,14 @@ def two_dim_gaussian(n_iterations=None): def 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". + 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`. """ + if n_iterations is None: n_iterations = 20000 @@ -63,12 +69,15 @@ def banana(n_iterations=None): } -def multimodal_gaussian( - n_iterations=None, n_temperatures=None): +def 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". + 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`. """ if n_iterations is None: n_iterations = 20000 diff --git a/pints/functionaltests/relativistic_mcmc.py b/pints/functionaltests/relativistic_mcmc.py index a45428e6c..d3acf0dcc 100644 --- a/pints/functionaltests/relativistic_mcmc.py +++ b/pints/functionaltests/relativistic_mcmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 1000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -26,6 +36,14 @@ def two_dim_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnBanana( @@ -43,6 +61,14 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnHighDimensionalGaussian( @@ -60,6 +86,15 @@ def high_dim_gaussian(n_iterations=None): def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( @@ -77,6 +112,14 @@ def correlated_gaussian(n_iterations=None): def annulus(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnAnnulus( @@ -94,6 +137,15 @@ def annulus(n_iterations=None): def multimodal_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnMultimodalGaussian( @@ -111,6 +163,14 @@ def multimodal_gaussian(n_iterations=None): def cone(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 2000 problem = ft.RunMcmcMethodOnCone( diff --git a/pints/functionaltests/slice_stepout_mcmc.py b/pints/functionaltests/slice_stepout_mcmc.py index 5d7268239..ebfcea50b 100644 --- a/pints/functionaltests/slice_stepout_mcmc.py +++ b/pints/functionaltests/slice_stepout_mcmc.py @@ -1,5 +1,7 @@ #!/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. @@ -9,6 +11,14 @@ def two_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnTwoDimGaussian( @@ -24,6 +34,15 @@ def two_dim_gaussian(n_iterations=None): } def correlated_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnCorrelatedGaussian( @@ -40,6 +59,14 @@ def correlated_gaussian(n_iterations=None): def banana(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnBanana( @@ -56,6 +83,14 @@ def banana(n_iterations=None): def high_dim_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnHighDimensionalGaussian( @@ -72,6 +107,14 @@ def high_dim_gaussian(n_iterations=None): def annulus(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 10000 problem = ft.RunMcmcMethodOnAnnulus( @@ -88,6 +131,15 @@ def annulus(n_iterations=None): def multimodal_gaussian(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnMultimodalGaussian( @@ -104,6 +156,14 @@ def multimodal_gaussian(n_iterations=None): def cone(n_iterations=None): + """ + 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`. + """ if n_iterations is None: n_iterations = 5000 problem = ft.RunMcmcMethodOnCone( From 3b0e026a67b4f9f1c227c04409a9572857bb8a7d Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Wed, 11 Aug 2021 12:32:58 +0100 Subject: [PATCH 06/11] Updated way iterations and warmup is set in functional tests. --- pints/functionaltests/__init__.py | 4 +- .../differential_evolution_mcmc.py | 40 ++++++----- pints/functionaltests/dram_acmc.py | 30 ++++---- pints/functionaltests/dream_mcmc.py | 40 ++++++----- pints/functionaltests/emcee_hammer_mcmc.py | 60 +++++++++------- pints/functionaltests/haario_acmc.py | 30 ++++---- pints/functionaltests/haario_bardenet_acmc.py | 40 ++++++----- pints/functionaltests/hamiltonian_mcmc.py | 30 ++++---- .../metropolis_random_walk_mcmc.py | 30 ++++---- .../monomial_gamma_hamiltonian_mcmc.py | 70 ++++++++++-------- pints/functionaltests/no_u_turn_mcmc.py | 30 ++++---- pints/functionaltests/population_mcmc.py | 16 +---- pints/functionaltests/relativistic_mcmc.py | 70 ++++++++++-------- pints/functionaltests/slice_stepout_mcmc.py | 71 +++++++++++-------- 14 files changed, 330 insertions(+), 231 deletions(-) diff --git a/pints/functionaltests/__init__.py b/pints/functionaltests/__init__.py index 82931b792..e300fec09 100644 --- a/pints/functionaltests/__init__.py +++ b/pints/functionaltests/__init__.py @@ -8,7 +8,7 @@ # Import all problem classes straight into this module, so that they can be # addressed as e.g. pints.functionaltests.RunMcmcMethodOnAnnulus. -from ._problems import ( +from ._problems import ( # noqa RunMcmcMethodOnAnnulus, RunMcmcMethodOnBanana, RunMcmcMethodOnCone, @@ -21,7 +21,7 @@ # 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 ( +from . import ( # noqa differential_evolution_mcmc, dram_acmc, dream_mcmc, diff --git a/pints/functionaltests/differential_evolution_mcmc.py b/pints/functionaltests/differential_evolution_mcmc.py index cd15f36a2..1951f6f5f 100644 --- a/pints/functionaltests/differential_evolution_mcmc.py +++ b/pints/functionaltests/differential_evolution_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=10000): """ Tests :class:`pints.DifferentialEvolutionMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.DifferentialEvolutionMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -34,7 +36,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=5000): """ Tests :class:`pints.DifferentialEvolutionMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -43,13 +45,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.DifferentialEvolutionMCMC, n_chains=20, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -58,7 +62,7 @@ def banana(n_iterations=None): } -def correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=10000): """ Tests :class:`pints.DifferentialEvolutionMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -68,13 +72,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.DifferentialEvolutionMCMC, n_chains=20, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -83,7 +89,7 @@ def correlated_gaussian(n_iterations=None): } -def annulus(n_iterations=None): +def annulus(n_iterations=10000): """ Tests :class:`pints.DifferentialEvolutionMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -92,13 +98,15 @@ def annulus(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnAnnulus( method=pints.DifferentialEvolutionMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { diff --git a/pints/functionaltests/dram_acmc.py b/pints/functionaltests/dram_acmc.py index 61faa771c..2216cdaa0 100644 --- a/pints/functionaltests/dram_acmc.py +++ b/pints/functionaltests/dram_acmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=8000): """ Tests :class:`pints.DramACMC` on a two-dimensional Gaussian distribution with true solution @@ -19,14 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ + n_warmup = 2000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 - if n_iterations is None: - n_iterations = 8000 problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.DramACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=2000 + n_warmup=n_warmup, ) return { @@ -35,7 +36,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=4000): """ Tests :class:`pints.DramACMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -43,13 +44,16 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. - """ if n_iterations is None: - n_iterations = 4000 + """ + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.DramACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -58,7 +62,7 @@ def banana(n_iterations=None): } -def correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=8000): """ Tests :class:`pints.DramACMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -68,13 +72,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 8000 + n_warmup = 4000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.DramACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=4000 + n_warmup=n_warmup, ) return { diff --git a/pints/functionaltests/dream_mcmc.py b/pints/functionaltests/dream_mcmc.py index db2c5afe2..ab0729b16 100644 --- a/pints/functionaltests/dream_mcmc.py +++ b/pints/functionaltests/dream_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=10000): """ Tests :class:`pints.DreamMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.DreamMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -34,7 +36,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=5000): """ Tests :class:`pints.DreamMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -43,13 +45,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.DreamMCMC, n_chains=20, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -58,7 +62,7 @@ def banana(n_iterations=None): } -def correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=10000): """ Tests :class:`pints.DreamMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -68,13 +72,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.DreamMCMC, n_chains=20, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -83,7 +89,7 @@ def correlated_gaussian(n_iterations=None): } -def annulus(n_iterations=None): +def annulus(n_iterations=10000): """ Tests :class:`pints.DreamMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -92,13 +98,15 @@ def annulus(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnAnnulus( method=pints.DreamMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { diff --git a/pints/functionaltests/emcee_hammer_mcmc.py b/pints/functionaltests/emcee_hammer_mcmc.py index 25570d862..7d6a6fc57 100644 --- a/pints/functionaltests/emcee_hammer_mcmc.py +++ b/pints/functionaltests/emcee_hammer_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=10000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -34,7 +36,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=10000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -43,13 +45,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 2000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=2000 + n_warmup=n_warmup, ) return { @@ -58,7 +62,7 @@ def banana(n_iterations=None): } -def correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=8000): """ Tests :class:`pints.EmceeHammerMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -68,13 +72,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 8000 + n_warmup = 4000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=4000 + n_warmup=n_warmup, ) return { @@ -83,7 +89,7 @@ def correlated_gaussian(n_iterations=None): } -def annulus(n_iterations=None): +def annulus(n_iterations=4000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -92,13 +98,15 @@ def annulus(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 2000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnAnnulus( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=2000 + n_warmup=n_warmup, ) return { @@ -107,7 +115,7 @@ def annulus(n_iterations=None): } -def multimodal_gaussian(n_iterations=None): +def multimodal_gaussian(n_iterations=10000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -117,13 +125,15 @@ def multimodal_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -132,7 +142,7 @@ def multimodal_gaussian(n_iterations=None): } -def cone(n_iterations=None): +def cone(n_iterations=10000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional cone distribution centered at ``[0, 0]``, and returns @@ -141,13 +151,15 @@ def cone(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCone( method=pints.EmceeHammerMCMC, n_chains=10, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { diff --git a/pints/functionaltests/haario_acmc.py b/pints/functionaltests/haario_acmc.py index 7808bc113..682827d23 100644 --- a/pints/functionaltests/haario_acmc.py +++ b/pints/functionaltests/haario_acmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=4000): """ Tests :class:`pints.HaarioACMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.HaarioACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -34,7 +36,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=4000): """ Tests :class:`pints.HaarioACMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -43,13 +45,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.HaarioACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -58,7 +62,7 @@ def banana(n_iterations=None): } -def correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=8000): """ Tests :class:`pints.HaarioACMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -68,13 +72,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 8000 + n_warmup = 4000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.HaarioACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=4000 + n_warmup=n_warmup, ) return { diff --git a/pints/functionaltests/haario_bardenet_acmc.py b/pints/functionaltests/haario_bardenet_acmc.py index 5aed19f84..1e505d38a 100644 --- a/pints/functionaltests/haario_bardenet_acmc.py +++ b/pints/functionaltests/haario_bardenet_acmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=4000): """ Tests :class:`pints.HaarioBardenetACMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.HaarioBardenetACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -34,7 +36,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=4000): """ Tests :class:`pints.HaarioBardenetACMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -43,13 +45,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.HaarioBardenetACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { @@ -58,7 +62,7 @@ def banana(n_iterations=None): } -def correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=8000): """ Tests :class:`pints.HaarioBardenetACMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -68,13 +72,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 8000 + n_warmup = 4000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.HaarioBardenetACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=4000 + n_warmup=n_warmup, ) return { @@ -83,7 +89,7 @@ def correlated_gaussian(n_iterations=None): } -def annulus(n_iterations=None): +def annulus(n_iterations=4000): """ Tests :class:`pints.HaarioBardenetACMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -92,13 +98,15 @@ def annulus(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 2000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnAnnulus( method=pints.HaarioBardenetACMC, n_chains=4, n_iterations=n_iterations, - n_warmup=2000 + n_warmup=n_warmup, ) return { diff --git a/pints/functionaltests/hamiltonian_mcmc.py b/pints/functionaltests/hamiltonian_mcmc.py index f987a37e3..c8d086aa0 100644 --- a/pints/functionaltests/hamiltonian_mcmc.py +++ b/pints/functionaltests/hamiltonian_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=1000): """ Tests :class:`pints.HamiltonianMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 1000 + n_warmup = 200 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.HamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=200, + n_warmup=n_warmup, method_hyper_parameters=[20, 1] ) @@ -35,7 +37,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=2000): """ Tests :class:`pints.HamiltonianMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -44,13 +46,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.HamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000, + n_warmup=n_warmup, method_hyper_parameters=[20, 2] ) @@ -60,7 +64,7 @@ def banana(n_iterations=None): } -def high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=4000): """ Tests :class:`pints.HamiltonianMCMC` on a 20-dimensional Gaussian distribution centered at the origin, and @@ -69,13 +73,15 @@ def high_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.HamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000, + n_warmup=n_warmup, method_hyper_parameters=[20, 1] ) diff --git a/pints/functionaltests/metropolis_random_walk_mcmc.py b/pints/functionaltests/metropolis_random_walk_mcmc.py index 7f89340ab..2830bff19 100644 --- a/pints/functionaltests/metropolis_random_walk_mcmc.py +++ b/pints/functionaltests/metropolis_random_walk_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=4000): """ Tests :class:`pints.MetropolisRandomWalkMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.MetropolisRandomWalkMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup ) return { @@ -34,7 +36,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=4000): """ Tests :class:`pints.MetropolisRandomWalkMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -43,13 +45,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.MetropolisRandomWalkMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup ) return { @@ -58,7 +62,7 @@ def banana(n_iterations=None): } -def correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=8000): """ Tests :class:`pints.MetropolisRandomWalkMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -68,13 +72,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 8000 + n_warmup = 4000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.MetropolisRandomWalkMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=4000 + n_warmup=n_warmup, ) return { diff --git a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py index c8424921a..9fe849ae5 100644 --- a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py +++ b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=1000): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 1000 + n_warmup = 200 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=200, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.5, 0.2, 1] ) @@ -35,7 +37,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=2000): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -44,13 +46,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.5, 0.2, 1] ) @@ -60,7 +64,7 @@ def banana(n_iterations=None): } -def high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=2000): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a 20-dimensional Gaussian distribution centered at the origin, and @@ -69,13 +73,15 @@ def high_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.5, 0.2, 1] ) @@ -85,7 +91,7 @@ def high_dim_gaussian(n_iterations=None): } -def correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=2000): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -95,13 +101,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.5, 0.2, 1] ) @@ -111,7 +119,7 @@ def correlated_gaussian(n_iterations=None): } -def annulus(n_iterations=None): +def annulus(n_iterations=2000): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -120,13 +128,15 @@ def annulus(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnAnnulus( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.5, 0.2, 1] ) @@ -136,7 +146,7 @@ def annulus(n_iterations=None): } -def multimodal_gaussian(n_iterations=None): +def multimodal_gaussian(n_iterations=2000): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -146,13 +156,15 @@ def multimodal_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.5, 0.2, 1] ) @@ -162,7 +174,7 @@ def multimodal_gaussian(n_iterations=None): } -def cone(n_iterations=None): +def cone(n_iterations=2000): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional cone distribution centered at ``[0, 0]``, and returns @@ -171,13 +183,15 @@ def cone(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCone( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.5, 0.2, 1] ) diff --git a/pints/functionaltests/no_u_turn_mcmc.py b/pints/functionaltests/no_u_turn_mcmc.py index 57b4da914..e1995449b 100644 --- a/pints/functionaltests/no_u_turn_mcmc.py +++ b/pints/functionaltests/no_u_turn_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=1000): """ Tests :class:`pints.NoUTurnMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 1000 + n_warmup = 200 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.NoUTurnMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=200 + n_warmup=n_warmup, ) return { @@ -34,7 +36,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=2000): """ Tests :class:`pints.NoUTurnMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -43,13 +45,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.NoUTurnMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500 + n_warmup=n_warmup, ) return { @@ -58,7 +62,7 @@ def banana(n_iterations=None): } -def high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=4000): """ Tests :class:`pints.NoUTurnMCMC` on a 20-dimensional Gaussian distribution centered at the origin, and @@ -67,13 +71,15 @@ def high_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - if n_iterations is None: - n_iterations = 4000 + n_warmup = 1000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.NoUTurnMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=1000 + n_warmup=n_warmup, ) return { diff --git a/pints/functionaltests/population_mcmc.py b/pints/functionaltests/population_mcmc.py index ce7d34203..111b66e7a 100644 --- a/pints/functionaltests/population_mcmc.py +++ b/pints/functionaltests/population_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=20000): """ Tests :class:`pints.PopulationMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,9 +19,6 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 20000 - n_warmup = 500 if n_warmup > n_iterations // 2: n_warmup = n_iterations // 10 @@ -39,7 +36,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=20000): """ Tests :class:`pints.PopulationMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -48,10 +45,6 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - - 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 @@ -69,7 +62,7 @@ def banana(n_iterations=None): } -def multimodal_gaussian(n_iterations=None, n_temperatures=None): +def multimodal_gaussian(n_iterations=20000, n_temperatures=None): """ Tests :class:`pints.PopulationMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -79,9 +72,6 @@ def multimodal_gaussian(n_iterations=None, n_temperatures=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - if n_iterations is None: - n_iterations = 20000 - n_warmup = 500 if n_warmup > n_iterations // 2: n_warmup = n_iterations // 10 diff --git a/pints/functionaltests/relativistic_mcmc.py b/pints/functionaltests/relativistic_mcmc.py index d3acf0dcc..063ee5106 100644 --- a/pints/functionaltests/relativistic_mcmc.py +++ b/pints/functionaltests/relativistic_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=1000): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 1000 + n_warmup = 200 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=200, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.1, 10] ) @@ -35,7 +37,7 @@ def two_dim_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=5000): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -44,13 +46,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.1, 10] ) @@ -60,7 +64,7 @@ def banana(n_iterations=None): } -def high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=5000): """ Tests :class:`pints.RelativisticMCMC` on a 20-dimensional Gaussian distribution centered at the origin, and @@ -69,13 +73,15 @@ def high_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.1, 10] ) @@ -85,7 +91,7 @@ def high_dim_gaussian(n_iterations=None): } -def correlated_gaussian(n_iterations=None): +def correlated_gaussian(n_iterations=5000): """ Tests :class:`pints.RelativisticMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -95,13 +101,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.1, 10] ) @@ -111,7 +119,7 @@ def correlated_gaussian(n_iterations=None): } -def annulus(n_iterations=None): +def annulus(n_iterations=5000): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -120,13 +128,15 @@ def annulus(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnAnnulus( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.1, 10] ) @@ -136,7 +146,7 @@ def annulus(n_iterations=None): } -def multimodal_gaussian(n_iterations=None): +def multimodal_gaussian(n_iterations=2000): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -146,13 +156,15 @@ def multimodal_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.1, 10] ) @@ -162,7 +174,7 @@ def multimodal_gaussian(n_iterations=None): } -def cone(n_iterations=None): +def cone(n_iterations=2000): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional cone distribution centered at ``[0, 0]``, and returns @@ -171,13 +183,15 @@ def cone(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ - if n_iterations is None: - n_iterations = 2000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCone( method=pints.RelativisticMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[20, 1, 0.1, 10] ) diff --git a/pints/functionaltests/slice_stepout_mcmc.py b/pints/functionaltests/slice_stepout_mcmc.py index ebfcea50b..e1968069e 100644 --- a/pints/functionaltests/slice_stepout_mcmc.py +++ b/pints/functionaltests/slice_stepout_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=None): +def two_dim_gaussian(n_iterations=5000): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,13 +19,15 @@ def two_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500 + n_warmup=n_warmup, ) return { @@ -33,7 +35,8 @@ def two_dim_gaussian(n_iterations=None): 'mean-ess': problem.estimate_mean_ess() } -def correlated_gaussian(n_iterations=None): + +def correlated_gaussian(n_iterations=5000): """ Tests :class:`pints.SliceStepoutMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -43,13 +46,15 @@ def correlated_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500 + n_warmup=n_warmup, ) return { @@ -58,7 +63,7 @@ def correlated_gaussian(n_iterations=None): } -def banana(n_iterations=None): +def banana(n_iterations=5000): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -67,13 +72,15 @@ def banana(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnBanana( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500 + n_warmup=n_warmup, ) return { @@ -82,7 +89,7 @@ def banana(n_iterations=None): } -def high_dim_gaussian(n_iterations=None): +def high_dim_gaussian(n_iterations=5000): """ Tests :class:`pints.SliceStepoutMCMC` on a 20-dimensional Gaussian distribution centered at the origin, and @@ -91,13 +98,15 @@ def high_dim_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500 + n_warmup=n_warmup, ) return { @@ -106,7 +115,7 @@ def high_dim_gaussian(n_iterations=None): } -def annulus(n_iterations=None): +def annulus(n_iterations=10000): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -115,13 +124,15 @@ def annulus(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - if n_iterations is None: - n_iterations = 10000 + n_warmup = 2000 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnAnnulus( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=2000 + n_warmup=n_warmup, ) return { @@ -130,7 +141,7 @@ def annulus(n_iterations=None): } -def multimodal_gaussian(n_iterations=None): +def multimodal_gaussian(n_iterations=5000): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -140,13 +151,15 @@ def multimodal_gaussian(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500 + n_warmup=n_warmup, ) return { @@ -155,7 +168,7 @@ def multimodal_gaussian(n_iterations=None): } -def cone(n_iterations=None): +def cone(n_iterations=5000): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional cone distribution centered at ``[0, 0]``, and returns @@ -164,13 +177,15 @@ def cone(n_iterations=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ - if n_iterations is None: - n_iterations = 5000 + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + problem = ft.RunMcmcMethodOnCone( method=pints.SliceStepoutMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500 + n_warmup=n_warmup, ) return { From c9cb2260e52ee2bab5bee60af28f8cb95f3f692f Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Wed, 11 Aug 2021 13:04:58 +0100 Subject: [PATCH 07/11] Added functional test discovery mechanism. --- pints/functionaltests/__init__.py | 3 ++ pints/functionaltests/_discovery.py | 40 +++++++++++++++++++ .../differential_evolution_mcmc.py | 9 +++++ pints/functionaltests/dram_acmc.py | 8 ++++ pints/functionaltests/dream_mcmc.py | 9 +++++ pints/functionaltests/emcee_hammer_mcmc.py | 11 +++++ pints/functionaltests/haario_acmc.py | 9 +++++ pints/functionaltests/haario_bardenet_acmc.py | 9 +++++ pints/functionaltests/hamiltonian_mcmc.py | 8 ++++ .../metropolis_random_walk_mcmc.py | 8 ++++ .../monomial_gamma_hamiltonian_mcmc.py | 12 ++++++ pints/functionaltests/no_u_turn_mcmc.py | 8 ++++ pints/functionaltests/population_mcmc.py | 7 ++++ pints/functionaltests/relativistic_mcmc.py | 12 ++++++ pints/functionaltests/slice_stepout_mcmc.py | 12 ++++++ 15 files changed, 165 insertions(+) create mode 100644 pints/functionaltests/_discovery.py diff --git a/pints/functionaltests/__init__.py b/pints/functionaltests/__init__.py index e300fec09..afb340246 100644 --- a/pints/functionaltests/__init__.py +++ b/pints/functionaltests/__init__.py @@ -37,3 +37,6 @@ slice_stepout_mcmc, ) + +# 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/differential_evolution_mcmc.py b/pints/functionaltests/differential_evolution_mcmc.py index 1951f6f5f..9ff41d802 100644 --- a/pints/functionaltests/differential_evolution_mcmc.py +++ b/pints/functionaltests/differential_evolution_mcmc.py @@ -113,3 +113,12 @@ def annulus(n_iterations=10000): '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_acmc.py b/pints/functionaltests/dram_acmc.py index 2216cdaa0..119e9bb66 100644 --- a/pints/functionaltests/dram_acmc.py +++ b/pints/functionaltests/dram_acmc.py @@ -87,3 +87,11 @@ def correlated_gaussian(n_iterations=8000): '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_mcmc.py b/pints/functionaltests/dream_mcmc.py index ab0729b16..85424a50b 100644 --- a/pints/functionaltests/dream_mcmc.py +++ b/pints/functionaltests/dream_mcmc.py @@ -113,3 +113,12 @@ def annulus(n_iterations=10000): '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_mcmc.py b/pints/functionaltests/emcee_hammer_mcmc.py index 7d6a6fc57..18c8edd68 100644 --- a/pints/functionaltests/emcee_hammer_mcmc.py +++ b/pints/functionaltests/emcee_hammer_mcmc.py @@ -166,3 +166,14 @@ def cone(n_iterations=10000): '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 682827d23..b93edf83a 100644 --- a/pints/functionaltests/haario_acmc.py +++ b/pints/functionaltests/haario_acmc.py @@ -87,3 +87,12 @@ def correlated_gaussian(n_iterations=8000): '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 1e505d38a..7c06425c3 100644 --- a/pints/functionaltests/haario_bardenet_acmc.py +++ b/pints/functionaltests/haario_bardenet_acmc.py @@ -113,3 +113,12 @@ def annulus(n_iterations=4000): '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_mcmc.py b/pints/functionaltests/hamiltonian_mcmc.py index c8d086aa0..313f8ea41 100644 --- a/pints/functionaltests/hamiltonian_mcmc.py +++ b/pints/functionaltests/hamiltonian_mcmc.py @@ -89,3 +89,11 @@ def high_dim_gaussian(n_iterations=4000): '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/metropolis_random_walk_mcmc.py b/pints/functionaltests/metropolis_random_walk_mcmc.py index 2830bff19..468caa1a2 100644 --- a/pints/functionaltests/metropolis_random_walk_mcmc.py +++ b/pints/functionaltests/metropolis_random_walk_mcmc.py @@ -87,3 +87,11 @@ def correlated_gaussian(n_iterations=8000): '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_mcmc.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py index 9fe849ae5..850916adf 100644 --- a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py +++ b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py @@ -199,3 +199,15 @@ def cone(n_iterations=2000): '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 index e1995449b..68058f1f7 100644 --- a/pints/functionaltests/no_u_turn_mcmc.py +++ b/pints/functionaltests/no_u_turn_mcmc.py @@ -86,3 +86,11 @@ def high_dim_gaussian(n_iterations=4000): '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/population_mcmc.py b/pints/functionaltests/population_mcmc.py index 111b66e7a..6f2779798 100644 --- a/pints/functionaltests/population_mcmc.py +++ b/pints/functionaltests/population_mcmc.py @@ -93,3 +93,10 @@ def multimodal_gaussian(n_iterations=20000, n_temperatures=None): 'mean-ess': problem.estimate_mean_ess() } + +_method = pints.PopulationMCMC +_functional_tests = [ + banana, + multimodal_gaussian, + two_dim_gaussian, +] diff --git a/pints/functionaltests/relativistic_mcmc.py b/pints/functionaltests/relativistic_mcmc.py index 063ee5106..4d4e4054e 100644 --- a/pints/functionaltests/relativistic_mcmc.py +++ b/pints/functionaltests/relativistic_mcmc.py @@ -199,3 +199,15 @@ def cone(n_iterations=2000): '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_mcmc.py b/pints/functionaltests/slice_stepout_mcmc.py index e1968069e..aebbdb776 100644 --- a/pints/functionaltests/slice_stepout_mcmc.py +++ b/pints/functionaltests/slice_stepout_mcmc.py @@ -192,3 +192,15 @@ def cone(n_iterations=5000): '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, +] From 6c8f607e17264c2910bf2eeb4c4d5cd3608001ec Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Mon, 16 Aug 2021 09:21:47 +0100 Subject: [PATCH 08/11] Updated new MALA tests. --- pints/functionaltests/mala_mcmc.py | 170 +++++++++++++++++++++-------- 1 file changed, 123 insertions(+), 47 deletions(-) diff --git a/pints/functionaltests/mala_mcmc.py b/pints/functionaltests/mala_mcmc.py index 7ee97b35a..03883c954 100644 --- a/pints/functionaltests/mala_mcmc.py +++ b/pints/functionaltests/mala_mcmc.py @@ -1,31 +1,33 @@ #!/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): + """ + 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( + For details of the solved problem, see + :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. + """ + n_warmup = 200 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + + problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.MALAMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=200, + n_warmup=n_warmup, method_hyper_parameters=[[1.0, 1.0]] ) @@ -35,14 +37,24 @@ def test_mala_mcmc_on_two_dim_gaussian(n_iterations=None): } -def test_mala_mcmc_on_banana(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnBanana( +def banana(n_iterations=2000): + """ + 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`. + """ + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + + problem = ft.RunMcmcMethodOnBanana( method=pints.MALAMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[[0.8] * 2] ) @@ -52,14 +64,24 @@ def test_mala_mcmc_on_banana(n_iterations=None): } -def test_mala_mcmc_on_high_dim_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnHighDimensionalGaussian( +def high_dim_gaussian(n_iterations=2000): + """ + 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`. + """ + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + + problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.MALAMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[[1.2] * 20] ) @@ -69,14 +91,25 @@ 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( +def correlated_gaussian(n_iterations=2000): + """ + 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`. + """ + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + + problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.MALAMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[[1.0] * 6] ) @@ -86,15 +119,25 @@ def test_mala_mcmc_on_correlated_gaussian(n_iterations=None): } -def test_mala_mcmc_on_annulus(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnAnnulus( +def annulus(n_iterations=2000): + """ + 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`. + """ + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + + problem = ft.RunMcmcMethodOnAnnulus( method=pints.MALAMCMC, 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 { @@ -103,14 +146,25 @@ def test_mala_mcmc_on_annulus(n_iterations=None): } -def test_mala_mcmc_on_multimodal_gaussian(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnMultimodalGaussian( +def multimodal_gaussian(n_iterations=2000): + """ + 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`. + """ + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + + problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.MALAMCMC, n_chains=4, n_iterations=n_iterations, - n_warmup=500, + n_warmup=n_warmup, method_hyper_parameters=[[2.0] * 2] ) @@ -120,18 +174,40 @@ def test_mala_mcmc_on_multimodal_gaussian(n_iterations=None): } -def test_mala_mcmc_on_cone(n_iterations=None): - if n_iterations is None: - n_iterations = 2000 - problem = RunMcmcMethodOnCone( +def cone(n_iterations=2000): + """ + 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`. + """ + n_warmup = 500 + if n_warmup > n_iterations // 2: + n_warmup = n_iterations // 10 + + problem = ft.RunMcmcMethodOnCone( method=pints.MALAMCMC, 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, +] From 1e434c58188421ce0c0f0646d297ce49e5b2f716 Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Mon, 16 Aug 2021 11:04:44 +0100 Subject: [PATCH 09/11] Updated new MALA tests. --- pints/functionaltests/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pints/functionaltests/__init__.py b/pints/functionaltests/__init__.py index afb340246..ee5981e63 100644 --- a/pints/functionaltests/__init__.py +++ b/pints/functionaltests/__init__.py @@ -29,6 +29,7 @@ haario_acmc, haario_bardenet_acmc, hamiltonian_mcmc, + mala_mcmc, metropolis_random_walk_mcmc, monomial_gamma_hamiltonian_mcmc, no_u_turn_mcmc, From 14c0263d3ac502732314bbc79f8efedb5a81413b Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Mon, 16 Aug 2021 11:04:55 +0100 Subject: [PATCH 10/11] Made ft warmup a user-set parameter. --- .../differential_evolution_mcmc.py | 24 ++--------- pints/functionaltests/dram_acmc.py | 18 ++------ pints/functionaltests/dream_mcmc.py | 24 ++--------- pints/functionaltests/emcee_hammer_mcmc.py | 36 +++------------- pints/functionaltests/haario_acmc.py | 18 ++------ pints/functionaltests/haario_bardenet_acmc.py | 24 ++--------- pints/functionaltests/hamiltonian_mcmc.py | 18 ++------ pints/functionaltests/mala_mcmc.py | 42 ++++--------------- .../metropolis_random_walk_mcmc.py | 18 ++------ .../monomial_gamma_hamiltonian_mcmc.py | 38 ++++------------- pints/functionaltests/no_u_turn_mcmc.py | 18 ++------ pints/functionaltests/population_mcmc.py | 19 ++------- pints/functionaltests/relativistic_mcmc.py | 42 ++++--------------- pints/functionaltests/slice_stepout_mcmc.py | 42 ++++--------------- 14 files changed, 65 insertions(+), 316 deletions(-) diff --git a/pints/functionaltests/differential_evolution_mcmc.py b/pints/functionaltests/differential_evolution_mcmc.py index 9ff41d802..f4510cac4 100644 --- a/pints/functionaltests/differential_evolution_mcmc.py +++ b/pints/functionaltests/differential_evolution_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=10000): +def two_dim_gaussian(n_iterations=10000, n_warmup=1000): """ Tests :class:`pints.DifferentialEvolutionMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.DifferentialEvolutionMCMC, n_chains=10, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=10000): } -def banana(n_iterations=5000): +def banana(n_iterations=5000, n_warmup=1000): """ Tests :class:`pints.DifferentialEvolutionMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -45,10 +41,6 @@ def banana(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.DifferentialEvolutionMCMC, n_chains=20, @@ -62,7 +54,7 @@ def banana(n_iterations=5000): } -def correlated_gaussian(n_iterations=10000): +def correlated_gaussian(n_iterations=10000, n_warmup=1000): """ Tests :class:`pints.DifferentialEvolutionMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -72,10 +64,6 @@ def correlated_gaussian(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.DifferentialEvolutionMCMC, n_chains=20, @@ -89,7 +77,7 @@ def correlated_gaussian(n_iterations=10000): } -def annulus(n_iterations=10000): +def annulus(n_iterations=10000, n_warmup=1000): """ Tests :class:`pints.DifferentialEvolutionMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -98,10 +86,6 @@ def annulus(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnAnnulus( method=pints.DifferentialEvolutionMCMC, n_chains=10, diff --git a/pints/functionaltests/dram_acmc.py b/pints/functionaltests/dram_acmc.py index 119e9bb66..17f82242f 100644 --- a/pints/functionaltests/dram_acmc.py +++ b/pints/functionaltests/dram_acmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=8000): +def two_dim_gaussian(n_iterations=8000, n_warmup=2000): """ Tests :class:`pints.DramACMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=8000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 2000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.DramACMC, n_chains=4, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=8000): } -def banana(n_iterations=4000): +def banana(n_iterations=4000, n_warmup=1000): """ Tests :class:`pints.DramACMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -45,10 +41,6 @@ def banana(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.DramACMC, n_chains=4, @@ -62,7 +54,7 @@ def banana(n_iterations=4000): } -def correlated_gaussian(n_iterations=8000): +def correlated_gaussian(n_iterations=8000, n_warmup=4000): """ Tests :class:`pints.DramACMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -72,10 +64,6 @@ def correlated_gaussian(n_iterations=8000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 4000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.DramACMC, n_chains=4, diff --git a/pints/functionaltests/dream_mcmc.py b/pints/functionaltests/dream_mcmc.py index 85424a50b..e8e75bf40 100644 --- a/pints/functionaltests/dream_mcmc.py +++ b/pints/functionaltests/dream_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=10000): +def two_dim_gaussian(n_iterations=10000, n_warmup=1000): """ Tests :class:`pints.DreamMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.DreamMCMC, n_chains=10, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=10000): } -def banana(n_iterations=5000): +def banana(n_iterations=5000, n_warmup=1000): """ Tests :class:`pints.DreamMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -45,10 +41,6 @@ def banana(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.DreamMCMC, n_chains=20, @@ -62,7 +54,7 @@ def banana(n_iterations=5000): } -def correlated_gaussian(n_iterations=10000): +def correlated_gaussian(n_iterations=10000, n_warmup=1000): """ Tests :class:`pints.DreamMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -72,10 +64,6 @@ def correlated_gaussian(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.DreamMCMC, n_chains=20, @@ -89,7 +77,7 @@ def correlated_gaussian(n_iterations=10000): } -def annulus(n_iterations=10000): +def annulus(n_iterations=10000, n_warmup=1000): """ Tests :class:`pints.DreamMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -98,10 +86,6 @@ def annulus(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnAnnulus( method=pints.DreamMCMC, n_chains=10, diff --git a/pints/functionaltests/emcee_hammer_mcmc.py b/pints/functionaltests/emcee_hammer_mcmc.py index 18c8edd68..8071a2508 100644 --- a/pints/functionaltests/emcee_hammer_mcmc.py +++ b/pints/functionaltests/emcee_hammer_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=10000): +def two_dim_gaussian(n_iterations=10000, n_warmup=1000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.EmceeHammerMCMC, n_chains=10, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=10000): } -def banana(n_iterations=10000): +def banana(n_iterations=10000, n_warmup=2000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -45,10 +41,6 @@ def banana(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 2000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.EmceeHammerMCMC, n_chains=10, @@ -62,7 +54,7 @@ def banana(n_iterations=10000): } -def correlated_gaussian(n_iterations=8000): +def correlated_gaussian(n_iterations=8000, n_warmup=4000): """ Tests :class:`pints.EmceeHammerMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -72,10 +64,6 @@ def correlated_gaussian(n_iterations=8000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 4000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.EmceeHammerMCMC, n_chains=10, @@ -89,7 +77,7 @@ def correlated_gaussian(n_iterations=8000): } -def annulus(n_iterations=4000): +def annulus(n_iterations=4000, n_warmup=2000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -98,10 +86,6 @@ def annulus(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - n_warmup = 2000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnAnnulus( method=pints.EmceeHammerMCMC, n_chains=10, @@ -115,7 +99,7 @@ def annulus(n_iterations=4000): } -def multimodal_gaussian(n_iterations=10000): +def multimodal_gaussian(n_iterations=10000, n_warmup=1000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -125,10 +109,6 @@ def multimodal_gaussian(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.EmceeHammerMCMC, n_chains=10, @@ -142,7 +122,7 @@ def multimodal_gaussian(n_iterations=10000): } -def cone(n_iterations=10000): +def cone(n_iterations=10000, n_warmup=1000): """ Tests :class:`pints.EmceeHammerMCMC` on a two-dimensional cone distribution centered at ``[0, 0]``, and returns @@ -151,10 +131,6 @@ def cone(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCone( method=pints.EmceeHammerMCMC, n_chains=10, diff --git a/pints/functionaltests/haario_acmc.py b/pints/functionaltests/haario_acmc.py index b93edf83a..c6e8df611 100644 --- a/pints/functionaltests/haario_acmc.py +++ b/pints/functionaltests/haario_acmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=4000): +def two_dim_gaussian(n_iterations=4000, n_warmup=1000): """ Tests :class:`pints.HaarioACMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.HaarioACMC, n_chains=4, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=4000): } -def banana(n_iterations=4000): +def banana(n_iterations=4000, n_warmup=1000): """ Tests :class:`pints.HaarioACMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -45,10 +41,6 @@ def banana(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.HaarioACMC, n_chains=4, @@ -62,7 +54,7 @@ def banana(n_iterations=4000): } -def correlated_gaussian(n_iterations=8000): +def correlated_gaussian(n_iterations=8000, n_warmup=4000): """ Tests :class:`pints.HaarioACMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -72,10 +64,6 @@ def correlated_gaussian(n_iterations=8000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 4000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.HaarioACMC, n_chains=4, diff --git a/pints/functionaltests/haario_bardenet_acmc.py b/pints/functionaltests/haario_bardenet_acmc.py index 7c06425c3..a6aafd9f0 100644 --- a/pints/functionaltests/haario_bardenet_acmc.py +++ b/pints/functionaltests/haario_bardenet_acmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=4000): +def two_dim_gaussian(n_iterations=4000, n_warmup=1000): """ Tests :class:`pints.HaarioBardenetACMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.HaarioBardenetACMC, n_chains=4, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=4000): } -def banana(n_iterations=4000): +def banana(n_iterations=4000, n_warmup=1000): """ Tests :class:`pints.HaarioBardenetACMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -45,10 +41,6 @@ def banana(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.HaarioBardenetACMC, n_chains=4, @@ -62,7 +54,7 @@ def banana(n_iterations=4000): } -def correlated_gaussian(n_iterations=8000): +def correlated_gaussian(n_iterations=8000, n_warmup=4000): """ Tests :class:`pints.HaarioBardenetACMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -72,10 +64,6 @@ def correlated_gaussian(n_iterations=8000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 4000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.HaarioBardenetACMC, n_chains=4, @@ -89,7 +77,7 @@ def correlated_gaussian(n_iterations=8000): } -def annulus(n_iterations=4000): +def annulus(n_iterations=4000, n_warmup=2000): """ Tests :class:`pints.HaarioBardenetACMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -98,10 +86,6 @@ def annulus(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - n_warmup = 2000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnAnnulus( method=pints.HaarioBardenetACMC, n_chains=4, diff --git a/pints/functionaltests/hamiltonian_mcmc.py b/pints/functionaltests/hamiltonian_mcmc.py index 313f8ea41..8720673d9 100644 --- a/pints/functionaltests/hamiltonian_mcmc.py +++ b/pints/functionaltests/hamiltonian_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=1000): +def two_dim_gaussian(n_iterations=1000, n_warmup=200): """ Tests :class:`pints.HamiltonianMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=1000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 200 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.HamiltonianMCMC, n_chains=4, @@ -37,7 +33,7 @@ def two_dim_gaussian(n_iterations=1000): } -def banana(n_iterations=2000): +def banana(n_iterations=2000, n_warmup=1000): """ Tests :class:`pints.HamiltonianMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -46,10 +42,6 @@ def banana(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.HamiltonianMCMC, n_chains=4, @@ -64,7 +56,7 @@ def banana(n_iterations=2000): } -def high_dim_gaussian(n_iterations=4000): +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 @@ -73,10 +65,6 @@ def high_dim_gaussian(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.HamiltonianMCMC, n_chains=4, diff --git a/pints/functionaltests/mala_mcmc.py b/pints/functionaltests/mala_mcmc.py index 03883c954..0de389afe 100644 --- a/pints/functionaltests/mala_mcmc.py +++ b/pints/functionaltests/mala_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=1000): +def two_dim_gaussian(n_iterations=1000, n_warmup=200): """ Tests :class:`pints.MALAMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=1000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 200 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.MALAMCMC, n_chains=4, @@ -37,7 +33,7 @@ def two_dim_gaussian(n_iterations=1000): } -def banana(n_iterations=2000): +def banana(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MALAMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -46,10 +42,6 @@ def banana(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.MALAMCMC, n_chains=4, @@ -64,7 +56,7 @@ def banana(n_iterations=2000): } -def high_dim_gaussian(n_iterations=2000): +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 @@ -73,10 +65,6 @@ def high_dim_gaussian(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.MALAMCMC, n_chains=4, @@ -91,7 +79,7 @@ def high_dim_gaussian(n_iterations=2000): } -def correlated_gaussian(n_iterations=2000): +def correlated_gaussian(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MALAMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -101,10 +89,6 @@ def correlated_gaussian(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.MALAMCMC, n_chains=4, @@ -119,7 +103,7 @@ def correlated_gaussian(n_iterations=2000): } -def annulus(n_iterations=2000): +def annulus(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MALAMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -128,10 +112,6 @@ def annulus(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnAnnulus( method=pints.MALAMCMC, n_chains=4, @@ -146,7 +126,7 @@ def annulus(n_iterations=2000): } -def multimodal_gaussian(n_iterations=2000): +def multimodal_gaussian(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MALAMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -156,10 +136,6 @@ def multimodal_gaussian(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.MALAMCMC, n_chains=4, @@ -174,7 +150,7 @@ def multimodal_gaussian(n_iterations=2000): } -def cone(n_iterations=2000): +def cone(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MALAMCMC` on a two-dimensional cone distribution centered at ``[0, 0]``, and returns @@ -183,10 +159,6 @@ def cone(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCone( method=pints.MALAMCMC, n_chains=4, diff --git a/pints/functionaltests/metropolis_random_walk_mcmc.py b/pints/functionaltests/metropolis_random_walk_mcmc.py index 468caa1a2..a13c3057d 100644 --- a/pints/functionaltests/metropolis_random_walk_mcmc.py +++ b/pints/functionaltests/metropolis_random_walk_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=4000): +def two_dim_gaussian(n_iterations=4000, n_warmup=1000): """ Tests :class:`pints.MetropolisRandomWalkMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.MetropolisRandomWalkMCMC, n_chains=4, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=4000): } -def banana(n_iterations=4000): +def banana(n_iterations=4000, n_warmup=1000): """ Tests :class:`pints.MetropolisRandomWalkMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -45,10 +41,6 @@ def banana(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.MetropolisRandomWalkMCMC, n_chains=4, @@ -62,7 +54,7 @@ def banana(n_iterations=4000): } -def correlated_gaussian(n_iterations=8000): +def correlated_gaussian(n_iterations=8000, n_warmup=4000): """ Tests :class:`pints.MetropolisRandomWalkMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -72,10 +64,6 @@ def correlated_gaussian(n_iterations=8000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 4000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.MetropolisRandomWalkMCMC, n_chains=4, diff --git a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py index 850916adf..c808c3f81 100644 --- a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py +++ b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=1000): +def two_dim_gaussian(n_iterations=1000, n_warmup=200): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=1000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 200 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, @@ -37,7 +33,7 @@ def two_dim_gaussian(n_iterations=1000): } -def banana(n_iterations=2000): +def banana(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -46,10 +42,6 @@ def banana(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, @@ -64,7 +56,7 @@ def banana(n_iterations=2000): } -def high_dim_gaussian(n_iterations=2000): +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 @@ -73,10 +65,6 @@ def high_dim_gaussian(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, @@ -91,7 +79,7 @@ def high_dim_gaussian(n_iterations=2000): } -def correlated_gaussian(n_iterations=2000): +def correlated_gaussian(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -119,7 +107,7 @@ def correlated_gaussian(n_iterations=2000): } -def annulus(n_iterations=2000): +def annulus(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -128,10 +116,6 @@ def annulus(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnAnnulus( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, @@ -146,7 +130,7 @@ def annulus(n_iterations=2000): } -def multimodal_gaussian(n_iterations=2000): +def multimodal_gaussian(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -156,10 +140,6 @@ def multimodal_gaussian(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, @@ -174,7 +154,7 @@ def multimodal_gaussian(n_iterations=2000): } -def cone(n_iterations=2000): +def cone(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.MonomialGammaHamiltonianMCMC` on a two-dimensional cone distribution centered at ``[0, 0]``, and returns @@ -183,10 +163,6 @@ def cone(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCone( method=pints.MonomialGammaHamiltonianMCMC, n_chains=4, diff --git a/pints/functionaltests/no_u_turn_mcmc.py b/pints/functionaltests/no_u_turn_mcmc.py index 68058f1f7..d627690ea 100644 --- a/pints/functionaltests/no_u_turn_mcmc.py +++ b/pints/functionaltests/no_u_turn_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=1000): +def two_dim_gaussian(n_iterations=1000, n_warmup=200): """ Tests :class:`pints.NoUTurnMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=1000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 200 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.NoUTurnMCMC, n_chains=4, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=1000): } -def banana(n_iterations=2000): +def banana(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.NoUTurnMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -45,10 +41,6 @@ def banana(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.NoUTurnMCMC, n_chains=4, @@ -62,7 +54,7 @@ def banana(n_iterations=2000): } -def high_dim_gaussian(n_iterations=4000): +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 @@ -71,10 +63,6 @@ def high_dim_gaussian(n_iterations=4000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - n_warmup = 1000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.NoUTurnMCMC, n_chains=4, diff --git a/pints/functionaltests/population_mcmc.py b/pints/functionaltests/population_mcmc.py index 6f2779798..b0390255b 100644 --- a/pints/functionaltests/population_mcmc.py +++ b/pints/functionaltests/population_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=20000): +def two_dim_gaussian(n_iterations=20000, n_warmup=500): """ Tests :class:`pints.PopulationMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=20000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.PopulationMCMC, n_chains=1, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=20000): } -def banana(n_iterations=20000): +def banana(n_iterations=20000, n_warmup=5000): """ Tests :class:`pints.PopulationMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -45,10 +41,6 @@ def banana(n_iterations=20000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 5000 # Needs a lot of warm-up on banana! - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.PopulationMCMC, n_chains=1, @@ -62,7 +54,8 @@ def banana(n_iterations=20000): } -def multimodal_gaussian(n_iterations=20000, n_temperatures=None): +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 @@ -72,10 +65,6 @@ def multimodal_gaussian(n_iterations=20000, n_temperatures=None): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - 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] diff --git a/pints/functionaltests/relativistic_mcmc.py b/pints/functionaltests/relativistic_mcmc.py index 4d4e4054e..711acc618 100644 --- a/pints/functionaltests/relativistic_mcmc.py +++ b/pints/functionaltests/relativistic_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=1000): +def two_dim_gaussian(n_iterations=1000, n_warmup=200): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=1000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 200 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.RelativisticMCMC, n_chains=4, @@ -37,7 +33,7 @@ def two_dim_gaussian(n_iterations=1000): } -def banana(n_iterations=5000): +def banana(n_iterations=5000, n_warmup=500): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -46,10 +42,6 @@ def banana(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.RelativisticMCMC, n_chains=4, @@ -64,7 +56,7 @@ def banana(n_iterations=5000): } -def high_dim_gaussian(n_iterations=5000): +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 @@ -73,10 +65,6 @@ def high_dim_gaussian(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.RelativisticMCMC, n_chains=4, @@ -91,7 +79,7 @@ def high_dim_gaussian(n_iterations=5000): } -def correlated_gaussian(n_iterations=5000): +def correlated_gaussian(n_iterations=5000, n_warmup=500): """ Tests :class:`pints.RelativisticMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -101,10 +89,6 @@ def correlated_gaussian(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.RelativisticMCMC, n_chains=4, @@ -119,7 +103,7 @@ def correlated_gaussian(n_iterations=5000): } -def annulus(n_iterations=5000): +def annulus(n_iterations=5000, n_warmup=500): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -128,10 +112,6 @@ def annulus(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnAnnulus( method=pints.RelativisticMCMC, n_chains=4, @@ -146,7 +126,7 @@ def annulus(n_iterations=5000): } -def multimodal_gaussian(n_iterations=2000): +def multimodal_gaussian(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -156,10 +136,6 @@ def multimodal_gaussian(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.RelativisticMCMC, n_chains=4, @@ -174,7 +150,7 @@ def multimodal_gaussian(n_iterations=2000): } -def cone(n_iterations=2000): +def cone(n_iterations=2000, n_warmup=500): """ Tests :class:`pints.RelativisticMCMC` on a two-dimensional cone distribution centered at ``[0, 0]``, and returns @@ -183,10 +159,6 @@ def cone(n_iterations=2000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCone( method=pints.RelativisticMCMC, n_chains=4, diff --git a/pints/functionaltests/slice_stepout_mcmc.py b/pints/functionaltests/slice_stepout_mcmc.py index aebbdb776..876c97762 100644 --- a/pints/functionaltests/slice_stepout_mcmc.py +++ b/pints/functionaltests/slice_stepout_mcmc.py @@ -10,7 +10,7 @@ import pints.functionaltests as ft -def two_dim_gaussian(n_iterations=5000): +def two_dim_gaussian(n_iterations=5000, n_warmup=500): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional Gaussian distribution with true solution @@ -19,10 +19,6 @@ def two_dim_gaussian(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnTwoDimGaussian( method=pints.SliceStepoutMCMC, n_chains=4, @@ -36,7 +32,7 @@ def two_dim_gaussian(n_iterations=5000): } -def correlated_gaussian(n_iterations=5000): +def correlated_gaussian(n_iterations=5000, n_warmup=500): """ Tests :class:`pints.SliceStepoutMCMC` on a six-dimensional highly correlated Gaussian distribution with true @@ -46,10 +42,6 @@ def correlated_gaussian(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( method=pints.SliceStepoutMCMC, n_chains=4, @@ -63,7 +55,7 @@ def correlated_gaussian(n_iterations=5000): } -def banana(n_iterations=5000): +def banana(n_iterations=5000, n_warmup=500): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional "twisted Gaussian" distribution with true solution @@ -72,10 +64,6 @@ def banana(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnBanana( method=pints.SliceStepoutMCMC, n_chains=4, @@ -89,7 +77,7 @@ def banana(n_iterations=5000): } -def high_dim_gaussian(n_iterations=5000): +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 @@ -98,10 +86,6 @@ def high_dim_gaussian(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnHighDimensionalGaussian( method=pints.SliceStepoutMCMC, n_chains=4, @@ -115,7 +99,7 @@ def high_dim_gaussian(n_iterations=5000): } -def annulus(n_iterations=10000): +def annulus(n_iterations=10000, n_warmup=2000): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional annulus distribution with radius 10, and returns a @@ -124,10 +108,6 @@ def annulus(n_iterations=10000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ - n_warmup = 2000 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnAnnulus( method=pints.SliceStepoutMCMC, n_chains=4, @@ -141,7 +121,7 @@ def annulus(n_iterations=10000): } -def multimodal_gaussian(n_iterations=5000): +def multimodal_gaussian(n_iterations=5000, n_warmup=500): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional multi-modal Gaussian distribution with modes at @@ -151,10 +131,6 @@ def multimodal_gaussian(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnMultimodalGaussian( method=pints.SliceStepoutMCMC, n_chains=4, @@ -168,7 +144,7 @@ def multimodal_gaussian(n_iterations=5000): } -def cone(n_iterations=5000): +def cone(n_iterations=5000, n_warmup=500): """ Tests :class:`pints.SliceStepoutMCMC` on a two-dimensional cone distribution centered at ``[0, 0]``, and returns @@ -177,10 +153,6 @@ def cone(n_iterations=5000): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCone( method=pints.SliceStepoutMCMC, n_chains=4, From 2ed963feb0d19268cba040812d0cbe154e784672 Mon Sep 17 00:00:00 2001 From: Michael Clerx Date: Mon, 16 Aug 2021 11:23:11 +0100 Subject: [PATCH 11/11] Slightly simplified ft code. --- .../differential_evolution_mcmc.py | 28 ++--------- pints/functionaltests/dram_acmc.py | 21 ++------ pints/functionaltests/dream_mcmc.py | 27 ++-------- pints/functionaltests/emcee_hammer_mcmc.py | 42 +++------------- pints/functionaltests/haario_acmc.py | 21 ++------ pints/functionaltests/haario_bardenet_acmc.py | 28 ++--------- pints/functionaltests/hamiltonian_mcmc.py | 9 ++-- pints/functionaltests/mala_mcmc.py | 20 +++----- .../metropolis_random_walk_mcmc.py | 21 ++------ .../monomial_gamma_hamiltonian_mcmc.py | 25 +++------- pints/functionaltests/no_u_turn_mcmc.py | 21 ++------ pints/functionaltests/population_mcmc.py | 15 ++---- pints/functionaltests/relativistic_mcmc.py | 21 +++----- pints/functionaltests/slice_stepout_mcmc.py | 49 +++---------------- 14 files changed, 64 insertions(+), 284 deletions(-) diff --git a/pints/functionaltests/differential_evolution_mcmc.py b/pints/functionaltests/differential_evolution_mcmc.py index f4510cac4..35ceea820 100644 --- a/pints/functionaltests/differential_evolution_mcmc.py +++ b/pints/functionaltests/differential_evolution_mcmc.py @@ -20,12 +20,7 @@ def two_dim_gaussian(n_iterations=10000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.DifferentialEvolutionMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 10, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -42,12 +37,7 @@ def banana(n_iterations=5000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.DifferentialEvolutionMCMC, - n_chains=20, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 20, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -65,12 +55,7 @@ def correlated_gaussian(n_iterations=10000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.DifferentialEvolutionMCMC, - n_chains=20, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 20, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -87,12 +72,7 @@ def annulus(n_iterations=10000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ problem = ft.RunMcmcMethodOnAnnulus( - method=pints.DifferentialEvolutionMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 10, n_iterations, n_warmup) return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() diff --git a/pints/functionaltests/dram_acmc.py b/pints/functionaltests/dram_acmc.py index 17f82242f..2ec83eea6 100644 --- a/pints/functionaltests/dram_acmc.py +++ b/pints/functionaltests/dram_acmc.py @@ -20,12 +20,7 @@ def two_dim_gaussian(n_iterations=8000, n_warmup=2000): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.DramACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -42,12 +37,7 @@ def banana(n_iterations=4000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.DramACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -65,12 +55,7 @@ def correlated_gaussian(n_iterations=8000, n_warmup=4000): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.DramACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() diff --git a/pints/functionaltests/dream_mcmc.py b/pints/functionaltests/dream_mcmc.py index e8e75bf40..ca6745a4b 100644 --- a/pints/functionaltests/dream_mcmc.py +++ b/pints/functionaltests/dream_mcmc.py @@ -20,11 +20,7 @@ def two_dim_gaussian(n_iterations=10000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.DreamMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) + _method, 10, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), @@ -42,12 +38,7 @@ def banana(n_iterations=5000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.DreamMCMC, - n_chains=20, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 20, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -65,12 +56,7 @@ def correlated_gaussian(n_iterations=10000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.DreamMCMC, - n_chains=20, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 20, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -87,12 +73,7 @@ def annulus(n_iterations=10000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ problem = ft.RunMcmcMethodOnAnnulus( - method=pints.DreamMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 10, n_iterations, n_warmup) 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 index 8071a2508..cc36eecee 100644 --- a/pints/functionaltests/emcee_hammer_mcmc.py +++ b/pints/functionaltests/emcee_hammer_mcmc.py @@ -20,12 +20,7 @@ def two_dim_gaussian(n_iterations=10000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 10, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -42,12 +37,7 @@ def banana(n_iterations=10000, n_warmup=2000): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 10, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -65,12 +55,7 @@ def correlated_gaussian(n_iterations=8000, n_warmup=4000): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 10, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -87,12 +72,7 @@ def annulus(n_iterations=4000, n_warmup=2000): :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ problem = ft.RunMcmcMethodOnAnnulus( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 10, n_iterations, n_warmup) return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() @@ -110,12 +90,7 @@ def multimodal_gaussian(n_iterations=10000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ problem = ft.RunMcmcMethodOnMultimodalGaussian( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 10, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -132,12 +107,7 @@ def cone(n_iterations=10000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ problem = ft.RunMcmcMethodOnCone( - method=pints.EmceeHammerMCMC, - n_chains=10, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 10, n_iterations, n_warmup) return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() diff --git a/pints/functionaltests/haario_acmc.py b/pints/functionaltests/haario_acmc.py index c6e8df611..b3adfeb47 100644 --- a/pints/functionaltests/haario_acmc.py +++ b/pints/functionaltests/haario_acmc.py @@ -20,12 +20,7 @@ def two_dim_gaussian(n_iterations=4000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.HaarioACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -42,12 +37,7 @@ def banana(n_iterations=4000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.HaarioACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -65,12 +55,7 @@ def correlated_gaussian(n_iterations=8000, n_warmup=4000): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.HaarioACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() diff --git a/pints/functionaltests/haario_bardenet_acmc.py b/pints/functionaltests/haario_bardenet_acmc.py index a6aafd9f0..b55dcf68e 100644 --- a/pints/functionaltests/haario_bardenet_acmc.py +++ b/pints/functionaltests/haario_bardenet_acmc.py @@ -20,12 +20,7 @@ def two_dim_gaussian(n_iterations=4000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.HaarioBardenetACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -42,12 +37,7 @@ def banana(n_iterations=4000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.HaarioBardenetACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -65,12 +55,7 @@ def correlated_gaussian(n_iterations=8000, n_warmup=4000): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.HaarioBardenetACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -87,12 +72,7 @@ def annulus(n_iterations=4000, n_warmup=2000): :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ problem = ft.RunMcmcMethodOnAnnulus( - method=pints.HaarioBardenetACMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() diff --git a/pints/functionaltests/hamiltonian_mcmc.py b/pints/functionaltests/hamiltonian_mcmc.py index 8720673d9..43cf4ab57 100644 --- a/pints/functionaltests/hamiltonian_mcmc.py +++ b/pints/functionaltests/hamiltonian_mcmc.py @@ -20,13 +20,12 @@ def two_dim_gaussian(n_iterations=1000, n_warmup=200): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.HamiltonianMCMC, + 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() @@ -43,13 +42,12 @@ def banana(n_iterations=2000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.HamiltonianMCMC, + 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() @@ -66,13 +64,12 @@ def high_dim_gaussian(n_iterations=4000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ problem = ft.RunMcmcMethodOnHighDimensionalGaussian( - method=pints.HamiltonianMCMC, + 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() diff --git a/pints/functionaltests/mala_mcmc.py b/pints/functionaltests/mala_mcmc.py index 0de389afe..5bd8c28ad 100644 --- a/pints/functionaltests/mala_mcmc.py +++ b/pints/functionaltests/mala_mcmc.py @@ -20,13 +20,12 @@ def two_dim_gaussian(n_iterations=1000, n_warmup=200): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.MALAMCMC, + method=_method, n_chains=4, n_iterations=n_iterations, n_warmup=n_warmup, method_hyper_parameters=[[1.0, 1.0]] ) - return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -43,13 +42,12 @@ def banana(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.MALAMCMC, + method=_method, n_chains=4, n_iterations=n_iterations, n_warmup=n_warmup, method_hyper_parameters=[[0.8] * 2] ) - return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -66,7 +64,7 @@ def high_dim_gaussian(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ problem = ft.RunMcmcMethodOnHighDimensionalGaussian( - method=pints.MALAMCMC, + method=_method, n_chains=4, n_iterations=n_iterations, n_warmup=n_warmup, @@ -90,13 +88,12 @@ def correlated_gaussian(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.MALAMCMC, + method=_method, n_chains=4, n_iterations=n_iterations, n_warmup=n_warmup, method_hyper_parameters=[[1.0] * 6] ) - return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -113,13 +110,12 @@ def annulus(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ problem = ft.RunMcmcMethodOnAnnulus( - method=pints.MALAMCMC, + method=_method, n_chains=4, n_iterations=n_iterations, n_warmup=n_warmup, method_hyper_parameters=[[1.2] * 2], ) - return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() @@ -137,13 +133,12 @@ def multimodal_gaussian(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ problem = ft.RunMcmcMethodOnMultimodalGaussian( - method=pints.MALAMCMC, + method=_method, n_chains=4, n_iterations=n_iterations, n_warmup=n_warmup, method_hyper_parameters=[[2.0] * 2] ) - return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -160,13 +155,12 @@ def cone(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ problem = ft.RunMcmcMethodOnCone( - method=pints.MALAMCMC, + method=_method, n_chains=4, n_iterations=n_iterations, n_warmup=n_warmup, method_hyper_parameters=[[1.0, 1.0]], ) - return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() diff --git a/pints/functionaltests/metropolis_random_walk_mcmc.py b/pints/functionaltests/metropolis_random_walk_mcmc.py index a13c3057d..e920a3368 100644 --- a/pints/functionaltests/metropolis_random_walk_mcmc.py +++ b/pints/functionaltests/metropolis_random_walk_mcmc.py @@ -20,12 +20,7 @@ def two_dim_gaussian(n_iterations=4000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.MetropolisRandomWalkMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -42,12 +37,7 @@ def banana(n_iterations=4000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.MetropolisRandomWalkMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -65,12 +55,7 @@ def correlated_gaussian(n_iterations=8000, n_warmup=4000): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.MetropolisRandomWalkMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() diff --git a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py index c808c3f81..1048a2152 100644 --- a/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py +++ b/pints/functionaltests/monomial_gamma_hamiltonian_mcmc.py @@ -20,13 +20,12 @@ def two_dim_gaussian(n_iterations=1000, n_warmup=200): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.MonomialGammaHamiltonianMCMC, + 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() @@ -43,13 +42,12 @@ def banana(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.MonomialGammaHamiltonianMCMC, + 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() @@ -66,13 +64,12 @@ def high_dim_gaussian(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ problem = ft.RunMcmcMethodOnHighDimensionalGaussian( - method=pints.MonomialGammaHamiltonianMCMC, + 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() @@ -89,18 +86,13 @@ def correlated_gaussian(n_iterations=2000, n_warmup=500): For details of the solved problem, see :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ - n_warmup = 500 - if n_warmup > n_iterations // 2: - n_warmup = n_iterations // 10 - problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.MonomialGammaHamiltonianMCMC, + 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() @@ -117,13 +109,12 @@ def annulus(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ problem = ft.RunMcmcMethodOnAnnulus( - method=pints.MonomialGammaHamiltonianMCMC, + 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() @@ -141,13 +132,12 @@ def multimodal_gaussian(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ problem = ft.RunMcmcMethodOnMultimodalGaussian( - method=pints.MonomialGammaHamiltonianMCMC, + 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() @@ -164,13 +154,12 @@ def cone(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ problem = ft.RunMcmcMethodOnCone( - method=pints.MonomialGammaHamiltonianMCMC, + 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() diff --git a/pints/functionaltests/no_u_turn_mcmc.py b/pints/functionaltests/no_u_turn_mcmc.py index d627690ea..7ca868e94 100644 --- a/pints/functionaltests/no_u_turn_mcmc.py +++ b/pints/functionaltests/no_u_turn_mcmc.py @@ -20,12 +20,7 @@ def two_dim_gaussian(n_iterations=1000, n_warmup=200): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.NoUTurnMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -42,12 +37,7 @@ def banana(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.NoUTurnMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -64,12 +54,7 @@ def high_dim_gaussian(n_iterations=4000, n_warmup=1000): :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ problem = ft.RunMcmcMethodOnHighDimensionalGaussian( - method=pints.NoUTurnMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) 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 index b0390255b..f525d40fb 100644 --- a/pints/functionaltests/population_mcmc.py +++ b/pints/functionaltests/population_mcmc.py @@ -20,11 +20,7 @@ def two_dim_gaussian(n_iterations=20000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.PopulationMCMC, - n_chains=1, - n_iterations=n_iterations, - n_warmup=n_warmup - ) + _method, 1, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), @@ -42,12 +38,7 @@ def banana(n_iterations=20000, n_warmup=5000): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.PopulationMCMC, - n_chains=1, - n_iterations=n_iterations, - n_warmup=n_warmup - ) - + _method, 1, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -70,7 +61,7 @@ def multimodal_gaussian( method_hyper_parameters = [n_temperatures] problem = ft.RunMcmcMethodOnMultimodalGaussian( - method=pints.PopulationMCMC, + method=_method, n_chains=1, n_iterations=n_iterations, n_warmup=n_warmup, diff --git a/pints/functionaltests/relativistic_mcmc.py b/pints/functionaltests/relativistic_mcmc.py index 711acc618..bbace567d 100644 --- a/pints/functionaltests/relativistic_mcmc.py +++ b/pints/functionaltests/relativistic_mcmc.py @@ -20,13 +20,12 @@ def two_dim_gaussian(n_iterations=1000, n_warmup=200): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.RelativisticMCMC, + 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() @@ -43,13 +42,12 @@ def banana(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.RelativisticMCMC, + 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() @@ -66,13 +64,12 @@ def high_dim_gaussian(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ problem = ft.RunMcmcMethodOnHighDimensionalGaussian( - method=pints.RelativisticMCMC, + 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() @@ -90,13 +87,12 @@ def correlated_gaussian(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.RelativisticMCMC, + 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() @@ -113,13 +109,12 @@ def annulus(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ problem = ft.RunMcmcMethodOnAnnulus( - method=pints.RelativisticMCMC, + 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() @@ -137,13 +132,12 @@ def multimodal_gaussian(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ problem = ft.RunMcmcMethodOnMultimodalGaussian( - method=pints.RelativisticMCMC, + 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() @@ -160,13 +154,12 @@ def cone(n_iterations=2000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ problem = ft.RunMcmcMethodOnCone( - method=pints.RelativisticMCMC, + 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() diff --git a/pints/functionaltests/slice_stepout_mcmc.py b/pints/functionaltests/slice_stepout_mcmc.py index 876c97762..40c78b91c 100644 --- a/pints/functionaltests/slice_stepout_mcmc.py +++ b/pints/functionaltests/slice_stepout_mcmc.py @@ -20,12 +20,7 @@ def two_dim_gaussian(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnTwoDimGaussian`. """ problem = ft.RunMcmcMethodOnTwoDimGaussian( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -43,12 +38,7 @@ def correlated_gaussian(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnCorrelatedGaussian`. """ problem = ft.RunMcmcMethodOnCorrelatedGaussian( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -65,12 +55,7 @@ def banana(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnBanana`. """ problem = ft.RunMcmcMethodOnBanana( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -87,12 +72,7 @@ def high_dim_gaussian(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnHighDimensionalGaussian`. """ problem = ft.RunMcmcMethodOnHighDimensionalGaussian( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -109,12 +89,7 @@ def annulus(n_iterations=10000, n_warmup=2000): :class:`pints.functionaltests.RunMcmcMethodOnAnnulus`. """ problem = ft.RunMcmcMethodOnAnnulus( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess() @@ -132,12 +107,7 @@ def multimodal_gaussian(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnMultimodalGaussian`. """ problem = ft.RunMcmcMethodOnMultimodalGaussian( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'kld': problem.estimate_kld(), 'mean-ess': problem.estimate_mean_ess() @@ -154,12 +124,7 @@ def cone(n_iterations=5000, n_warmup=500): :class:`pints.functionaltests.RunMcmcMethodOnCone`. """ problem = ft.RunMcmcMethodOnCone( - method=pints.SliceStepoutMCMC, - n_chains=4, - n_iterations=n_iterations, - n_warmup=n_warmup, - ) - + _method, 4, n_iterations, n_warmup) return { 'distance': problem.estimate_distance(), 'mean-ess': problem.estimate_mean_ess()