DGtal  1.3.beta
Public Types | Public Member Functions | Protected Attributes
DGtal::LagrangeInterpolation< TEuclideanRing > Class Template Reference

Aim: This class implements Lagrange basis functions and Lagrange interpolation. More...

#include <DGtal/math/LagrangeInterpolation.h>

Public Types

typedef LagrangeInterpolation< TEuclideanRing > Self
 
typedef TEuclideanRing Ring
 
typedef DGtal::MPolynomial< 1, RingPolynomial
 The monovariate polynomial type. More...
 
typedef std::size_t Size
 

Public Member Functions

 BOOST_CONCEPT_ASSERT ((concepts::CEuclideanRing< Ring >))
 
 ~LagrangeInterpolation ()=default
 
 LagrangeInterpolation ()
 
 LagrangeInterpolation (const std::vector< Ring > &xvalues)
 
 LagrangeInterpolation (const LagrangeInterpolation &other)=default
 
 LagrangeInterpolation (LagrangeInterpolation &&other)=default
 
LagrangeInterpolationoperator= (const LagrangeInterpolation &other)=default
 
LagrangeInterpolationoperator= (LagrangeInterpolation &&other)=default
 
Size size () const
 
Size degree () const
 
Ring denominator () const
 
void init (const std::vector< Ring > &xvalues)
 
Polynomial polynomial (const std::vector< Ring > &yvalues)
 
Polynomial basis (Size i) const
 
void selfDisplay (std::ostream &that_stream) const
 
bool OK () const
 

Protected Attributes

std::vector< RingmyX
 The vector of X-values (abscissa) More...
 
Ring myDeterminant
 The determinant of the Vandermonde matrix corresponding to X-values. More...
 
std::vector< PolynomialmyLagrangeBasis
 The Lagrange polynomial basis corresponding to X-values. More...
 

Detailed Description

template<typename TEuclideanRing>
class DGtal::LagrangeInterpolation< TEuclideanRing >

Aim: This class implements Lagrange basis functions and Lagrange interpolation.

Description of class 'LagrangeInterpolation'

See also
testLagrangeInterpolation.cpp
Template Parameters
TEuclideanRingany model of CEuclideanRing like int, double, etc.

Definition at line 62 of file LagrangeInterpolation.h.

Member Typedef Documentation

◆ Polynomial

template<typename TEuclideanRing >
typedef DGtal::MPolynomial< 1, Ring > DGtal::LagrangeInterpolation< TEuclideanRing >::Polynomial

The monovariate polynomial type.

Definition at line 72 of file LagrangeInterpolation.h.

◆ Ring

template<typename TEuclideanRing >
typedef TEuclideanRing DGtal::LagrangeInterpolation< TEuclideanRing >::Ring

Definition at line 68 of file LagrangeInterpolation.h.

◆ Self

template<typename TEuclideanRing >
typedef LagrangeInterpolation< TEuclideanRing > DGtal::LagrangeInterpolation< TEuclideanRing >::Self

Definition at line 67 of file LagrangeInterpolation.h.

◆ Size

template<typename TEuclideanRing >
typedef std::size_t DGtal::LagrangeInterpolation< TEuclideanRing >::Size

Definition at line 73 of file LagrangeInterpolation.h.

Constructor & Destructor Documentation

◆ ~LagrangeInterpolation()

template<typename TEuclideanRing >
DGtal::LagrangeInterpolation< TEuclideanRing >::~LagrangeInterpolation ( )
default

Destructor.

◆ LagrangeInterpolation() [1/4]

template<typename TEuclideanRing >
DGtal::LagrangeInterpolation< TEuclideanRing >::LagrangeInterpolation ( )
inline

Constructor. The object is invalid.

Definition at line 86 of file LagrangeInterpolation.h.

◆ LagrangeInterpolation() [2/4]

template<typename TEuclideanRing >
DGtal::LagrangeInterpolation< TEuclideanRing >::LagrangeInterpolation ( const std::vector< Ring > &  xvalues)
inline

Constructs the Lagrange interpolation object with its x-values

Parameters
xvaluesthe vector of X-values, corresponding to the abscissa where the interpolation will take place.

Definition at line 94 of file LagrangeInterpolation.h.

95  {
96  init( xvalues );
97  }

References DGtal::LagrangeInterpolation< TEuclideanRing >::init().

◆ LagrangeInterpolation() [3/4]

template<typename TEuclideanRing >
DGtal::LagrangeInterpolation< TEuclideanRing >::LagrangeInterpolation ( const LagrangeInterpolation< TEuclideanRing > &  other)
default

Copy constructor.

Parameters
otherthe object to clone.

◆ LagrangeInterpolation() [4/4]

