Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

fitbenchmarking / fitbenchmarking / 2330948078

16 May 2022 - 9:26 coverage decreased (-0.2%) to 86.542%
2330948078

Pull #1036

github

GitHub
Merge f94846412 into ed08b4d37
Pull Request #1036: Enable max runtime in curve fitting

0 of 46 new or added lines in 6 files covered. (0.0%)

5 existing lines in 4 files now uncovered.

3421 of 3953 relevant lines covered (86.54%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/fitbenchmarking/controllers/matlab_stats_controller.py
1
"""
2
Implements a controller for MATLAB Statistics Toolbox
3
"""
4

5
import matlab
!
6
import numpy as np
!
7

8
from fitbenchmarking.controllers.base_controller import Controller
!
9
from fitbenchmarking.controllers.matlab_mixin import MatlabMixin
!
10

11

12
class MatlabStatsController(MatlabMixin, Controller):
!
13
    """
14
    Controller for MATLAB Statistics Toolbox fitting (nlinfit)
15
    """
16

17
    algorithm_check = {
!
18
        'all': ['Levenberg-Marquardt'],
19
        'ls': ['Levenberg-Marquardt'],
20
        'deriv_free': [],
21
        'general': [],
22
        'simplex': [],
23
        'trust_region': ['Levenberg-Marquardt'],
24
        'levenberg-marquardt': ['Levenberg-Marquardt'],
25
        'gauss_newton': [],
26
        'bfgs': [],
27
        'conjugate_gradient': [],
28
        'steepest_descent': [],
29
        'global_optimization': []}
30

31
    controller_name = 'matlab_stats'
!
32

33
    incompatible_problems = ['mantid']
!
34

35
    def __init__(self, cost_func):
!
36
        """
37
        Initialises variables used for temporary storage.
38

39
        :param cost_func: Cost function object selected from options.
40
        :type cost_func: subclass of
41
                :class:`~fitbenchmarking.cost_func.base_cost_func.CostFunc`
42
        """
43
        super().__init__(cost_func)
!
44
        self.x_data_mat = None
!
45
        self.y_data_mat = None
!
46
        self._status = None
!
47
        self.result = None
!
48

49
    def setup(self):
!
50
        """
51
        Setup for Matlab fitting
52
        """
53
        # Convert initial params into matlab array
54
        self.y_data_mat = matlab.double(np.zeros(self.data_y.shape).tolist())
!
55
        self.initial_params_mat = matlab.double([self.initial_params])
!
56
        self.x_data_mat = matlab.double(self.data_x.tolist())
!
57

58
        # serialize cost_func.eval_r and open within matlab engine
59
        # so that matlab fitting function can be called
NEW
60
        self.eng.workspace['eval_f'] = self.py_to_mat('eval_r')
!
61
        self.eng.evalc('f_wrapper = @(p, x)double(eval_f(p))')
!
62

UNCOV
63
    def fit(self):
!
64
        """
65
        Run problem with Matlab Statistics Toolbox
66
        """
67

68
        self.result = self.eng.nlinfit(self.x_data_mat, self.y_data_mat,
!
69
                                       self.eng.workspace['f_wrapper'],
70
                                       self.initial_params_mat, nargout=1)
71
        self._status = 0 if self.result is not None else 1
!
72

73
    def cleanup(self):
!
74
        """
75
        Convert the result to a numpy array and populate the variables results
76
        will be read from.
77
        """
78
        if self._status == 0:
!
79
            self.flag = 0
!
80
        else:
81
            self.flag = 2
!
82

83
        self.final_params = self.result[0]
!
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc