Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsNumericPolatorT< Type > Class Template Reference

a not so basic polator for numeric types. More...

#include <PsNumericPolator.h>

Inheritance diagram for PsNumericPolatorT< Type >:

Inheritance graph
[legend]
Collaboration diagram for PsNumericPolatorT< Type >:

Collaboration graph
[legend]
List of all members.

Public Methods

 PsNumericPolatorT (void)
virtual ~PsNumericPolatorT (void)
virtual const PsNumericTypeT<
Type > & 
interpolate (PsNumericTypeT< Type > &resultPlaceHolder, const int interprecisionLevel, const PsDate &dateNeeded, const PsDate &dateAfter, const PsNumericTypeT< Type > &valueAfter, const PsDate &dateBefore, int offsetToMostRecentOfDateBefore) const
 Interpolation member function.

virtual const PsNumericTypeT<
Type > & 
extrapolate (PsNumericTypeT< Type > &resultPlaceHolder, const int requestedPrecisionLevel, const PsDate &t, const PsDate &tIndice) const
 extrapolate member function

virtual const PsNumericTypeT<
Type > & 
antepolate (PsNumericTypeT< Type > &resultPlaceHolder, const int requestedPrecisionLevel, const PsDate &t, const PsDate &tIndice, unsigned int indice) const
 La méthode d'antépolation.


Detailed Description

template<typename Type>
class PsNumericPolatorT< Type >

a not so basic polator for numeric types.

This polator supports 4 levels of polation : from none to 3, which supposes second degre continuity

Definition at line 31 of file PsNumericPolator.h.


Constructor & Destructor Documentation

template<typename Type>
PsNumericPolatorT< Type >::PsNumericPolatorT void    [inline]
 

Definition at line 64 of file PsNumericPolator.h.

