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: ABC

Base class for all fitting classes

__call__()[source]

Calls optimize() and then show() for chosen data.

__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 PolyFit when order is 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 precision is 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.) pass auto_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_guess feature 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 if auto_guess is True. If auto_guess is True and fitting takes a lot of time, lowering the precision may 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

abstract default_guess(context)[source]

Default guess adequate for the model function.

label_type = 'model_fit'
latex_text()[source]

Returns string with formula used by the model in latex format.

abstract model_function(x, *args, **kwargs)[source]

Depends on the module.

optimize(xdata, ydata, ind)[source]

Finds the optimal parameters and corresponding errors.

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.

show(xdata, ydata, ind)[source]

Saves graph of the results as pdf.

type_of_fit = 'Name of the model'
x_label = 'x_label'
y_label = 'y_label'
minifit.fit_base.log(str1)[source]

Logger

3.1.2. minifit.poly module

Module containing PolyFit class for curve fitting with polynomials.

class minifit.poly.PolyFit(filename, **kwargs)[source]

Bases: FitBase

This 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 precision is 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.) pass auto_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_guess feature 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 if auto_guess is True. If auto_guess is True and fitting takes a lot of time, lowering the precision may 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.

default_guess(context)[source]

Default guess adequate for the model function.

label_type = 'polynomial_fit'
latex_text()[source]

Returns string with formula used by the model in latex format.

model_function(x, *args, **kwargs)[source]

Depends on the module.

print_info(popt)[source]

Print info about popt in the format adequate for the model function.

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: FitBase

This 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-de it 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 precision is 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) pass auto_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_guess feature 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 if auto_guess is True. If auto_guess is True and fitting takes a lot of time, lowering the precision may 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

default_guess(context)[source]

Default guess adequate for the model function.

label_type = 'morse_fit'
latex_text()[source]

Returns string with formula used by the model in latex format.

model_function(x, *args, **kwargs)[source]

Depends on the module.

print_info(popt)[source]

Print info about popt in the format adequate for the model function.

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: FitBase

This 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 precision is 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) pass auto_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_guess feature 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 if auto_guess is True. If auto_guess is True and fitting takes a lot of time, lowering the precision may 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.

default_guess(context)[source]

Default guess adequate for the model function.

label_type = 'lennard_jones_fit'
latex_text()[source]

Returns a string with the model formula in latex format.

model_function(x, *args, **kwargs)[source]

Depends on the module.

print_info(popt)[source]

Print info about popt in the format adequate for the model function.

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: FitBase

This 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) + c it 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 precision is 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) pass auto_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_guess feature 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 if auto_guess is True. If auto_guess is True and fitting takes a lot of time, lowering the precision may 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.

default_guess(context)[source]

Default guess adequate for the model function.

label_type = 'exp_fit'
latex_text()[source]

Returns a string with the formula used by the model in latex format.

model_function(x, *args, **kwargs)[source]

Depends on the module.

print_info(popt)[source]

Print info about popt in the format adequate for the model function.

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: FitBase

This 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 precision is 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) pass auto_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_guess feature 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 if auto_guess is True. If auto_guess is True and fitting takes a lot of time, lowering the precision may 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.

default_guess(context)[source]

Default guess adequate for the model function.

label_type = 'gauss_fit'
latex_text()[source]

Returns a string with the formula used by the model in latex format.

model_function(x, *args, **kwargs)[source]

Depends on the module.

print_info(popt)[source]

Print info about popt in the format adequate for the model function.

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: FitBase

This 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 = 3 should 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 precision is 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.), pass auto_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_guess feature 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 if auto_guess is True. If auto_guess is True and fitting takes a lot of time, lowering the precision may 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.

default_guess(context)[source]

Default guess adequate for the model function.

label_type = 'user_fit'
latex_text()[source]

Returns string with formula used by the model in latex format.

model_function(x, *args, **kwargs)[source]

Depends on the module.

print_info(popt)[source]

Print info about popt in the format adequate for the model function.

random_guess(context)[source]

Random guess adequate for the model function with constraints chosen by the user.

type_of_fit = 'User defined function'