SpECTRE  v2024.04.12
intrp::LinearLeastSquares< Order > Class Template Reference

A linear least squares solver class. More...

#include <LinearLeastSquares.hpp>

Public Member Functions

 LinearLeastSquares (const size_t num_observations)
 
 LinearLeastSquares (const LinearLeastSquares &)=delete
 
LinearLeastSquaresoperator= (const LinearLeastSquares &)=delete
 
 LinearLeastSquares (LinearLeastSquares &&)=default
 
LinearLeastSquaresoperator= (LinearLeastSquares &&rhs)=default
 
double interpolate (const std::array< double, Order+1 > coefficients, const double x_to_interp_to)
 
template<typename T >
std::array< double, Order+1 > fit_coefficients (const T &x_values, const T &y_values)
 
template<typename T >
std::vector< std::array< double, Order+1 > > fit_coefficients (const T &x_values, const std::vector< T > &y_values)
 
void pup (PUP::er &p)
 

Detailed Description

template<size_t Order>
class intrp::LinearLeastSquares< Order >

A linear least squares solver class.

A wrapper class for the gsl linear least squares solver which determines the coefficients of best fit for a polynomial of order Order given a set of data points x_values and y_values representing some function y(x). Note that the interpolate function requires a set of fit coefficients, which can be obtained by first calling the fit_coefficients function. The parameter num_observations refers to the number of entries in x_values.

The details of the linear least squares solver can be seen here: GSL documentation.

Warning
This class is not thread-safe, the reason for this is because making the buffers used in the class thread-local would be a large use of memory. This class should be treated as a function that internally stores workspace variables to reduce memory allocations.

Member Function Documentation

◆ fit_coefficients()

template<size_t Order>
template<typename T >
std::vector< std::array< double, Order+1 > > intrp::LinearLeastSquares< Order >::fit_coefficients ( const T &  x_values,
const std::vector< T > &  y_values 
)

The x_values are a sequence of times, positions, or other abscissa. The y_values are a std::vector of sequences of ordinates corresponding to these abscissa, with each element of the std::vector containing one sequence. Therefore, one set of fit coefficients is found for each entry in the std::vector y_values. In other words, the data in y_values is stored as: y_values[fit_index][x_value_index], where fit_index runs over the number of different sequences being fit to, and x_value_index runs over the different entries corrsponding to those in x_values.


The documentation for this class was generated from the following file: