Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : namespace intrp { 7 : 8 0 : struct LinearRegressionResult { 9 0 : double intercept; 10 0 : double slope; 11 0 : double delta_intercept; 12 0 : double delta_slope; 13 : }; 14 : 15 : /*! 16 : * \ingroup NumericalAlgorithmsGroup 17 : * \brief A linear regression function. 18 : * 19 : * A wrapper for gsl linear regression. 20 : * Fits the data to \f$y = m x + b\f$. Returns a struct 21 : * containing \f$(b, m, \delta b, \delta m)\f$, where 22 : * \f$\delta b\f$ and \f$\delta m\f$ are the error bars in \f$b\f$ and 23 : * \f$m\f$. The error bars are computed assuming unknown errors in \f$y\f$. 24 : * 25 : * linear_regression could be implemented by calling 26 : * LinearLeastSquares using Order=1, but we choose instead to 27 : * implement linear_regression in a simpler way, by calling a simpler gsl 28 : * function that involves no memory allocations, no copying, and no 29 : * `pow` functions. 30 : */ 31 : template <typename T> 32 1 : LinearRegressionResult linear_regression(const T& x_values, const T& y_values); 33 : } // namespace intrp