fitbenchmarking.parsing.fitting_problem module¶
Implements the FittingProblem class, this will be the object that inputs are parsed into before being passed to the controllers
-
class
fitbenchmarking.parsing.fitting_problem.
FittingProblem
(options)¶ Bases:
object
Definition of a fitting problem, which will be populated by a parser from a problem definition file.
This defines a fitting problem where, given a set of data points , associated errors , and a model function , we find the optimal parameters in the least-squares sense by solving:
where is a vector of length , and we start from a given intial guess for the optimal parameters.
-
additional_info
= None¶ dict Container for software specific information. This should be avoided if possible.
-
correct_data
()¶ Strip data that overruns the start and end x_range, and approximate errors if not given. Modifications happen on member variables.
-
data_e
= None¶ numpy array The errors
-
data_x
= None¶ numpy array The x-data
-
data_y
= None¶ numpy array The y-data
-
end_x
= None¶ float The end of the range to fit model data over (if different from entire range) (/float/)
-
equation
= None¶ string Equation (function or model) to fit against data
-
eval_f
(params, x=None)¶ Function evaluation method
Parameters: - params (list) – parameter value(s)
- x (numpy array) – x data values or None, if None this uses self.data_x
Returns: y data values evaluated from the function of the problem
Return type: numpy array
-
eval_r
(params, x=None, y=None, e=None)¶ Calculate residuals and weight them if using errors
Parameters: - params (list) – The parameters to calculate residuals for
- x (numpy array, optional) – x data points, defaults to self.data_x
- y (numpy array, optional) – y data points, defaults to self.data_y
- e (numpy array, optional) – error at each data point, defaults to self.data_e
Returns: The residuals for the datapoints at the given parameters
Return type: numpy array
-
eval_r_norm
(params, x=None, y=None, e=None)¶ Evaluate the square of the L2 norm of the residuals
Parameters: - params (list) – The parameters to calculate residuals for
- x (numpy array, optional) – x data points, defaults to self.data_x
- y (numpy array, optional) – y data points, defaults to self.data_y
- e (numpy array, optional) – error at each data point, defaults to self.data_e
Returns: The sum of squares of residuals for the datapoints at the given parameters
Return type: numpy array
-
eval_starting_params
(param_set)¶ Evaluate the function using the starting parameters.
Parameters: param_set (int) – The index of the parameter set in starting_params Returns: Results from evaluation Return type: numpy array
-
function
= None¶ Callable function
-
get_function_params
(params)¶ Return the function definition in a string format for output
Parameters: params (list) – The parameters to use in the function string Returns: Representation of the function example format: ‘b1 * (b2+x) | b1=-2.0, b2=50.0’ Return type: string
-
multifit
= None¶ bool Used to check if a problem is using multifit.
-
name
= None¶ string Name (title) of the fitting problem
-
param_names
¶ Utility function to get the parameter names
Returns: the names of the parameters Return type: list of str
-
sorted_index
= None¶ numpy array The index for sorting the data (used in plotting)
-
start_x
= None¶ float The start of the range to fit model data over (if different from entire range)
-
starting_values
= None¶ list of dict Starting values of the fitting parameters
e.g.
[{p1_name: p1_val1, p2_name: p2_val1, ...}, {p1_name: p1_val2, ...}, ...]
-
value_ranges
= None¶ dict Smallest and largest values of interest in the data
e.g.
{p1_name: [p1_min, p1_max], ...}
-
verify
()¶ Basic check that minimal set of attributes have been set.
Raise FittingProblemError if object is not properly initialised.
-
-
fitbenchmarking.parsing.fitting_problem.
correct_data
(x, y, e, startx, endx, use_errors)¶ Strip data that overruns the start and end x_range, and approximate errors if not given.
Parameters: - x (np.array) – x data
- y (np.array) – y data
- e (np.array) – error data
- startx (float) – minimum x value
- endx (float) – maximum x value
- use_errors (bool) – whether errors should be added if not present