template<typename TEuclideanRing >
DGtal::LagrangeInterpolation< TEuclideanRing >::LagrangeInterpolation ( LagrangeInterpolation< TEuclideanRing > &&  other)
default

Move constructor.

Parameters
otherthe object to clone.

Member Function Documentation

◆ basis()

template<typename TEuclideanRing >
Polynomial DGtal::LagrangeInterpolation< TEuclideanRing >::basis ( Size  i) const
inline
Parameters
iany value between 0 included and size() excluded.
Returns
the numerator of i-th Lagrange basis polynomial (divide by denominator to get the exact Lagrange basis polynomial).

Definition at line 199 of file LagrangeInterpolation.h.

200  {
201  ASSERT( 0 <= i && i < size() );
202  return myLagrangeBasis[ i ];
203  }

References DGtal::LagrangeInterpolation< TEuclideanRing >::myLagrangeBasis, and DGtal::LagrangeInterpolation< TEuclideanRing >::size().

Referenced by DGtal::LagrangeInterpolation< TEuclideanRing >::selfDisplay().

◆ BOOST_CONCEPT_ASSERT()

template<typename TEuclideanRing >
DGtal::LagrangeInterpolation< TEuclideanRing >::BOOST_CONCEPT_ASSERT ( (concepts::CEuclideanRing< Ring >)  )

◆ degree()

template<typename TEuclideanRing >
Size DGtal::LagrangeInterpolation< TEuclideanRing >::degree ( ) const
inline
Returns
the degree of Lagrange polynomials (i.e. size()-1)

Definition at line 132 of file LagrangeInterpolation.h.

133  {
134  return size() - 1;
135  }

References DGtal::LagrangeInterpolation< TEuclideanRing >::size().

◆ denominator()

template<typename TEuclideanRing >
Ring DGtal::LagrangeInterpolation< TEuclideanRing >::denominator ( ) const
inline
Returns
the common denominator to Lagrange bases and Lagrange polynomial.

Definition at line 138 of file LagrangeInterpolation.h.

139  {
140  return myDeterminant;
141  }

References DGtal::LagrangeInterpolation< TEuclideanRing >::myDeterminant.

Referenced by DGtal::EhrhartPolynomial< TSpace, TInteger >::init().

◆ init()

template<typename TEuclideanRing >
void DGtal::LagrangeInterpolation< TEuclideanRing >::init ( const std::vector< Ring > &  xvalues)
inline

Initializes the Lagrange interpolation object with its x-values, and computes the corresponding Lagrange Basis.

Parameters
xvaluesthe vector of X-values, corresponding to the abscissa where the interpolation will take place.

Definition at line 148 of file LagrangeInterpolation.h.

149  {
150  myX = xvalues;
151  // Compute Vandermonde determinant
153  for ( Dimension i = 0; (i+1) < size(); ++i )
154  for ( Dimension j = i + 1; j < size(); ++j )
155  myDeterminant *= myX[ j ] - myX[ i ];
156  // compute Lagrange polynomial basis.
157  myLagrangeBasis.clear();
158  myLagrangeBasis.reserve( size() );
159  for ( Dimension j = 0; j < size(); ++j )
160  {
161  Ring c = myDeterminant;
162  for ( Dimension m = 0; m < size(); ++m )
163  if ( m != j )
164  c /= myX[ j ] - myX[ m ];
165  Polynomial P = c; // constant
166  for ( Dimension m = 0; m < size(); ++m )
167  if ( m != j )
168  P *= mmonomial<Ring>( 1 ) - myX[ m ] * mmonomial<Ring>( 0 );
169  myLagrangeBasis.push_back( P );
170  }
171  }

References DGtal::LagrangeInterpolation< TEuclideanRing >::myDeterminant, DGtal::LagrangeInterpolation< TEuclideanRing >::myLagrangeBasis, DGtal::LagrangeInterpolation< TEuclideanRing >::myX, and DGtal::LagrangeInterpolation< TEuclideanRing >::size().

Referenced by DGtal::LagrangeInterpolation< TEuclideanRing >::LagrangeInterpolation().

◆ OK()

template<typename TEuclideanRing >
bool DGtal::LagrangeInterpolation< TEuclideanRing >::OK ( ) const
inline

Checks the validity/consistency of the object.

Returns
'true' if the object is valid, 'false' otherwise.

Definition at line 224 of file LagrangeInterpolation.h.

225  {
227  }

References DGtal::LagrangeInterpolation< TEuclideanRing >::myDeterminant.

◆ operator=() [1/2]

template<typename TEuclideanRing >
LagrangeInterpolation& DGtal::LagrangeInterpolation< TEuclideanRing >::operator= ( const LagrangeInterpolation< TEuclideanRing > &  other)
default

Assignment.

