3.1. Implemented Models.
3.1.1. minifit.fit_base module
Module containing logger and FitBase class.
- class minifit.fit_base.FitBase(filename, **kwargs)[source]
Bases:
ABCBase class for all fitting classes
- __init__(filename, **kwargs)[source]
Common constructor.
Arguments:
- filename:
(str) name of the file containing the data
Keyword arguments:
- guess:
(tuple) A guess of the optimal parameters for the model. The number of guesses should match the arguments that the model function expects. For example, for
PolyFitwhenorderis 2: ax^2 + bx + c it expects(val1, val2, val3)etc. It is the case because model function expects three values. For ax+b it would expect 2, etc. Otherwise, an exception will be raised. If not passed, a default guess adequate for the model function will be used.- auto_guess:
(bool) If true, tries to fit until chosen
precisionis reached. Default false.- auto_range:
(tuple) Sets boundaries for each parameter of the guess. If not set, the default range is used. Only used if auto_guess is True. Instead of
guess = (5., 10., -3.)passauto_range = ((0.,10.), (5., 15.), (-40., 30.))If fitting takes a lot of time, giving a better range might be helpful.- precision:
(float) Used by the
auto_guessfeature to control the fitting accuracy. The precision parameter represents the maximum allowable error between the fitted curve and the actual data points. During the fitting process, MiniFit continuously refines the parameters until the absolute sum of differences and the square root error between the model predictions and the data fall below this specified precision value. If the precision is set to 0.4, for instance, the fitted curve’s error will be less than 0.4 for both the absolute sum of differences and the square root error. Default value is 0.4. Only used ifauto_guessis True. Ifauto_guessis True and fitting takes a lot of time, lowering theprecisionmay be necessary for convergence. Lowering the precision will make the fitting process faster, but the quality of the popt may be worse.- shift:
- (bool) If true, shift the data. Default false.
Data can be shifted and it may make the convergence of the least squares algorithm easier.
- type_of_fit:
(string) Default:
Name of the model. Used for displaying results in the terminal.- label_type:
(string) Default:
model_fit. Used for part of the filename of the graph.- state_info:
(list of str) Descriptions for each data set in ydata. Each string should describe the corresponding data set. If provided, the number of descriptions must match the number of columns in ydata. Default is an empty list.
- context_setter(xdata, ydata)[source]
If overwritten can return data useful for setting guess in random_guess and default_guess
- label_type = 'model_fit'
- abstract print_info(popt)[source]
Print info about popt in the format adequate for the model function.
- abstract random_guess(context)[source]
Random guess adequate for the model function with constraints chosen by the user.
- read_data(filename)[source]
Reads data from each column then shifts the data if shift is set to True.
- type_of_fit = 'Name of the model'
- x_label = 'x_label'
- y_label = 'y_label'
3.1.2. minifit.poly module
Module containing PolyFit class for curve fitting with polynomials.
- class minifit.poly.PolyFit(filename, **kwargs)[source]
Bases:
FitBaseThis class makes a polynomial curve fitting. Order of the polynomial can be chosen. It reads data from a file given as the first argument. The data file must contain at least two columns. The first column represents x values, the second and following columns are the y values.
- __init__(filename, **kwargs)[source]
Arguments:
- filename:
(string) Name of the file that contains data.
Keyword arguments:
- order:
(int) Unique for PolyFit. Order of the polynomial. Optional. Default 1.
- guess:
(tuple) A guess of the optimal parameters for the model. The number of guesses should match the arguments that the model function expects. For ax^2 + bx + c it expects
(val1, val2, val3)such as(10, 5, -100). For ax + b it expects(val1, val2), such as(-1, 1), etc. Otherwise, an exception will be raised. If not passed, a default guess adequate for the model function will be used.- auto_guess:
(bool) If true, tries to fit until chosen
precisionis reached. Default false.- auto_range:
(tuple) Sets boundaries for each parameter of the
guess. If not set, the default range is used. Only used ifauto_guessis True. Instead ofguess = (5., 10., -3.)passauto_range = ((0.,10.), (5., 15.), (-40., 30.))If fitting takes a lot of time, giving a better range might be helpful.- precision:
(float) Used by the
auto_guessfeature to control the fitting accuracy. The precision parameter represents the maximum allowable error between the fitted curve and the actual data points. During the fitting process, MiniFit continuously refines the parameters until the absolute sum of differences and the square root error between the model predictions and the data fall below this specified precision value. If the precision is set to 0.4, for instance, the fitted curve’s error will be less than 0.4 for both the absolute sum of differences and the square root error. Default value is 0.4. Only used ifauto_guessis True. Ifauto_guessis True and fitting takes a lot of time, lowering theprecisionmay be necessary for convergence. Lowering the precision will make the fitting process faster, but the quality of the popt may be worse.- shift:
- (bool) If true, shift the data. Default false.
Data can be shifted and it may make the convergence of the least squares algorithm easier.
- label_type = 'polynomial_fit'
- random_guess(context)[source]
Random guess adequate for the model function with constraints chosen by the user.
- type_of_fit = 'Polynomials'
3.1.3. minifit.morse module
Module containing MorseFit class for curve fitting with morse.
- class minifit.morse.MorseFit(filename, **kwargs)[source]
Bases:
FitBaseThis class makes curve fitting using the Generalized Morse Potential Formula. It reads data from a file given as the first argument. The data file must contain at least two columns. The first column represents x values, the second and following columns are the y values.
- __init__(filename, **kwargs)[source]
Arguments:
- filename:
(string) Name of the file that contains data.
Keyword arguments:
- guess:
(tuple) A guess of the optimal parameters for the model. The number of guesses should match the arguments that the model function expects. The model is defined as:
de*(1-np.exp(-b0*(x-re)/re*(1+b1*(b0*(x-re)/re)+b2*(b0*(x-re)/re)**2 +b3*(b0*(x-re)/re)**3+b4*(b0*(x-re)/re)**4+b5*(b0*(x-re)/re)**5 +b6*(b0*(x-re)/re)**6)))**2-deit expects a tuple, such as:(re, de, b0, b1, b2, b3, b4, b5, b6)or(1.1, 109.36948, 2.919051390412818, 2.6012960451552996, 3.9624444493272435, -3.836256017508912, 0.07368753155656269, 0.0885673770356121, 0.04092539988145455)- auto_guess:
(bool) If true, tries to fit until chosen
precisionis reached. Default false.- auto_range:
(tuple) Sets boundaries for each parameter of the guess. If not set, the default range is used. Only used if auto_guess is True. Instead of
guess = (re, de, b0, b1, b2, b3, b4, b5, b6)passauto_range = ( (-100, 100), (-300, 300), (-300, -300), (-300, 300), (-300, 300), (-300, 300), (-300, 300), (-300, 300) )If fitting takes a lot of time, giving a better range might be helpful.- precision:
(float) Used by the
auto_guessfeature to control the fitting accuracy. The precision parameter represents the maximum allowable error between the fitted curve and the actual data points. During the fitting process, MiniFit continuously refines the parameters until the absolute sum of differences and the square root error between the model predictions and the data fall below this specified precision value. If the precision is set to 0.4, for instance, the fitted curve’s error will be less than 0.4 for both the absolute sum of differences and the square root error. Default value is 0.4. Only used ifauto_guessis True. Ifauto_guessis True and fitting takes a lot of time, lowering theprecisionmay be necessary for convergence. Lowering the precision will make the fitting process faster, but the quality of the popt may be worse.- shift:
- (bool) If true, shift the data. Default false.
Data can be shifted and it may make the convergence of the least squares algorithm easier.
- context_setter(xdata, ydata)[source]
If overwritten can return data useful for setting guess in random_guess and default_guess
- label_type = 'morse_fit'
- random_guess(context)[source]
Random guess adequate for the model function with constraints chosen by the user.
- type_of_fit = 'Generalized Morse'
3.1.4. minifit.lennard_jones module
Module containing LennardJonesFit class for curve fitting with Lennard-Jones.
- class minifit.lennard_jones.LennardJonesFit(filename, **kwargs)[source]
Bases:
FitBaseThis class makes curve fitting using the Lennard-Jones potential formula. It reads data from a file given as the first argument. The data file must contain at least two columns. The first column represents x values, the second and following columns are the y values.
- __init__(filename, **kwargs)[source]
Arguments:
- filename:
(string) Name of the file that contains data.
Keyword arguments:
- guess:
(tuple) A guess of the optimal parameters for the model. The number of guesses should match the arguments that the model function expects. The model is defined as:
4 * epsilon * ((sigma / r) ** 12 - (sigma / r) ** 6)it expects(val1, val2)for sigma, epsilon, such as:(0.74, 0.34)Otherwise, an exception will be raised. If not passed, a default guess adequate for the model function will be used.- auto_guess:
(bool) If true, tries to fit until chosen
precisionis reached. Default false.- auto_range:
(tuple) Sets boundaries for each parameter of the guess. If not set, the default range is used. Only used if auto_guess is True. Instead of
guess = (0.74, 0.34)passauto_range = ((0.,10.), (0., 15.))If fitting takes a lot of time, giving a better range might be helpful.- precision:
(float) Used by the
auto_guessfeature to control the fitting accuracy. The precision parameter represents the maximum allowable error between the fitted curve and the actual data points. During the fitting process, MiniFit continuously refines the parameters until the absolute sum of differences and the square root error between the model predictions and the data fall below this specified precision value. If the precision is set to 0.4, for instance, the fitted curve’s error will be less than 0.4 for both the absolute sum of differences and the square root error. Default value is 0.4. Only used ifauto_guessis True. Ifauto_guessis True and fitting takes a lot of time, lowering theprecisionmay be necessary for convergence. Lowering the precision will make the fitting process faster, but the quality of the popt may be worse.- shift:
- (bool) If true, shift the data. Default false.
Data can be shifted and it may make the convergence of the least squares algorithm easier.
- label_type = 'lennard_jones_fit'
- random_guess(context)[source]
Random guess adequate for the model function with constraints chosen by the user.
- type_of_fit = 'Lennard-Jones potential'
3.1.5. minifit.exponential module
Module containing ExponentialFit class for curve fitting with exponentials.
- class minifit.exponential.ExponentialFit(filename, **kwargs)[source]
Bases:
FitBaseThis class makes an exponential curve fitting. It reads data from a file given as the first argument. The data file must contain at least two columns. The first column represents x values, the second and following columns are the y values.
- __init__(filename, **kwargs)[source]
Arguments:
- filename:
(string) Name of the file that contains data.
Keyword arguments:
- guess:
(tuple) A guess of the optimal parameters for the model. The number of guesses should match the arguments that the model function expects. The model is defined as:
a * np.exp(b * x) + cit expects(val1, val2, val3)for a, b, and c, such as:(2.5, 12., -3.75)Otherwise, an exception will be raised. If not passed, a default guess adequate for the model function will be used.- auto_guess:
(bool) If true, tries to fit until chosen
precisionis reached. Default false.- auto_range:
(tuple) Sets boundaries for each parameter of the guess. If not set, the default range is used. Only used if auto_guess is True. Instead of
guess = (2.5, 12., -3.75)passauto_range = ((0.,10.), (5., 15.), (-40., 30.))If fitting takes a lot of time, giving a better range might be helpful.- precision:
(float) Used by the
auto_guessfeature to control the fitting accuracy. The precision parameter represents the maximum allowable error between the fitted curve and the actual data points. During the fitting process, MiniFit continuously refines the parameters until the absolute sum of differences and the square root error between the model predictions and the data fall below this specified precision value. If the precision is set to 0.4, for instance, the fitted curve’s error will be less than 0.4 for both the absolute sum of differences and the square root error. Default value is 0.4. Only used ifauto_guessis True. Ifauto_guessis True and fitting takes a lot of time, lowering theprecisionmay be necessary for convergence. Lowering the precision will make the fitting process faster, but the quality of the popt may be worse.- shift:
- (bool) If true, shift the data. Default false.
Data can be shifted and it may make the convergence of the least squares algorithm easier.
- label_type = 'exp_fit'
- random_guess(context)[source]
Random guess adequate for the model function with constraints chosen by the user.
- type_of_fit = 'Exponential'
3.1.6. minifit.gauss module
Module containing GaussFit class for curve fitting with normal distribution.
- class minifit.gauss.GaussFit(filename, **kwargs)[source]
Bases:
FitBaseThis class makes a curve fitting using the normal distribution It reads data from a file given as the first argument. The data file must contain at least two columns. The first column represents x values, the second and following columns are the y values.
- __init__(filename, **kwargs)[source]
Arguments:
- filename:
(string) Name of the file that contains data.
Keyword arguments:
- guess:
(tuple) A guess of the optimal parameters for the model. The number of guesses should match the arguments that the model function expects. The model is defined as:
A * np.exp(-((x - mu) ** 2) / sig**2)it expects(val1, val2, val3)for A, mu, and sig, such as:(4.9, 20., 2.85)Otherwise, an exception will be raised. If not passed, a default guess adequate for the model function will be used.- auto_guess:
(bool) If true, tries to fit until chosen
precisionis reached. Default false.- auto_range:
(tuple) Sets boundaries for each parameter of the guess. If not set, the default range is used. Only used if auto_guess is True. Instead of
guess = (4.9, 20., 2.85)passauto_range = ((0.,10.), (5., 35.), (1., 8.))If fitting takes a lot of time, giving a better range might be helpful.- precision:
(float) Used by the
auto_guessfeature to control the fitting accuracy. The precision parameter represents the maximum allowable error between the fitted curve and the actual data points. During the fitting process, MiniFit continuously refines the parameters until the absolute sum of differences and the square root error between the model predictions and the data fall below this specified precision value. If the precision is set to 0.4, for instance, the fitted curve’s error will be less than 0.4 for both the absolute sum of differences and the square root error. Default value is 0.4. Only used ifauto_guessis True. Ifauto_guessis True and fitting takes a lot of time, lowering theprecisionmay be necessary for convergence. Lowering the precision will make the fitting process faster, but the quality of the popt may be worse.- shift:
- (bool) If true, shift the data. Default false.
Data can be shifted and it may make the convergence of the least squares algorithm easier.
- label_type = 'gauss_fit'
- random_guess(context)[source]
Random guess adequate for the model function with constraints chosen by the user.
- type_of_fit = 'Normal distribution'
3.1.7. minifit.user_defined module
Module containing UserFit class for curve fitting with model that is passed to UserFit.
- class minifit.user_defined.UserFit(filename, **kwargs)[source]
Bases:
FitBaseThis class makes curve fitting using a user defined model. It reads data from a file given as the first argument. The data file must contain at least two columns. The first column represents x values, the second and following columns are the y values.
- __init__(filename, **kwargs)[source]
Arguments:
- filename:
(string) Name of the file that contains data.
Keyword arguments:
- num_param:
(int) Number of parameters of user defined model function. Mandatory. For ax^2 + bx + c
num_param = 3should be passed etc. Used for sanity checks. Unique for UserFit.- model:
(function/callable) An object that expects
(x, *args, **kwargs)and returns y value for given arguments. Mandatory. Unique for UserFit.- type_of_fit:
(string) Default:
User defined function. Used for displaying results in the terminal.- label_type:
(string) Default: user_fit. Used for part of the filename of the graph.
- guess:
(tuple) A guess of the optimal parameters for the model. The number of guesses should match the arguments that the model function expects. If model is defined as:
- def quadratic_poly(x, *args, **kwargs):
a, b, c = args
return a * x**2 + b * x + c
it expects
(val1, val2, val3)for a, b, and c, such as:(-5., 25., 1.5)Otherwise, an exception will be raised. If not passed, a default guess adequate for the model function will be used.- auto_guess:
(bool) If true, tries to fit until chosen
precisionis reached. Default false.- auto_range:
(tuple) Sets boundaries for each parameter of the guess. If not set, the default range is used. Only used if auto_guess is True. Example usage:
- def quadratic_poly(x, *args, **kwargs):
a, b, c = args
return a * x**2 + b *x + c
Instead of
guess = (5., 10., -3.), passauto_range = ((0., 10.), (5., 15.), (-40., 30.)). If fitting takes a lot of time, giving a better range might be helpful.- precision:
(float) Used by the
auto_guessfeature to control the fitting accuracy. The precision parameter represents the maximum allowable error between the fitted curve and the actual data points. During the fitting process, MiniFit continuously refines the parameters until the absolute sum of differences and the square root error between the model predictions and the data fall below this specified precision value. If the precision is set to 0.4, for instance, the fitted curve’s error will be less than 0.4 for both the absolute sum of differences and the square root error. Default value is 0.4. Only used ifauto_guessis True. Ifauto_guessis True and fitting takes a lot of time, lowering theprecisionmay be necessary for convergence. Lowering the precision will make the fitting process faster, but the quality of the popt may be worse.- shift:
- (bool) If true, shift the data. Default false.
Data can be shifted and it may make the convergence of the least squares algorithm easier.
- label_type = 'user_fit'
- random_guess(context)[source]
Random guess adequate for the model function with constraints chosen by the user.
- type_of_fit = 'User defined function'