2.1.6.1.9. sf_tools.signal.regression module¶
REGRESSION ROUTINES
This module contains methods for linear regression.
| Author: | Samuel Farrens <samuel.farrens@gmail.com> |
|---|---|
| Version: | 1.0 |
| Date: | 04/04/2017 |
-
sf_tools.signal.regression.linear_fit(B, x)[source]¶ Linear fit
This method defines the equation of a straight line.
Parameters: - B (tuple) – Slope (m) and intercept (b) of the line.
- x (list or np.ndarray) – The 1D data vector
Returns: Return type: np.ndarray 1D array of corresponding y values
Notes
This equation of a stright line is given by
\[y = mx + b\]
-
sf_tools.signal.regression.polynomial(x, a)[source]¶ Polynomial
This method defines the equation of a polynomial line.
Parameters: - x (list or np.ndarray) – The 1D data vector
- a (list or np.ndarray) – The 1D polynomial coefficient vector
Returns: Return type: np.ndarray 1D array of corresponding y values
Notes
This equation of a stright line is given by
\[y = a_0 + a_1x + a_2x^2 + \dots + a_kx^k\]
-
sf_tools.signal.regression.polynomial_fit(x, y, k=1)[source]¶ Polynomial fit
This method finds the coefficients for a polynomial line fit to the input data using least squares.
Parameters: - x (list or np.ndarray) – The 1D independent data vector
- y (list or np.ndarray) – The 1D dependent data vector
- k (int, optional) – Number of degrees of freedom. Default (k=1)
Returns: Return type: np.ndarray 1D array of coefficients a
-
sf_tools.signal.regression.least_squares(X, y)[source]¶ Least squares
This method performs an analytical least squares regression. Returns the values of the coefficients, a, given the input matrix X and the corresponding y values.
Parameters: - X (np.ndarray) – The 2D independent data matrix.
- y (np.ndarray) – The 1D dependent data vector
Returns: Return type: np.ndarray 1D array of coefficients a
Raises: ValueError– If inputs are not numpy arraysTodo
Add equation and example
-
sf_tools.signal.regression.x_matrix(x, k)[source]¶ Define X matrix
This method defines the matrix X for a given vector x corresponding to a polynomial with k degrees of freedom.
Parameters: - x (list or np.ndarray) – The 1D independent data vector
- k (int) – Number of degrees of freedom
Returns: Return type: np.ndarray the 2D independent variable matrix X
-
sf_tools.signal.regression.fit_odr(x, y, xerr, yerr, fit)[source]¶ Fit via ODR
This method performs an orthogonal distance regression fit.
Parameters: - x (list or np.ndarray) – The 1D independent data vector
- y (list or np.ndarray) – The 1D dependent data vector
- x_err (list or np.ndarray) – 1D data vector of x value errors
- y_err (list or np.ndarray) – 1D data vector of y value errors
- fit (function) – Fitting function
Returns: Return type: tuple best fit parameters