Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Types | List of all members
lar::util::details::SimplePolyFitterBase< T, D > Class Template Reference

Base class providing virtual fitting interface for polynomial fitters. More...

#include <SimpleFits.h>

Inheritance diagram for lar::util::details::SimplePolyFitterBase< T, D >:
lar::util::details::SimpleFitterInterface< T, D+1 > lar::util::details::SimplePolyFitterDataBase< T, D >

Public Types

using Data_t = typename Base_t::Data_t
 type of the data More...
 
using FitParameters_t = typename Interface_t::FitParameters_t
 type of set of fit parameters More...
 
using FitMatrix_t = typename Interface_t::FitMatrix_t
 type of matrix for covariance (a std::array) More...
 
- Public Types inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
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 Types inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
using Data_t = typename Collector_t::Data_t
 type of the data More...
 
using Measurement_t = typename Collector_t::Measurement_t
 type of measurement without uncertainty More...
 
using MeasurementAndUncertainty_t = typename Collector_t::MeasurementAndUncertainty_t
 type of measurement with uncertainty More...
 

Public Member Functions

virtual bool isValid () const override
 Returns if the fit has valid results. More...
 
bool FillResults (FitParameters_t &params, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const override
 Fills the specified parameters. More...
 
bool FillResults (FitParameters_t &params, FitParameters_t &paramerrors, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const override
 Fills the specified parameters. More...
 
bool FillResults (FitParameters_t &params, FitParameters_t &paramerrors) const override
 Fills the specified parameters. More...
 
virtual Data_t Evaluate (Data_t x) const override
 Evaluates the fitted function at the specified point. More...
 
Fitting
virtual FitParameters_t FitParameters () const override
 Computes and returns all the parameters of the fit result. More...
 
virtual FitParameters_t FitParameterErrors () const override
 Computes and returns all the parameter errors of the fit result. More...
 
virtual FitMatrix_t FitParameterCovariance () const override
 Computes and returns all the covariance matrix of the fit result. More...
 
virtual Data_t FitParameter (unsigned int n) const override
 Returns the parameter n of the fit result. More...
 
virtual Data_t FitParameterError (unsigned int n) const override
 Returns the error on parameter n of the fit result. More...
 
virtual Data_t ChiSquare () const override
 Returns the $ \chi^{2} $ of the fit. More...
 
virtual int NDF () const override
 Returns the degrees of freedom in the determination of the fit. More...
 
- Public Member Functions inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
virtual ~SimpleFitterInterface ()=default
 Virtual destructor: compiler's default. 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...
 
- Public Member Functions inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
void clear ()
 Clears all the statistics. More...
 
template<typename Stream >
void PrintStats (Stream &out) const
 Prints the collected statistics into a stream. More...
 
bool add (Data_t x, Data_t y, Data_t sy=Data_t(1.0))
 
bool add (Measurement_t value, Data_t sy=Data_t(1.0))
 
bool add (MeasurementAndUncertainty_t value)
 
template<typename Iter >
void add_without_uncertainty (Iter begin, Iter end)
 
template<typename Iter , typename Pred >
void add_without_uncertainty (Iter begin, Iter end, Pred extractor)
 
template<typename Cont , typename Pred >
void add_without_uncertainty (Cont cont, Pred extractor)
 
template<typename Cont >
void add_without_uncertainty (Cont cont)
 
template<typename VIter , typename UIter , typename VPred , typename UPred = identity>
unsigned int add_with_uncertainty (VIter begin_value, VIter end_value, UIter begin_uncertainty, VPred value_extractor, UPred uncertainty_extractor=UPred())
 
template<typename Iter >
unsigned int add_with_uncertainty (Iter begin, Iter end)
 
template<typename Cont >
unsigned int add_with_uncertainty (Cont cont)
 
int N () const
 
Data_t AverageUncertainty () const
 

Static Public Member Functions

static FitParameters_t ExtractParameterErrors (FitMatrix_t const &Smat)
 Extracts parameter errors from diagonal of the covarriance matrix. More...
 
- Static Public Member Functions inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
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 Member Functions inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
template<typename V >
static constexpr V sqr (V const &v)
 Returns the square of the specified value. More...
 

Static Public Attributes

static constexpr unsigned int Degree = Base_t::Degree
 Degree of the fit. More...
 
static constexpr unsigned int NParams = Interface_t::NParams
 Number of parameters in the fit. More...
 
- Static Public Attributes inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
static constexpr unsigned int NParams
 Number of parameters in the fit. More...
 
- Static Public Attributes inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
static constexpr unsigned int Degree = Collector_t::Degree
 Degree of the fit. More...
 

Protected Member Functions

virtual FitMatrix_t MakeMatrixX () const
 Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } ) More...
 
