atomcloud.functions.multi_base module
Created on Sat Mar 19 14:49:49 2022
@author: hofer
- class atomcloud.functions.multi_base.ConstrainedMultiFunction(funcs, constraints=None)[source]
Bases:
MultiFunctionBaseCreates a multi function which takes a list of functions and a list of constraints. The constraints are the input arguments which should have the same value when in a sub-functions parameters. The individual function parameters are then mapped to a single list of arguments which are passed to the constrained multi function.
The fit function arguments are then passed to the multi function which calls the functions with the correct parameters.
- Parameters:
funcs (list[callable]) –
constraints (list[str] | None) –
- arg_list(arg_param_map, funcs_args)[source]
Opposite to above, makes a list of lists of the same size as the parameters. Each entry is the index of that variable in the single argument list for the scipy/jaxfit compatible fit function
- Parameters:
arg_param_map (dict[str, list[tuple[int, int]]]) – See return of get_arg_map function for detailed description of this argument.
funcs_args (list[list[str]]) – all arguments of the individual functions excluding the first coordinate argument
- Returns:
List of lists of the same size as the parameters. Each entry is the index of that variable in the 1D
- Return type:
list[list[int]]
- check_contraint_strs(constraints, unique_args)[source]
Checks that the constraints are valid strings and that they are arguments of the functions.
- Parameters:
constraints (list[str]) – list of strings which are the names of the parameters which are constrained to between the individual functions comprising the multi-function.
unique_args (list[str]) – the unique input arguments across all the individual functions comprising the multi-function.
- Return type:
None
- check_parameters(aparams)[source]
Checks that the list of list of func parameters is the correct type and that each sublist is the correct length.
- Parameters:
aparams (list[list[float]]) – list of lists of function parameters for the individual functions comprising the multi-function.
- Return type:
None
- create_args_to_params()[source]
Creates a function which maps the 1D list of fit function arguments to the 2D list of function parameters. We use a creator function wrapper so that the args_to_params function can be used in a JAX (i.e. to self argument)
- fit_function(coords, *args)[source]
The fit function which takes a list of arguments and converts them to the 2D list of function parameters and then call the multi-function. This is compatible with the scipy/jaxfit curvefit function input type which requires a single argument list.
- Parameters:
coords (ndarray | Iterable[ndarray]) – coordinates of the data being fit
*args (float) – list of multi-function arguments which are converted then
comprising (converted to parameters for the individual functions) –
multi-function. (the) –
- Returns:
The value of the multi-function at the given coordinates.
- Return type:
ndarray
- get_arg_map(constraints, func_args)[source]
Creates a dictionary which maps the constrained arguments to the individual function parameters. :param constraints: list of constraints (input parameters) :param func_args: list of lists of individual function input arguments
- Returns:
Dictionary which maps the index of the single argument list for the scipy/jaxfit compatible fit function to the two indices of the individual function parameters. The first index is the index of the function in the list of functions and the second index is the index of the parameter in the list of parameters for that function.
- Parameters:
constraints (list[str]) –
func_args (list[list[str]]) –
- Return type:
dict[str, list[tuple[int, int]]]
- params_to_args(params)[source]
Converts the list of lists of individual function parameters into a 1D list of arguments for the fit function compatible with SciPy/JAX curvefit.
- Parameters:
params (list[list[float]]) – list of lists of function parameters for the individual functions comprising the multi-function.
- Returns:
Single list of arguments for the fit function which is compatible with the SciPy/JAX curvefit function.
- Return type:
list[float]
- class atomcloud.functions.multi_base.MultiFunctionBase(funcs)[source]
Bases:
ABCClass which allows multiple functions to be added together to form a single function. This is useful for multi function fitting.
- Parameters:
funcs (list[callable]) –
- function(coords, function_parameters)[source]
Multi function which adds together the functions passed to the class initializer.
- Parameters:
coords (ndarray | Iterable[ndarray]) – coordinates of the data
function_parameters (list[list[float]]) – list of parameters for each function
- Returns:
The value of the multi function at the given coordinates
- Return type:
ndarray