Parameters
otherthe object to copy.
Returns
a reference on 'this'.

◆ operator=() [2/2]

template<typename TEuclideanRing >
LagrangeInterpolation& DGtal::LagrangeInterpolation< TEuclideanRing >::operator= ( LagrangeInterpolation< TEuclideanRing > &&  other)
default

Move assignment.

Parameters
otherthe object to move.
Returns
a reference on 'this'.

◆ polynomial()

template<typename TEuclideanRing >
Polynomial DGtal::LagrangeInterpolation< TEuclideanRing >::polynomial ( const std::vector< Ring > &  yvalues)
inline
Parameters
[in]yvaluesthe y-values corresponding to the current x-values, in the same order.
Returns
the numerator of the Lagrange polynomial that interpolates all given values (divide by denominator to get the exact Lagrange polynomial).
Note
if yvalues has not the correct size, then the zero polynomial is returned.

Definition at line 182 of file LagrangeInterpolation.h.

183  {
184  Polynomial P;
185  if ( yvalues.size() != size() ) return P;
186  for ( Dimension j = 0; j < size(); ++j )
187  P += yvalues[ j ] * myLagrangeBasis[ j ];
188  return P;
189  }

References DGtal::LagrangeInterpolation< TEuclideanRing >::myLagrangeBasis, and DGtal::LagrangeInterpolation< TEuclideanRing >::size().

Referenced by DGtal::EhrhartPolynomial< TSpace, TInteger >::init().

◆ selfDisplay()

template<typename TEuclideanRing >
void DGtal::LagrangeInterpolation< TEuclideanRing >::selfDisplay ( std::ostream &  that_stream) const
inline

Writes/Displays the object on an output stream.

Parameters
that_streamthe output stream where the object is written.

Definition at line 212 of file LagrangeInterpolation.h.

213  {
214  that_stream << "[LagrangeInterpolation det=" << myDeterminant << std::endl;
215  for ( Size i = 0; i < size(); i++ )
216  that_stream << "l_" << i << "=" << basis( i ) << std::endl;
217  that_stream << "]";
218  }

References DGtal::LagrangeInterpolation< TEuclideanRing >::basis(), DGtal::LagrangeInterpolation< TEuclideanRing >::myDeterminant, and DGtal::LagrangeInterpolation< TEuclideanRing >::size().

Referenced by DGtal::operator<<().

◆ size()

template<typename TEuclideanRing >
Size DGtal::LagrangeInterpolation< TEuclideanRing >::size ( ) const
inline

Field Documentation

◆ myDeterminant

template<typename TEuclideanRing >
Ring DGtal::LagrangeInterpolation< TEuclideanRing >::myDeterminant
protected

◆ myLagrangeBasis

template<typename TEuclideanRing >
std::vector<Polynomial> DGtal::LagrangeInterpolation< TEuclideanRing >::myLagrangeBasis
protected

◆ myX

template<typename TEuclideanRing >
std::vector< Ring > DGtal::LagrangeInterpolation< TEuclideanRing >::myX
protected

The documentation for this class was generated from the following file:
DGtal::NumberTraitsImpl< std::decay< T >::type >::ZERO
static const std::decay< T >::type ZERO
Constant Zero.
Definition: NumberTraits.h:100
DGtal::Dimension
DGtal::uint32_t Dimension
Definition: Common.h:137
Size
HalfEdgeDataStructure::Size Size
Definition: testHalfEdgeDataStructure.cpp:50
DGtal::LagrangeInterpolation::basis
Polynomial basis(Size i) const
Definition: LagrangeInterpolation.h:199
DGtal::LagrangeInterpolation::Polynomial
DGtal::MPolynomial< 1, Ring > Polynomial
The monovariate polynomial type.
Definition: LagrangeInterpolation.h:72
DGtal::LagrangeInterpolation::size
Size size() const
Definition: LagrangeInterpolation.h:126
DGtal::LagrangeInterpolation::myLagrangeBasis
std::vector< Polynomial > myLagrangeBasis
The Lagrange polynomial basis corresponding to X-values.
Definition: LagrangeInterpolation.h:237
DGtal::LagrangeInterpolation::init
void init(const std::vector< Ring > &xvalues)
Definition: LagrangeInterpolation.h:148
DGtal::LagrangeInterpolation::myDeterminant
Ring myDeterminant
The determinant of the Vandermonde matrix corresponding to X-values.
Definition: LagrangeInterpolation.h:235
DGtal::LagrangeInterpolation::myX
std::vector< Ring > myX
The vector of X-values (abscissa)
Definition: LagrangeInterpolation.h:233
DGtal::NumberTraitsImpl< std::decay< T >::type >::ONE
static const std::decay< T >::type ONE
Constant One.
Definition: NumberTraits.h:103