virtual FitParameters_t MakeMatrixY () const
 Fills and returns the matrix (vector) of x^n y sum coefficients. More...
 
virtual FitParameters_t FitParameterErrors (FitMatrix_t const &Smat) const
 Computes and returns all the parameter errors of the fit result. More...
 
virtual FitParameters_t FitParameters (FitMatrix_t const &Xmat) const
 Returns the fitted parameters using the provided information. More...
 
virtual FitParameters_t FitParameters (FitMatrix_t const &Smat, Data_t) const
 
virtual Data_t Param (unsigned int n, FitMatrix_t const &Xmat) const
 Computes a single fit parameter using the given information. More...
 
virtual Data_t Param (unsigned int n, FitMatrix_t const &Xmat, Data_t detXmat) const
 
- Protected Member Functions inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
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...
 
- Protected Member Functions inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
Data_t XN (unsigned int n) const
 Returns the weighted sum of x^n. More...
 
Data_t XNY (unsigned int n) const
 Returns the weighted sum of x^n y. More...
 

Private Types

using Interface_t = SimpleFitterInterface< T, D+1 >
 interface More...
 
using Base_t = SimplePolyFitterDataBase< T, D >
 class storing input More...
 

Additional Inherited Members

- Protected Attributes inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
Collector_t stats
 statistics collected from fit data input More...
 

Detailed Description

template<typename T, unsigned int D>
class lar::util::details::SimplePolyFitterBase< T, D >

Base class providing virtual fitting interface for polynomial fitters.

Definition at line 637 of file SimpleFits.h.

Member Typedef Documentation

template<typename T, unsigned int D>
using lar::util::details::SimplePolyFitterBase< T, D >::Base_t = SimplePolyFitterDataBase<T, D>
private

class storing input

Definition at line 642 of file SimpleFits.h.

template<typename T, unsigned int D>
using lar::util::details::SimplePolyFitterBase< T, D >::Data_t = typename Base_t::Data_t

type of the data

Definition at line 653 of file SimpleFits.h.

template<typename T, unsigned int D>
using lar::util::details::SimplePolyFitterBase< T, D >::FitMatrix_t = typename Interface_t::FitMatrix_t

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

Definition at line 659 of file SimpleFits.h.

template<typename T, unsigned int D>
using lar::util::details::SimplePolyFitterBase< T, D >::FitParameters_t = typename Interface_t::FitParameters_t

type of set of fit parameters

Definition at line 656 of file SimpleFits.h.

template<typename T, unsigned int D>
using lar::util::details::SimplePolyFitterBase< T, D >::Interface_t = SimpleFitterInterface<T, D + 1>
private

interface

Definition at line 641 of file SimpleFits.h.

Member Function Documentation

template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::ChiSquare ( ) const
overridevirtual

Returns the $ \chi^{2} $ of the fit.

Returns
the $ \chi^{2} $ of the fit (not divided by NDF())

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

Reimplemented in lar::util::QuadraticFit< T >, and lar::util::LinearFit< T >.

Definition at line 1741 of file SimpleFits.h.

1742 {
1743  // the generic implementation of ChiSquare from sums is complex enough that
1744  // I freaked out
1745  throw std::logic_error
1746  ("SimplePolyFitterBase::ChiSquare() not implemented for generic fit");
1747 } // SimplePolyFitterBase<>::ChiSquare()
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::Evaluate ( Data_t  x) const
overridevirtual

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.

Definition at line 1641 of file SimpleFits.h.

