-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from fitbenchmarking/215_ralfit
215 Adding RALfit
- Loading branch information
Showing
8 changed files
with
139 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
SCRIPTPATH=$PWD | ||
|
||
git clone https://github.com/ralna/RALFit | ||
|
||
cd $SCRIPTPATH/RALFit/libRALFit/ | ||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
python setup.py build_ext | ||
python setup.py install | ||
|
||
cd $SCRIPTPATH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
""" | ||
Implements a controller for RALFit | ||
https://github.com/ralna/RALFit | ||
""" | ||
|
||
import ral_nlls | ||
from scipy.optimize._numdiff import approx_derivative | ||
|
||
from fitbenchmarking.fitting.controllers.base_controller import Controller | ||
|
||
|
||
class RALFitController(Controller): | ||
""" | ||
Controller for the RALFit fitting software. | ||
""" | ||
|
||
def __init__(self, problem, use_errors): | ||
""" | ||
Initialises variable used for temporary storage. | ||
""" | ||
super(RALFitController, self).__init__(problem, use_errors) | ||
|
||
self._x = None | ||
self._inform = None | ||
|
||
def setup(self): | ||
""" | ||
Setup for RALFit | ||
""" | ||
pass | ||
|
||
def _eval_f_arg_swap(self, params, x): | ||
return self.problem.eval_f(x=x, | ||
params=params, | ||
function_id=self.function_id) | ||
|
||
def _prediction_error(self, params, x, y): | ||
return self._eval_f_arg_swap(params, x) - y | ||
|
||
def _jac(self, params, x, y): | ||
return approx_derivative(self._eval_f_arg_swap, | ||
params, | ||
args=tuple([x])) | ||
|
||
def fit(self): | ||
""" | ||
Run problem with RALFit. | ||
""" | ||
self.success = False | ||
try: | ||
(self._x, self._inform) = ral_nlls.solve(self.initial_params, | ||
self._prediction_error, | ||
self._jac, | ||
params=(self.data_x, | ||
self.data_y)) | ||
self.success = True | ||
except: | ||
self.success = False | ||
|
||
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._x, | ||
function_id=self.function_id) | ||
self.final_params = self._x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters