Skip to content

Commit

Permalink
Merge 293d6c0 into ba4eb70
Browse files Browse the repository at this point in the history
  • Loading branch information
tyronerees committed Oct 31, 2019
2 parents ba4eb70 + 293d6c0 commit 71b470d
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/source/contributors/extending_fitbenchmarking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ that the fitting software can use, and converting the result back to a
standardised format (numpy arrays). As well as this, the controller must be
written so that the fitting is separated from the preparation wherever possible
in order to give accurate timings for the fitting. Examples of these
controllers can be found in ``fitbenchmarking/fitting/software_controllers``.
controllers can be found in ``fitbenchmarking/fitting/controllers``.

In order to add a new controller, you will need to:

1. Create a new subclass of BaseSoftwareController in
``fitbenchmarking/fitting/software_controllers``.
``fitbenchmarking/fitting/controllers``.
This should implement 4 functions:

- ``__init__()``: Initialise anything that is needed specifically for the
Expand Down
10 changes: 9 additions & 1 deletion docs/source/users/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ These include:
The software to use in fitting as a string or list of strings.
Selected softwares will be benchmarked.

Available options are ``"mantid"``, ``"sasview"``, and ``"scipy"``.
Available options are ``"mantid"``, ``"sasview"``, ``"scipy"`` and ``"dfogn"``.

``results_dir``
---------------
Expand Down Expand Up @@ -118,11 +118,19 @@ Scipy:
- ``"dogbox"``
- ``"lm"``
- and ``"trf"``


Information about these can be found on the
`Scipy documentation
<https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.least_squares.html>`__

DFO-GN:
- ``"dfogn"``
Information about this can be found on the
`DFO-GN documentation
<http://people.maths.ox.ac.uk/robertsl/dfogn/>`__


``comparison_mode``
-------------------
The comparison mode is used when displaying results to select the value
Expand Down
7 changes: 6 additions & 1 deletion fitbenchmarking/fitbenchmark_one_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
from fitbenchmarking.fitting.controllers.scipy_controller import ScipyController
except ImportError:
ScipyController = None
try:
from fitbenchmarking.fitting.controllers.dfogn_controller import DFOGNController
except ImportError:
DFOGNController = None


def fitbm_one_prob(user_input, problem):
Expand All @@ -43,7 +47,8 @@ def fitbm_one_prob(user_input, problem):

controllers = {'mantid': MantidController,
'sasview': SasviewController,
'scipy': ScipyController}
'scipy': ScipyController,
'dfogn': DFOGNController}

if software in controllers:
controller = controllers[software](problem, user_input.use_errors)
Expand Down
3 changes: 2 additions & 1 deletion fitbenchmarking/fitbenchmarking_default_options.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"Simplex","SteepestDescent",
"Trust Region"],
"scipy" : ["lm", "trf", "dogbox"],
"sasview" : ["amoeba", "lm", "newton", "de", "pt", "mp"]
"sasview" : ["amoeba", "lm", "newton", "de", "pt", "mp"],
"dfogn" : ["dfogn"]
},

"comparison_mode" : "both"
Expand Down
66 changes: 66 additions & 0 deletions fitbenchmarking/fitting/controllers/dfogn_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
Implements a controller for DFO-GN
http://people.maths.ox.ac.uk/robertsl/dfogn/
"""

import dfogn
import numpy as np

from fitbenchmarking.fitting.controllers.base_controller import Controller

class DFOGNController(Controller):
"""
Controller for the DFO-GN fitting software.
"""

def __init__(self, problem, use_errors):
"""
Initialises variable used for temporary storage.
"""
super(DFOGNController, self).__init__(problem, use_errors)

self._soln = None
self._popt = None
self._pinit = None
self._use_errors = use_errors

def setup(self):
"""
Setup for DFO-GN
"""
self._pinit = np.asarray(self.initial_params)

def _prediction_error(self,p):
f = self.data_y - self.problem.eval_f(x=self.data_x,
params=p,
function_id=self.function_id)
if self._use_errors:
f = f/self.data_e

return f

def fit(self):
"""
Run problem with Scipy.
"""
popt = None
self.success = False

self._soln = dfogn.solve(self._prediction_error,
self._pinit)

if (self._soln.flag == 0):
self.success = True

self._popt = self._soln.x

def cleanup(self):
"""
Convert the result to a numpy array and populate the variables results
will be read from.
"""
if self.success:
self.results = self.problem.eval_f(x=self.data_x,
params=self._popt,
function_id=self.function_id)
self.final_params = self._popt
16 changes: 14 additions & 2 deletions fitbenchmarking/fitting/tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
SasviewController
from fitbenchmarking.fitting.controllers.scipy_controller import \
ScipyController
from fitbenchmarking.fitting.controllers.scipy_controller import \
ScipyController
from fitbenchmarking.fitting.controllers.dfogn_controller import \
DFOGNController
from fitbenchmarking.parsing.parse_nist_data import FittingProblem


Expand All @@ -23,8 +27,8 @@ def misra1a_file():
main_dir = os.path.dirname(os.path.normpath(parent_dir))
root_dir = os.path.dirname(os.path.normpath(main_dir))
bench_prob_dir = os.path.join(root_dir, 'benchmark_problems')
fname = os.path.join(bench_prob_dir, 'NIST', 'low_difficulty',
'Misra1a.dat')
fname = os.path.join(bench_prob_dir, 'simple_tests',
'cubic.dat')

return fname

Expand Down Expand Up @@ -124,6 +128,14 @@ def test_scipy(self):
controller.minimizer = 'lm'
self.shared_testing(controller)

def test_dfogn(self):
"""
DFOGNController: Tests for output shape
"""
controller = DFOGNController(self.problem, True)
controller.minimizer = 'dfogn'
self.shared_testing(controller)

def shared_testing(self, controller):
"""
Utility function to run controller and check output is in generic form
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
license='GPL-3.0',
packages=find_packages(),
install_requires=['docutils', 'numpy<1.17', 'matplotlib<3.0',
'scipy>=0.18,<1.3', 'bumps', 'sasmodels', 'lxml'],
'scipy>=0.18,<1.3', 'bumps', 'sasmodels', 'lxml',
'dfogn'],
zip_safe=False,

cmdclass={
Expand Down

0 comments on commit 71b470d

Please sign in to comment.