1643 {
1645  unsigned int iParam = NParams - 1; // point to last parameter (highest degree)
1646  Data_t v = params[iParam];
1647  while (iParam > 0) v = v * x + params[--iParam];
1648  return v;
1649 } // SimplePolyFitterBase<>::Evaluate()
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
typename Base_t::Data_t Data_t
type of the data
Definition: SimpleFits.h:653
typename Interface_t::FitParameters_t FitParameters_t
type of set of fit parameters
Definition: SimpleFits.h:656
virtual FitParameters_t FitParameters() const override
Computes and returns all the parameters of the fit result.
Definition: SimpleFits.h:1564
list x
Definition: train.py:276
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::ExtractParameterErrors ( FitMatrix_t const &  Smat)
static

Extracts parameter errors from diagonal of the covarriance matrix.

Definition at line 1715 of file SimpleFits.h.

1717 {
1718  FitParameters_t fit_errors;
1719  for (unsigned int iParam = 0; iParam <= Degree; ++iParam)
1720  fit_errors[iParam] = std::sqrt(Smat[iParam * (NParams + 1)]);
1721  return fit_errors;
1722 } // SimplePolyFitterBase<>::FitParameterErrors(FitMatrix_t)
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
typename Interface_t::FitParameters_t FitParameters_t
type of set of fit parameters
Definition: SimpleFits.h:656
static constexpr unsigned int Degree
Degree of the fit.
Definition: SimpleFits.h:648
template<typename T , unsigned int D>
bool lar::util::details::SimplePolyFitterBase< T, D >::FillResults ( FitParameters_t params,
FitMatrix_t Xmat,
Data_t det,
FitMatrix_t Smat 
) const
override

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)

Definition at line 1598 of file SimpleFits.h.

1601  {
1602 
1603  Xmat = MakeMatrixX();
1604  det = Determinant(Xmat);
1605  if (!std::isnormal(det)) {
1606  Smat.fill(Data_t(0));
1607  params.fill(Data_t(0));
1608  return false;
1609  }
1610  Smat = InvertMatrix(Xmat, det);
1611  params = FitParameters(Smat, det);
1612  return true;
1613 } // SimplePolyFitterBase<>::FillResults(params, matrices, determinant)
virtual FitMatrix_t InvertMatrix(FitMatrix_t const &mat, Data_t det) const
Computes the inverse of a matrix (using provided determinant)
Definition: SimpleFits.h:620
virtual FitMatrix_t MakeMatrixX() const
Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } )
Definition: SimpleFits.h:1654
typename Base_t::Data_t Data_t
type of the data
Definition: SimpleFits.h:653
virtual FitParameters_t FitParameters() const override
Computes and returns all the parameters of the fit result.
Definition: SimpleFits.h:1564
virtual Data_t Determinant(FitMatrix_t const &mat) const
Computes the determinant of a matrix.
Definition: SimpleFits.h:615
template<typename T , unsigned int D>
bool lar::util::details::SimplePolyFitterBase< T, D >::FillResults ( FitParameters_t params,
FitParameters_t paramerrors,
FitMatrix_t Xmat,
Data_t det,
FitMatrix_t Smat 
) const
override

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)

Definition at line 1617 of file SimpleFits.h.

1620  {
1621 
1622  if (!this->FillResults(params, Xmat, det, Smat)) return false;
1623  paramerrors = ExtractParameterErrors(Smat);
1624  return true;
1625 } // SimplePolyFitterBase<>::FillResults(params, errors, matrices, determinant)
bool FillResults(FitParameters_t &params, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const override
Fills the specified parameters.
Definition: SimpleFits.h:1598
static FitParameters_t ExtractParameterErrors(FitMatrix_t const &Smat)
Extracts parameter errors from diagonal of the covarriance matrix.
Definition: SimpleFits.h:1715
template<typename T , unsigned int D>
bool lar::util::details::SimplePolyFitterBase< T, D >::FillResults ( FitParameters_t params,
FitParameters_t paramerrors 
) const
override

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)

Definition at line 1629 of file SimpleFits.h.

