Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
lar::util::details::SimpleFitterInterface< T, N > Class Template Referenceabstract

Simple fitter abstract interface. More...

#include <SimpleFits.h>

Public Types

using Data_t = T
 type of the data More...
 
using MatrixOps = FastMatrixOperations< Data_t, NParams >
 
using FitParameters_t = std::array< Data_t, NParams >
 type of set of fit parameters More...
 
using FitMatrix_t = typename MatrixOps::Matrix_t
 type of matrix for covariance (a std::array) More...
 

Public Member Functions

virtual ~SimpleFitterInterface ()=default
 Virtual destructor: compiler's default. More...
 
virtual bool isValid () const =0
 Returns if the fit has valid results. More...
 
virtual bool FillResults (FitParameters_t &params, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const =0
 Fills the specified parameters. More...
 
virtual bool FillResults (FitParameters_t &params, FitParameters_t &paramerrors, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const =0
 Fills the specified parameters. More...
 
virtual bool FillResults (FitParameters_t &params, FitParameters_t &paramerrors) const =0
 Fills the specified parameters. More...
 
virtual Data_t Evaluate (Data_t x) const =0
 Evaluates the fitted function at the specified point. More...
 
Data_t operator() (Data_t x) const
 Evaluates the fitted function; alias of Evaluate() More...
 
Fitting
virtual FitParameters_t FitParameters () const =0
 Computes and returns all the parameters of the fit result. More...
 
virtual FitParameters_t FitParameterErrors () const =0
 Computes and returns all the parameter errors of the fit result. More...
 
virtual FitMatrix_t FitParameterCovariance () const =0
 Computes and returns all the covariance matrix of the fit result. More...
 
virtual Data_t FitParameter (unsigned int n) const
 Returns the parameter n of the fit result. More...
 
virtual Data_t FitParameterError (unsigned int n) const
 Returns the error on parameter n of the fit result. More...
 
virtual Data_t ChiSquare () const =0
 Returns the $ \chi^{2} $ of the fit. More...
 
virtual int NDF () const =0
 Returns the degrees of freedom in the determination of the fit. More...
 

Static Public Member Functions

static constexpr Data_t sqr (Data_t v)
 Returns the square of the specified data value. More...
 
static constexpr Data_t cube (Data_t v)
 Returns the cube of the specified data value. More...
 

Static Public Attributes

static constexpr unsigned int NParams = N
 Number of parameters in the fit. More...
 

Protected Member Functions

virtual Data_t Determinant (FitMatrix_t const &mat) const
 Computes the determinant of a matrix. More...
 
virtual FitMatrix_t InvertMatrix (FitMatrix_t const &mat, Data_t det) const
 Computes the inverse of a matrix (using provided determinant) More...
 
virtual FitMatrix_t InvertMatrix (FitMatrix_t const &mat) const
 Computes the inverse of a matrix. More...
 
virtual FitParameters_t MatrixProduct (FitMatrix_t const &mat, FitParameters_t const &vec) const
 Computes the product of a FitMatrix_t and a FitParameters_t. More...
 

Detailed Description

template<typename T, unsigned int N>
class lar::util::details::SimpleFitterInterface< T, N >

Simple fitter abstract interface.

Definition at line 458 of file SimpleFits.h.

Member Typedef Documentation

template<typename T, unsigned int N>
using lar::util::details::SimpleFitterInterface< T, N >::Data_t = T

type of the data

Definition at line 464 of file SimpleFits.h.

template<typename T, unsigned int N>
using lar::util::details::SimpleFitterInterface< T, N >::FitMatrix_t = typename MatrixOps::Matrix_t

type of matrix for covariance (a std::array)

Definition at line 472 of file SimpleFits.h.

template<typename T, unsigned int N>
using lar::util::details::SimpleFitterInterface< T, N >::FitParameters_t = std::array<Data_t, NParams>

type of set of fit parameters

Definition at line 469 of file SimpleFits.h.

template<typename T, unsigned int N>
using lar::util::details::SimpleFitterInterface< T, N >::MatrixOps = FastMatrixOperations<Data_t, NParams>

Definition at line 466 of file SimpleFits.h.

Constructor & Destructor Documentation

template<typename T, unsigned int N>
virtual lar::util::details::SimpleFitterInterface< T, N >::~SimpleFitterInterface ( )
virtualdefault

Virtual destructor: compiler's default.

Member Function Documentation

template<typename T, unsigned int N>
virtual Data_t lar::util::details::SimpleFitterInterface< T, N >::ChiSquare ( ) const
pure virtual
template<typename T, unsigned int N>
static constexpr Data_t lar::util::details::SimpleFitterInterface< T, N >::cube ( Data_t  v)
inlinestatic

Returns the cube of the specified data value.

Definition at line 610 of file SimpleFits.h.

610 { return v*v*v; }
template<typename T, unsigned int N>
virtual Data_t lar::util::details::SimpleFitterInterface< T, N >::Determinant ( FitMatrix_t const &  mat) const
inlineprotectedvirtual

Computes the determinant of a matrix.

Definition at line 615 of file SimpleFits.h.

616  { return MatrixOps::Determinant(mat); }
static Data_t Determinant(Matrix_t const &mat)
Computes the determinant of a matrix.
template<typename T, unsigned int N>
virtual Data_t lar::util::details::SimpleFitterInterface< T, N >::Evaluate ( Data_t  x) const
pure virtual

Evaluates the fitted function at the specified point.

Parameters
xthe point where to evaluate the fit function
Returns
the value of the fit function

No check is performed whether the fit is valid.

template<typename T, unsigned int N>
virtual bool lar::util::details::SimpleFitterInterface< T, N >::FillResults ( FitParameters_t params,
FitMatrix_t Xmat,
Data_t det,
FitMatrix_t Smat 
) const
pure virtual

Fills the specified parameters.

Parameters
paramsthe fitted values of the parameters
Xmatthe matrix of the x^n/s^2 sums
Smatthe covariance matrix
detthe determinant of Xmat
Returns
true if the fit is valid (i.e. if a unique solution exists)
template<typename T, unsigned int N>
virtual bool lar::util::details::SimpleFitterInterface< T, N >::FillResults ( FitParameters_t params,
FitParameters_t paramerrors,
FitMatrix_t Xmat,
Data_t det,
FitMatrix_t Smat 
) const
pure virtual

Fills the specified parameters.

Parameters
paramsthe fitted values of the parameters
paramerrorsthe uncertainty on the fitted parameters
Xmatthe matrix of the x^n/s^2 sums
Smatthe covariance matrix
detthe determinant of Xmat
Returns
true if the fit is valid (i.e. if a unique solution exists)
template<typename T, unsigned int N>
virtual bool lar::util::details::SimpleFitterInterface< T, N >::FillResults ( FitParameters_t params,
FitParameters_t paramerrors 
) const
pure virtual

Fills the specified parameters.

Parameters
paramsthe fitted values of the parameters
paramerrorsthe uncertainty on the fitted parameters
Returns
true if the fit is valid (i.e. if a unique solution exists)

Implemented in lar::util::details::SimplePolyFitterBase< T, 1U >, and lar::util::details::SimplePolyFitterBase< T, 2U >.

template<typename T, unsigned int N>
virtual Data_t lar::util::details::SimpleFitterInterface< T, N >::FitParameter ( unsigned int  n) const
inlinevirtual

Returns the parameter n of the fit result.

Parameters
ndegree of the parameter; must be no larger than Degree
Returns
the parameter of the fit, in y/x^n units
Exceptions
std::runtime_errorif there is no unique solution

Reimplemented in lar::util::details::SimplePolyFitterBase< T, D >, lar::util::details::SimplePolyFitterBase< T, 1U >, and lar::util::details::SimplePolyFitterBase< T, 2U >.

Definition at line 524 of file SimpleFits.h.

525  { return FitParameters()[n]; }
std::void_t< T > n
virtual FitParameters_t FitParameters() const =0
Computes and returns all the parameters of the fit result.
template<typename T, unsigned int N>
virtual FitMatrix_t lar::util::details::SimpleFitterInterface< T, N >::FitParameterCovariance ( ) const
pure virtual

Computes and returns all the covariance matrix of the fit result.

Returns
the the covariance matrix of the fit
Exceptions
std::runtime_errorif there is no unique solution

The matrix is symmetric, and stored in a linear way (say, first row, then second row).

Implemented in lar::util::GaussianFit< T >, lar::util::details::SimplePolyFitterBase< T, D >, lar::util::details::SimplePolyFitterBase< T, 1U >, and lar::util::details::SimplePolyFitterBase< T, 2U >.

template<typename T, unsigned int N>
virtual Data_t lar::util::details::SimpleFitterInterface< T, N >::FitParameterError ( unsigned int  n) const
inlinevirtual

Returns the error on parameter n of the fit result.

Parameters
ndegree of the parameter; must be no larger than Degree
Returns
the error on the parameter of the fit, in y/x^n units
Exceptions
std::runtime_errorif there is no unique solution

Reimplemented in lar::util::details::SimplePolyFitterBase< T, D >, lar::util::details::SimplePolyFitterBase< T, 1U >, and lar::util::details::SimplePolyFitterBase< T, 2U >.

Definition at line 533 of file SimpleFits.h.

534  { return std::sqrt(FitParameterCovariance()[n * (NParams + 1)]); }
std::void_t< T > n
virtual FitMatrix_t FitParameterCovariance() const =0
Computes and returns all the covariance matrix of the fit result.
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:462
template<typename T, unsigned int N>
virtual FitParameters_t lar::util::details::SimpleFitterInterface< T, N >::FitParameterErrors ( ) const
pure virtual

Computes and returns all the parameter errors of the fit result.

Returns
the full set of parameter errors of the fit
Exceptions
std::runtime_errorif there is no unique solution

Implemented in lar::util::GaussianFit< T >, lar::util::details::SimplePolyFitterBase< T, D >, lar::util::details::SimplePolyFitterBase< T, 1U >, and lar::util::details::SimplePolyFitterBase< T, 2U >.

template<typename T, unsigned int N>
virtual FitParameters_t lar::util::details::SimpleFitterInterface< T, N >::FitParameters ( ) const
pure virtual

Computes and returns all the parameters of the fit result.

Returns
the full set of parameters of the fit
Exceptions
std::runtime_errorif there is no unique solution

Implemented in lar::util::GaussianFit< T >, lar::util::details::SimplePolyFitterBase< T, D >, lar::util::details::SimplePolyFitterBase< T, 1U >, and lar::util::details::SimplePolyFitterBase< T, 2U >.

template<typename T, unsigned int N>
virtual FitMatrix_t lar::util::details::SimpleFitterInterface< T, N >::InvertMatrix ( FitMatrix_t const &  mat,
Data_t  det 
) const
inlineprotectedvirtual

Computes the inverse of a matrix (using provided determinant)

Definition at line 620 of file SimpleFits.h.

621  { return MatrixOps::InvertSymmetricMatrix(mat, det); }
static Matrix_t InvertSymmetricMatrix(Matrix_t const &mat, Data_t det)
template<typename T, unsigned int N>
virtual FitMatrix_t lar::util::details::SimpleFitterInterface< T, N >::InvertMatrix ( FitMatrix_t const &  mat) const
inlineprotectedvirtual

Computes the inverse of a matrix.

Definition at line 624 of file SimpleFits.h.

625  { return MatrixOps::InvertSymmetricMatrix(mat); }
static Matrix_t InvertSymmetricMatrix(Matrix_t const &mat, Data_t det)
template<typename T, unsigned int N>
virtual bool lar::util::details::SimpleFitterInterface< T, N >::isValid ( ) const
pure virtual

Returns if the fit has valid results.

Returns
if the fit has valid results

The fit has no valid results if:

  1. insufficient data has been add()ed (no more than the fit Degree)
  2. if input points are vertically aligned

Note that checking point 2 is expensive in terms of time.

Implemented in lar::util::GaussianFit< T >, lar::util::details::SimplePolyFitterBase< T, D >, lar::util::details::SimplePolyFitterBase< T, 1U >, and lar::util::details::SimplePolyFitterBase< T, 2U >.

template<typename T, unsigned int N>
virtual FitParameters_t lar::util::details::SimpleFitterInterface< T, N >::MatrixProduct ( FitMatrix_t const &  mat,
FitParameters_t const &  vec 
) const
inlineprotectedvirtual

Computes the product of a FitMatrix_t and a FitParameters_t.

Definition at line 629 of file SimpleFits.h.

630  { return MatrixOps::MatrixVectorProduct(mat, vec); }
static Vector_t MatrixVectorProduct(Matrix_t const &mat, Vector_t const &vec)
Returns the product of a square matrix times a column vector.
template<typename T, unsigned int N>
virtual int lar::util::details::SimpleFitterInterface< T, N >::NDF ( ) const
pure virtual

Returns the degrees of freedom in the determination of the fit.

Returns
the degrees of freedom in the determination of the fit

The return value may be 0 or negative if insufficient points have been added.

Implemented in lar::util::GaussianFit< T >, lar::util::details::SimplePolyFitterBase< T, D >, lar::util::details::SimplePolyFitterBase< T, 1U >, and lar::util::details::SimplePolyFitterBase< T, 2U >.

template<typename T, unsigned int N>
Data_t lar::util::details::SimpleFitterInterface< T, N >::operator() ( Data_t  x) const
inline

Evaluates the fitted function; alias of Evaluate()

Definition at line 603 of file SimpleFits.h.

603 { return Evaluate(x); }
list x
Definition: train.py:276
virtual Data_t Evaluate(Data_t x) const =0
Evaluates the fitted function at the specified point.
template<typename T, unsigned int N>
static constexpr Data_t lar::util::details::SimpleFitterInterface< T, N >::sqr ( Data_t  v)
inlinestatic

Returns the square of the specified data value.

Definition at line 607 of file SimpleFits.h.

607 { return v*v; }

Member Data Documentation

template<typename T, unsigned int N>
constexpr unsigned int lar::util::details::SimpleFitterInterface< T, N >::NParams = N
static

Number of parameters in the fit.

Definition at line 462 of file SimpleFits.h.


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