Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I1083 l bfgs optimiser #1149

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
5 changes: 4 additions & 1 deletion pints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def version(formatted=False):
optimise,
Optimiser,
PopulationBasedOptimiser,
TriangleWaveTransform,
LineSearchBasedOptimiser,
TriangleWaveTransform
)
from ._optimisers._cmaes import CMAES
from ._optimisers._cmaes_bare import BareCMAES
Expand All @@ -175,6 +176,8 @@ def version(formatted=False):
from ._optimisers._pso import PSO
from ._optimisers._snes import SNES
from ._optimisers._xnes import XNES
from ._optimisers._bfgs_scipy import BFGS_scipy
from ._optimisers._bfgs_linesearch import BFGS


#
Expand Down
25 changes: 25 additions & 0 deletions pints/_optimisers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,29 @@ def set_hyper_parameters(self, x):
self.set_population_size(x[0])


class LineSearchBasedOptimiser(Optimiser):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure this is the best way to do it yet, but let's leave all that till after we have a working prototype!

"""
Base class for optimisers that incorporate a line search
within their algorithm.

Extends :class:`Optimiser`.
"""

def __init__(self, x0, sigma0=None, boundaries=None):
super(LineSearchBasedOptimiser, self).__init__(x0, sigma0, boundaries)

self._evaluator = None

def _set_function_evaluator(self, function):

f = function
if self.needs_sensitivities:
f = f.evaluateS1

# Create evaluator object
self._evaluator = pints.SequentialEvaluator(f)


class OptimisationController(object):
"""
Finds the parameter values that minimise an :class:`ErrorMeasure` or
Expand Down Expand Up @@ -337,6 +360,8 @@ def __init__(
elif not issubclass(method, pints.Optimiser):
raise ValueError('Method must be subclass of pints.Optimiser.')
self._optimiser = method(x0, sigma0, boundaries)
if issubclass(method, pints.LineSearchBasedOptimiser):
self._optimiser._set_function_evaluator(self._function)

# Check if sensitivities are required
self._needs_sensitivities = self._optimiser.needs_sensitivities()
Expand Down
Loading