1631  {
1632  // to compute the parameters, we need all the stuff;
1633  // we just keep it local and discard it in the end. Such a waste.
1634  FitMatrix_t Xmat, Smat;
1635  Data_t det;
1636  return FillResults(params, paramerrors, Xmat, det, Smat);
1637 } // SimplePolyFitterBase<>::FillResults(params, errors)
typename Base_t::Data_t Data_t
type of the data
Definition: SimpleFits.h:653
bool FillResults(FitParameters_t &params, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const override
Fills the specified parameters.
Definition: SimpleFits.h:1598
typename Interface_t::FitMatrix_t FitMatrix_t
type of matrix for covariance (a std::array)
Definition: SimpleFits.h:659
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::FitParameter ( unsigned int  n) const
inlineoverridevirtual

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::range_errorif there is no unique solution

Reimplemented from lar::util::details::SimpleFitterInterface< T, D+1 >.

Definition at line 1548 of file SimpleFits.h.

1549 {
1550  return Param(n, MakeMatrixX());
1551 } // SimplePolyFitterBase<>::FitParameter(unsigned int)
virtual Data_t Param(unsigned int n, FitMatrix_t const &Xmat) const
Computes a single fit parameter using the given information.
Definition: SimpleFits.h:1700
virtual FitMatrix_t MakeMatrixX() const
Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } )
Definition: SimpleFits.h:1654
std::void_t< T > n
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::FitParameterCovariance ( ) const
overridevirtual

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

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

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

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

Definition at line 1585 of file SimpleFits.h.

1586 {
1587  FitMatrix_t Xmat = MakeMatrixX();
1588  Data_t det = Determinant(Xmat);
1589  if (!std::isnormal(det)) {
1590  throw std::range_error
1591  ("SimplePolyFitterBase::FitParameterCovariance(): determinant 0 while fitting");
1592  }
1593  return InvertMatrix(Xmat, det);
1594 } // SimplePolyFitterBase<>::FitParameterCovariance()
virtual FitMatrix_t InvertMatrix(FitMatrix_t const &mat, Data_t det) const
Computes the inverse of a matrix (using provided determinant)
Definition: SimpleFits.h:620
virtual FitMatrix_t MakeMatrixX() const
Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } )
Definition: SimpleFits.h:1654
typename Base_t::Data_t Data_t
type of the data
Definition: SimpleFits.h:653
typename Interface_t::FitMatrix_t FitMatrix_t
type of matrix for covariance (a std::array)
Definition: SimpleFits.h:659
virtual Data_t Determinant(FitMatrix_t const &mat) const
Computes the determinant of a matrix.
Definition: SimpleFits.h:615
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::FitParameterError ( unsigned int  n) const
overridevirtual

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::range_errorif there is no unique solution

Reimplemented from lar::util::details::SimpleFitterInterface< T, D+1 >.

Definition at line 1556 of file SimpleFits.h.

1557 {
1558  if (n > Degree) return Data_t(0); // no parameter, no error
1559  return std::sqrt(FitParameterCovariance()[n * (NParams + 1)]);
1560 } // SimplePolyFitterBase<>::FitParameterError()
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
typename Base_t::Data_t Data_t
type of the data
Definition: SimpleFits.h:653
std::void_t< T > n
virtual FitMatrix_t FitParameterCovariance() const override
Computes and returns all the covariance matrix of the fit result.
Definition: SimpleFits.h:1585
static constexpr unsigned int Degree
Degree of the fit.
Definition: SimpleFits.h:648
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::FitParameterErrors ( ) const
overridevirtual

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

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

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

Definition at line 1576 of file SimpleFits.h.

1578 {
1580 } // SimplePolyFitterBase<>::FitParameterErrors()
virtual FitParameters_t FitParameterErrors() const override
Computes and returns all the parameter errors of the fit result.
Definition: SimpleFits.h:1576
virtual FitMatrix_t FitParameterCovariance() const override
Computes and returns all the covariance matrix of the fit result.
Definition: SimpleFits.h:1585
template<typename T, unsigned int D>
virtual FitParameters_t lar::util::details::SimplePolyFitterBase< T, D >::FitParameterErrors ( FitMatrix_t const &  Smat) const
inlineprotectedvirtual

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

Definition at line 798 of file SimpleFits.h.

799  { return ExtractParameterErrors(Smat); }
static FitParameters_t ExtractParameterErrors(FitMatrix_t const &Smat)
Extracts parameter errors from diagonal of the covarriance matrix.
Definition: SimpleFits.h:1715
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::FitParameters ( ) const
overridevirtual