00065                                                       : PsPolator< PsNumericTypeT<Type> > (3)
00066 {

template<typename Type>
PsNumericPolatorT< Type >::~PsNumericPolatorT void    [inline, virtual]
 

Definition at line 70 of file PsNumericPolator.h.

00072 {


Member Function Documentation

template<typename Type>
const PsNumericTypeT< Type > & PsNumericPolatorT< Type >::antepolate PsNumericTypeT< Type > &    resultPlaceHolder,
const int    requestedPrecisionLevel,
const PsDate   t,
const PsDate   tIndice,
unsigned int    indice
const [inline, virtual]
 

La méthode d'antépolation.

Parameters:
requestedPrecisionLevel : le niveau souhaité d'antepolate
t : la date à laquelle on souhaite obtenir une valeur
tIndice : la date associé à la valeur la plus proche == getDate(indice)

Reimplemented from PsPolator< PsNumericTypeT< Type > >.

Definition at line 202 of file PsNumericPolator.h.

References PsPolatorNT::Constant, PsPolatorNT::Cubic, PsNumericType::cubicExtrapolate(), PsPolatorNT::Linear, PsNumericType::linearExtrapolate(), PsDate, PsPolatorNT::Quadratic, and PsNumericType::quadraticExtrapolate().

00209 {
00210    
00211 #ifdef _DEBUGTYPEUTIL
00212   cout << "*********************************************" << endl ;
00213   cout << "PsNumericPolatorT<Type>::antepolate" << endl;
00214   cout << "PsDate t <----- : " << t << endl ;
00215   cout << "PsDate tIndice <----- : " << tIndice << endl ;
00216   cout << "polation level : " << requestedPrecisionLevel << endl ;
00217   cout << "index " << indice << endl ;
00218   cout << "*********************************************" << endl ;
00219 #endif
00220 
00221   double v0,v1,v2,v3 ;
00222   long t0,t1,t2,t3 ;
00223 
00224 #ifdef _DEBUGPOLATION
00225   cerr << "PsNumericPolatorT<Type>::antepolate (" <<requestedPrecisionLevel<<", "<<t<<", "<<tIndice<<" "<<indice<<")"<<endl;
00226 #endif
00227   switch (requestedPrecisionLevel) {
00228   case PsPolatorNT::Constant : 
00229     resultPlaceHolder = get(indice) ;
00230     break ;
00231   case PsPolatorNT::Linear : 
00232     v0 = get(indice-1);
00233     t0 = getDate(indice-1);
00234     v1 = get(indice) ;
00235     t1 = tIndice ;
00236 #ifdef _DEBUGPOLATION
00237     cerr<<"calling linearExtrapolate("<<t<<", "<<t1<<", "<<v1<<", "<<t0<<", "<<v0<<")"<<endl;
00238     assert (t != tIndice ) ;
00239     assert (t0 != tIndice ) ;
00240 #endif
00241     resultPlaceHolder = PsNumericType::linearExtrapolate(t, t1, v1, t0, v0) ;
00242     break ; 
00243   case PsPolatorNT::Quadratic :
00244     v0 = get( indice - 2 );
00245     t0 = getDate( indice - 2 ); 
00246     v1 = get( indice - 1 );  
00247     t1 = getDate( indice - 1 );  
00248     v2 = get( indice ) ;
00249     t2 = tIndice ;
00250 #ifdef _DEBUGPOLATION
00251     cerr<<"calling quadraticExtrapolate("<<t<<", "<<t2<<", "<<v2<<", "<<t1<<", "<<v1<<", "<<t0<<", "<<v0<<")"<<endl;
00252 #endif
00253     resultPlaceHolder = PsNumericType::quadraticExtrapolate(t, t2, v2, t1, v1, t0, v0) ;
00254     break;
00255   case PsPolatorNT::Cubic :
00256     v0 = get( indice - 3 );
00257     t0 = getDate( indice - 3 );
00258     v1 = get( indice - 2 );
00259     t1 = getDate( indice - 2 );
00260     v2 = get( indice - 1 );  
00261     t2 = getDate( indice - 1 );  
00262     v3 = get( indice ) ;
00263     t3 = tIndice ;
00264     resultPlaceHolder = PsNumericType:: cubicExtrapolate(t, t3, v3, t2, v2, t1, v1, t0, v0) ;
00265     break;
00266   default :
00267     throw PsUserException ("PsInterpoleurNumerique::antepolate : unknown polation level") ;
00268   }
00269   return resultPlaceHolder ;

template<typename Type>
const PsNumericTypeT< Type > & PsNumericPolatorT< Type >::extrapolate PsNumericTypeT< Type > &    resultPlaceHolder,
const int    requestedPrecisionLevel,
const PsDate   t,
const PsDate   tIndice
const [inline, virtual]
 

extrapolate member function

Parameters:
requestedPrecisionLevel : le niveau souhaité d'extrapolation
t : la date à laquelle on souhaite obtenir une valeur
tIndice : la date associé à la valeur la plus proche == getDate (0)

Reimplemented from PsPolator< PsNumericTypeT< Type > >.

Definition at line 140 of file PsNumericPolator.h.

References PsPolatorNT::Constant, PsPolatorNT::Cubic, PsNumericType::cubicExtrapolate(), PsPolatorNT::Linear, PsNumericType::linearExtrapolate(), PsDate, PsPolatorNT::Quadratic, and PsNumericType::quadraticExtrapolate().

00145                                                                                            {
00146   //extrapolate à la sauce David Margery
00147   //il s'agit d'une extrapolation par morceaux
00148   //on cherche à trouver la valeur à t
00149 
00150   double v0,v1,v2,v3 ;
00151   long t0,t1,t2,t3 ;
00152 
00153 #ifdef _DEBUGPOLATION
00154   cerr << "PsNumericPolatorT<Type>::extrapolate (" <<requestedPrecisionLevel<<", "<<t<<", "<<tIndice<<")"<<endl;
00155 #endif
00156   switch (requestedPrecisionLevel) {
00157   case PsPolatorNT::Constant : 
00158     resultPlaceHolder = get(0) ;
00159     break ;
00160   case PsPolatorNT::Linear : 
00161     v1 = get(0) ;
00162     v0 = get(1);
00163     t0 = getDate(1);
00164     t1 = tIndice ;
00165 #ifdef _DEBUGPOLATION
00166     cerr<<"calling linearExtrapolate("<<t<<", "<<t1<<", "<<v1<<", "<<t0<<", "<<v0<<")"<<endl;
00167     assert (t != tIndice ) ;
00168     assert (t0 != tIndice ) ;
00169 #endif
00170     resultPlaceHolder = PsNumericType::linearExtrapolate(t, t1, v1, t0, v0) ;
00171     break ; 
00172   case PsPolatorNT::Quadratic :
00173      //calculating v3, next value after v0,v1,v2,
00174     v2 = get( 0 ) ;
00175     t2 = tIndice ;
00176     v1 = get( 1 );  
00177     t1 = getDate( 1 );  
00178     v0 = get( 2 );
00179     t0 = getDate( 2 ); 
00180 #ifdef _DEBUGPOLATION
00181     cerr<<"calling quadraticExtrapolate("<<t<<", "<<t2<<", "<<v2<<", "<<t1<<", "<<v1<<", "<<t0<<", "<<v0<<")"<<endl;
00182 #endif
00183     resultPlaceHolder = PsNumericType::quadraticExtrapolate(t, t2, v2, t1, v1, t0, v0) ;
00184     break;
00185   case PsPolatorNT::Cubic :
00186     v3 = get( 0 ) ;
00187     t3 = tIndice ;
00188     v2 = get( 1 );  
00189     t2 = getDate( 1 );  
00190     v1 = get( 2 );
00191     t1 = getDate( 2 );
00192     v0 = get( 3 );
00193     t0 = getDate( 3 );
00194     resultPlaceHolder = PsNumericType::cubicExtrapolate(t, t3, v3, t2, v2, t1, v1, t0, v0) ;
00195     break;
00196   default :
00197     throw PsUserException ("PsInterpoleurNumerique::extrapolate : unknown polation level") ;
00198   }
00199   return resultPlaceHolder ;

template<typename Type>
const PsNumericTypeT< Type > & PsNumericPolatorT< Type >::interpolate PsNumericTypeT< Type > &    resultPlaceHolder,
const int    interprecisionLevel,
const PsDate   dateNeeded,
const PsDate   dateAfter,
const PsNumericTypeT< Type > &    valueAfter,
const PsDate   dateBefore,
int    offsetToMostRecentOfDateBefore
const [inline, virtual]
 

Interpolation member function.

Parameters:
interprecisionLevel : the requested interpolation level
dateNeeded : date for which a value will be calculated
dateAfter : date of the nearest exact value which date is after dateNeeded
valueAfter : the coressponding value
dateBefore : date of the nearest exact value which date is before dateNeeded
offsetToMostRecentOfDateBefore : getDate(offsetToMostRecentOfDateBefore) == dateBefore
Returns:
: an estimated value for dateNeeded

Reimplemented from PsPolator< PsNumericTypeT< Type > >.

Definition at line 76 of file PsNumericPolator.h.

References PsPolatorNT::Constant, PsPolatorNT::Cubic, PsNumericType::cubicInterpolate(), PsPolator< PsNumericTypeT< Type > >::get(), PsPolator< PsNumericTypeT< Type > >::getDate(), PsPolatorNT::Linear, PsNumericType::linearInterpolate(), PsDate, PsPolatorNT::Quadratic, and PsNumericType::quadraticInterpolate().

00084                                                                                           {
00085    
00086 #ifdef _DEBUGTYPEUTIL
00087   cout << "*********************************************" << endl ;
00088   cout << "PsNumericPolatorT<Type>::interpolate" << endl;
00089   cout << "interpolate level : " << interprecisionLevel <<endl ;
00090   cout << "PsDate dateAfter <----- : " << dateAfter << endl ;
00091   cout << "PsDate dateNeeded <----- : " << dateNeeded << endl ;
00092   cout << "PsDate dateBefore <----- : " << dateBefore << endl ;
00093   cout << "Type : valueAfter " << valueAfter << endl ;
00094   cout << "int : offsetToMostRecentOfDateBefore " << offsetToMostRecentOfDateBefore << endl ;
00095   cout << "*********************************************" << endl ;
00096 #endif
00097     
00098   switch ( interprecisionLevel ) {
00099   case PsPolatorNT::Constant : 
00100      if ( (dateAfter - dateNeeded) <= (dateNeeded - dateBefore) ) {
00101         resultPlaceHolder = valueAfter ;
00102      }
00103      else {
00104         resultPlaceHolder = get (offsetToMostRecentOfDateBefore) ;
00105      }
00106      break ;
00107   case PsPolatorNT::Linear : 
00108      resultPlaceHolder = PsNumericType::linearInterpolate(dateNeeded, 
00109                                                           dateAfter, 
00110                                                           valueAfter, 
00111                                                           dateBefore, 
00112                                                           get (offsetToMostRecentOfDateBefore) );
00113   case PsPolatorNT::Quadratic :
00114      resultPlaceHolder = PsNumericType::quadraticInterpolate(dateNeeded, 
00115                                                              dateAfter, 
00116                                                              valueAfter, 
00117                                                              dateBefore, 
00118                                                              get (offsetToMostRecentOfDateBefore) ,
00119                                                              getDate (offsetToMostRecentOfDateBefore + 1), 
00120                                                              get (offsetToMostRecentOfDateBefore + 1) ) ;
00121   case PsPolatorNT::Cubic :
00122      resultPlaceHolder = PsNumericType::cubicInterpolate(dateNeeded, 
00123                                                          dateAfter, 
00124                                                          valueAfter, 
00125                                                          dateBefore, 
00126                                                          get (offsetToMostRecentOfDateBefore),
00127                                                          getDate (offsetToMostRecentOfDateBefore + 1), 
00128                                                          get (offsetToMostRecentOfDateBefore + 1), 
00129                                                          getDate (offsetToMostRecentOfDateBefore + 2), 
00130                                                          get (offsetToMostRecentOfDateBefore + 2) ) ;
00131   break ;
00132   default :
00133     throw PsUserException ("PsNumericPolatorT<Type>::interpolate : unknown polation level") ;
00134   }
00135   return resultPlaceHolder ;


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

Documentation generated on Mon Nov 25 15:26:16 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001