fit

libra_py.fit.Regression(X, Y, opt=0)[source]

Performs a linear regression of the Y vs. X of the form:

Y = b*x opt=0 (default) Y = a + b*x opt=1

Parameters
  • X (list of doubles) – The x axis data

  • Y (list of doubles) – The y axis data

  • opt (int) –

    Selects the type of fitting to perform:

    • opt = 0: The fitting is of the form: Y = b*X (default)

    • opt = 1: The fitting is of a more general form: Y = a + b*X

Returns

the linear regression coefficients a and b

For opt==0, a = 0

Return type

[double, double]

libra_py.fit.fit_exp(X, Y, x0=0.0, verbose=0, linreg_opt=0)[source]

Fits Y vs. X data using: Y = A*exp(-B*(X-x0))

Parameters
  • X (list of doubles) – The x axis data

  • Y (list of doubles) – The y axis data

  • x0 (double) – the “origin” of the exponential function [default: 0.0]

  • verbose (int) – whether to print extra info (1) or not (0) [default: 0]

  • linreg_opt (int) –

    the type of the linear regression to use SeeAlso:: :funct:`Regression` [default: 0]

    • opt = 0: ln(Y) = b*(X-x0)

    • opt = 1: ln(Y) = a + b*(X-x0)

Returns

The Y values predicted using the obtained linear

interpolation parameters. These values are computed for all X values

A ( double ): The A coefficient in: Y = A*exp(-B*(X-x0)) B ( double ): The B coefficient in: Y = A*exp(-B*(X-x0))

Return type

predy ( list of doubles )

Example

>>> # get the first two columns of data as X and Y
>>> X, Y = get_data_from_file("relax.txt", 0, 1)
>>>
>>> # Y = exp(-B*X), the minimaal version
>>> Ypred, A, B = fit_exp(X,Y)
>>>
>>> # Y = exp(-B*X), the more explicit version
>>> Ypred, A, B = fit_exp(X,Y, 0.0)
>>>
>>> # Y = A * exp(-B*X), the most explicit version
>>> Ypred, A, B = fit_exp(X,Y, 0.0, 1, 1)
>>>
>>> # Assume the fitting function is: Y = A * exp(-B*(X+1.5))
>>> Ypred, A, B = fit_exp(X,Y, 1.5, 1, 1)  # Y = A * exp(-B*(X+1.5))
libra_py.fit.fit_gau(X, Y, x0=0.0, verbose=0, linreg_opt=0)[source]

Fits Y vs. X data using: Y = A*exp(-B*(X-x0)^2)

Parameters
  • X (list of doubles) – The x axis data

  • Y (list of doubles) – The y axis data

  • x0 (double) – the “origin” of the exponential function [default: 0.0]

  • verbose (int) – whether to print extra info (1) or not (0) [default: 0]

  • linreg_opt (int) –

    the type of the linear regression to use SeeAlso:: :funct:`Regression` [default: 0]

    • opt = 0: ln(Y) = b*(X-x0)^2

    • opt = 1: ln(Y) = a + b*(X-x0)^2

Returns

The Y values predicted using the obtained linear

interpolation parameters. These values are computed for all X values

A ( double ): The A coefficient in: Y = A*exp(-B*(X-x0)^2) B ( double ): The B coefficient in: Y = A*exp(-B*(X-x0)^2)

Return type

predy ( list of doubles )

Example

>>> # get the first two columns of data as X and Y
>>> X, Y = get_data_from_file("relax.txt", 0, 1)
>>>
>>> # Y = exp(-B*X^2), the minimaal version
>>> Ypred, A, B = fit_gau(X,Y)
>>>
>>> # Y = exp(-B*X^2), the more explicit version
>>> Ypred, A, B = fit_gau(X,Y, 0.0)
>>>
>>> # Y = A * exp(-B*X^2), the most explicit version
>>> Ypred, A, B = fit_gau(X,Y, 0.0, 1, 1)
>>>
>>> # Assume the fitting function is: Y = A * exp(-B*(X-1)^2)
>>> Ypred, A, B = fit_exp(X,Y, -1.0, 1, 1)  # Y = A * exp(-B*(X-1)^2)