Computes and returns all the parameters of the fit result.

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

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

Definition at line 1564 of file SimpleFits.h.

1566 {
1567  FitMatrix_t Xmat = MakeMatrixX();
1568  FitParameters_t fit_params;
1569  for (unsigned int iParam = 0; iParam < NParams; ++iParam)
1570  fit_params[iParam] = Param(iParam, Xmat);
1571  return fit_params;
1572 } // SimplePolyFitterBase<>::FitParameters()
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
virtual Data_t Param(unsigned int n, FitMatrix_t const &Xmat) const
Computes a single fit parameter using the given information.
Definition: SimpleFits.h:1700
virtual FitMatrix_t MakeMatrixX() const
Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } )
Definition: SimpleFits.h:1654
typename Interface_t::FitParameters_t FitParameters_t
type of set of fit parameters
Definition: SimpleFits.h:656
typename Interface_t::FitMatrix_t FitMatrix_t
type of matrix for covariance (a std::array)
Definition: SimpleFits.h:659
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::FitParameters ( FitMatrix_t const &  Xmat) const
protectedvirtual

Returns the fitted parameters using the provided information.

Definition at line 1679 of file SimpleFits.h.

1681 {
1682  FitParameters_t fit_params;
1683  for (unsigned int iParam = 0; iParam < NParams; ++iParam)
1684  fit_params[iParam] = Param(iParam, Xmat);
1685  return fit_params;
1686 } // SimplePolyFitterBase<>::FitParameters(FitMatrix_t)
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
virtual Data_t Param(unsigned int n, FitMatrix_t const &Xmat) const
Computes a single fit parameter using the given information.
Definition: SimpleFits.h:1700
typename Interface_t::FitParameters_t FitParameters_t
type of set of fit parameters
Definition: SimpleFits.h:656
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::FitParameters ( FitMatrix_t const &  Smat,
Data_t   
) const
protectedvirtual

Definition at line 1691 of file SimpleFits.h.

1693 {
1694  return MatrixProduct(Smat, MakeMatrixY());
1695 } // SimplePolyFitterBase<>::FitParameters(FitMatrix_t)
virtual FitParameters_t MatrixProduct(FitMatrix_t const &mat, FitParameters_t const &vec) const
Computes the product of a FitMatrix_t and a FitParameters_t.
Definition: SimpleFits.h:629
virtual FitParameters_t MakeMatrixY() const
Fills and returns the matrix (vector) of x^n y sum coefficients.
Definition: SimpleFits.h:1668
template<typename T , unsigned int D>
bool lar::util::details::SimplePolyFitterBase< T, D >::isValid ( ) const
inlineoverridevirtual

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.

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

Definition at line 1540 of file SimpleFits.h.

1540  {
1541  return (Base_t::N() > (int) Degree)
1542  && std::isnormal(Determinant(MakeMatrixX()));
1543 } // SimplePolyFitterBase<>::isValid()
virtual FitMatrix_t MakeMatrixX() const
Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } )
Definition: SimpleFits.h:1654
virtual Data_t Determinant(FitMatrix_t const &mat) const
Computes the determinant of a matrix.
Definition: SimpleFits.h:615
static constexpr unsigned int Degree
Degree of the fit.
Definition: SimpleFits.h:648
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::MakeMatrixX ( ) const
protectedvirtual

Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } )

Definition at line 1654 of file SimpleFits.h.

1656 {
1657  FitMatrix_t Xmat;
1658  for (unsigned int i = 0; i < NParams; ++i) { // row
1659  for (unsigned int j = i; j < NParams; ++j) { // column
1660  Xmat[j * NParams + i] = Xmat[i * NParams + j] = Base_t::XN(i+j);
1661  } // for j
1662  } // for i
1663  return Xmat;
1664 } // SimplePolyFitterBase<>::MakeMatrixX()
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
Data_t XN(unsigned int n) const
Returns the weighted sum of x^n.
Definition: SimpleFits.h:447
typename Interface_t::FitMatrix_t FitMatrix_t
type of matrix for covariance (a std::array)
Definition: SimpleFits.h:659
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::MakeMatrixY ( ) const
protectedvirtual

