Skip to content

Commit

Permalink
Added xNES tests (requires fix from #1517).
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelClerx committed Jan 2, 2024
1 parent 6bb0255 commit 6970872
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pints/cptests/_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ def __init__(self, error, x0, sigma0, boundaries, transformation, method,
controller.set_max_iterations(n_iterations)
controller.set_max_unchanged_iterations(None)
controller.set_log_to_screen(False)
if use_guessed:
controller.set_f_guessed_tracking(True)
if method_hyper_parameters is not None:
controller.optimiser().set_hyperparameters(method_hyper_parameters)
self._x, self._f = controller.run()
Expand Down
82 changes: 82 additions & 0 deletions pints/cptests/xnes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env python3
#
# Change point tests for XNES.
#
# This file is part of PINTS (https://github.com/pints-team/pints/) which is
# released under the BSD 3-clause license. See accompanying LICENSE.md for
# copyright notice and full license details.
#
import pints
import pints.cptests as cpt


def bounded_fitzhugh_nagumo(n_iterations=100):
"""
Tests :class:`pints.XNES` on a bounded Fitzhugh-Nagumo model, and returns
a dictionary with ``error`` and ``distance``.
For details of the solved problem, see
:class:`pints.cptests.RunOptimiserOnBoundedUntransformedLogistic`.
"""
problem = cpt.RunOptimiserOnBoundedFitzhughNagumo(
_method, n_iterations, _fguess)
return {
'error': problem.error(),
'distance': problem.distance()
}


def bounded_untransformed_logistic(n_iterations=300):
"""
Tests :class:`pints.XNES` on a bounded logistic model without
transformations, and returns a dictionary with ``error`` and ``distance``.
For details of the solved problem, see
:class:`pints.cptests.RunOptimiserOnBoundedUntransformedLogistic`.
"""
problem = cpt.RunOptimiserOnBoundedUntransformedLogistic(
_method, n_iterations, _fguess)
return {
'error': problem.error(),
'distance': problem.distance()
}


def rosenbrock(n_iterations=100):
"""
Tests :class:`pints.XNES` on a Rosenbrock error and returns a dictionary
with ``error`` and ``distance``.
For details of the solved problem, see
:class:`pints.cptests.RunOptimiserOnRosenbrockError`.
"""
problem = cpt.RunOptimiserOnRosenbrockError(_method, n_iterations, _fguess)
return {
'error': problem.error(),
'distance': problem.distance()
}


def two_dim_parabola(n_iterations=50):
"""
Tests :class:`pints.XNES` on a two-dimensional parabolic error and returns
a dictionary with entries ``error`` and ``distance``.
For details of the solved problem, see
:class:`pints.cptests.RunOptimiserOnTwoDimParabola`.
"""
problem = cpt.RunOptimiserOnTwoDimParabola(_method, n_iterations, _fguess)
return {
'error': problem.error(),
'distance': problem.distance()
}


_method = pints.XNES
_fguess = True
_change_point_tests = [
bounded_fitzhugh_nagumo,
bounded_untransformed_logistic,
rosenbrock,
two_dim_parabola,
]

0 comments on commit 6970872

Please sign in to comment.