Fills and returns the matrix (vector) of x^n y sum coefficients.

Definition at line 1668 of file SimpleFits.h.

1670 {
1671  FitParameters_t Ymat;
1672  for (unsigned int i = 0; i < NParams; ++i) Ymat[i] = Base_t::XNY(i);
1673  return Ymat;
1674 } // SimplePolyFitterBase<>::MakeMatrixY()
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
Data_t XNY(unsigned int n) const
Returns the weighted sum of x^n y.
Definition: SimpleFits.h:450
typename Interface_t::FitParameters_t FitParameters_t
type of set of fit parameters
Definition: SimpleFits.h:656
template<typename T, unsigned int D>
virtual int lar::util::details::SimplePolyFitterBase< T, D >::NDF ( ) const
inlineoverridevirtual

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.

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

Definition at line 731 of file SimpleFits.h.

731 { return Base_t::N() - NParams; }
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::Param ( unsigned int  n,
FitMatrix_t const &  Xmat 
) const
protectedvirtual

Computes a single fit parameter using the given information.

Definition at line 1700 of file SimpleFits.h.

1701 {
1702  if (n > Degree) return Data_t(0); // no such a degree, its coefficient is 0
1703 
1704  Data_t detXmat = Determinant(Xmat);
1705  if (!std::isnormal(detXmat)) {
1706  throw std::range_error
1707  ("SimplePolyFitterBase::Param(): Determinant 0 while fitting");
1708  }
1709  return Param(n, Xmat, detXmat);
1710 } // SimplePolyFitterBase<>::Param(unsigned int, FitMatrix_t)
virtual Data_t Param(unsigned int n, FitMatrix_t const &Xmat) const
Computes a single fit parameter using the given information.
Definition: SimpleFits.h:1700
typename Base_t::Data_t Data_t
type of the data
Definition: SimpleFits.h:653
std::void_t< T > n
virtual Data_t Determinant(FitMatrix_t const &mat) const
Computes the determinant of a matrix.
Definition: SimpleFits.h:615
static constexpr unsigned int Degree
Degree of the fit.
Definition: SimpleFits.h:648
template<typename T , unsigned int D>
auto lar::util::details::SimplePolyFitterBase< T, D >::Param ( unsigned int  n,
FitMatrix_t const &  Xmat,
Data_t  detXmat 
) const
protectedvirtual

Definition at line 1727 of file SimpleFits.h.

1728 {
1729  if (n > Degree) return Data_t(0); // no such a degree, its coefficient is 0
1730  // XYmat is as Xmat...
1731  FitMatrix_t XYmat(Xmat);
1732  // ... except that the N-th column is replaced with { sum x^i y }
1733  for (unsigned int i = 0; i < NParams; ++i)
1734  XYmat[i * NParams + n] = Base_t::XNY(i);
1735 
1736  return Determinant(XYmat) / detXmat;
1737 } // SimplePolyFitterBase<>::Param(unsigned int, FitMatrix_t, Data_t)
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
Data_t XNY(unsigned int n) const
Returns the weighted sum of x^n y.
Definition: SimpleFits.h:450
typename Base_t::Data_t Data_t
type of the data
Definition: SimpleFits.h:653
std::void_t< T > n
typename Interface_t::FitMatrix_t FitMatrix_t
type of matrix for covariance (a std::array)
Definition: SimpleFits.h:659
virtual Data_t Determinant(FitMatrix_t const &mat) const
Computes the determinant of a matrix.
Definition: SimpleFits.h:615
static constexpr unsigned int Degree
Degree of the fit.
Definition: SimpleFits.h:648

Member Data Documentation

template<typename T, unsigned int D>
constexpr unsigned int lar::util::details::SimplePolyFitterBase< T, D >::Degree = Base_t::Degree
static

Degree of the fit.

Definition at line 648 of file SimpleFits.h.

template<typename T, unsigned int D>
constexpr unsigned int lar::util::details::SimplePolyFitterBase< T, D >::NParams = Interface_t::NParams
static

Number of parameters in the fit.

Definition at line 651 of file SimpleFits.h.


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