OptIntp Class Template Reference

Class template optimizes multi-dimensional interpolation tables for class calc::NIntp. More...

#include <OptIntp.h>

Inherits Base.

Inheritance diagram for OptIntp:

Inheritance graph
[legend]
List of all members.

Public Types

 GRID_AVG = 0
 GRID_DEV
 GRID_MAX
 GRID_SAMPLE = 0
 LOOP_MAXIMUM
enum  PTYPE { GRID_SAMPLE = 0, RANDOM_COUNT, RANDOM_SEED, LOOP_MAXIMUM, PTYPE_CNT }
 PTYPE_CNT
 RANDOM_AVG
 RANDOM_COUNT
 RANDOM_DEV
 RANDOM_MAX
 RANDOM_SEED
enum  VTYPE { GRID_AVG = 0, GRID_DEV, GRID_MAX, RANDOM_AVG, RANDOM_DEV, RANDOM_MAX, VTYPE_CNT }
 VTYPE_CNT

Public Member Functions

yType evalBasis (const xType *vXn) const throw (IntpErr)
yType evalTable (const xType *vXn) throw (IntpErr)
yType(* getBasis (void))(const xType *)
xType getError (enum OptIntp< xType, yType >::VTYPE vType) const
NIntp< xType, yType > * getNIntp (void)
int getParameter (enum OptIntp< xType, yType >::PTYPE pType) const
bool getPrintStatus (void) const
bool gridError (xType **yErr=(xType **)(0))
bool optimize (const xType *xTol, xType yTol)
bool optimize (xType xTol, xType yTol)
 OptIntp (const OptIntp< xType, yType > &ei)
 OptIntp (yType(&rFn)(const xType *), NIntp< xType, yType > &ni)
bool randomError (void)
bool setBasis (yType(&rFn)(const xType *))
bool setParameter (enum OptIntp< xType, yType >::PTYPE pType, int param)
bool setPrintStatus (bool flag)
bool update (const xType *const *arXn=(xType **)(0), const yType *arYn=(yType *)(0))
 ~OptIntp (void)

Static Public Member Functions

template<typename bType>
static bool setSpanX (bType **arXn, const bType *arXLo, const bType *arXHi, const int *arNn, int nDimen)
template<typename bType>
static bool setSpanX (bType **arXn, bType vXLo, bType vXHi, const int *arNn, int nDimen)

Static Public Attributes

static const int DEF_GRID_SAMPLE = 1
static const int DEF_LOOP_MAX = 1000
static const int DEF_RANDOM_COUNT = 2000
static const int DEF_RANDOM_SEED = 1

Detailed Description

template<typename xType, typename yType>
class calc::OptIntp< xType, yType >

Class template optimizes multi-dimensional interpolation tables for class calc::NIntp.

This class defines interpolation table errors and reduces these errors for multi-dimensional interpolation table formulations expressed as class calc::NIntp through optimization. To optimize data tables, this class perturbs data point locations in a multi-dimensional interpolation table to minimize interpolation error for a static number of data points. A known function describing the interpolation table is incorporated into the error evaluation calc::OptIntp object. The interpolation table can be constructed from any class inheriting the abstract multi-dimensional interpolation class calc::NIntp.

The declaration typename <xType> specifies the form of independent variables used in interpolation calculations. The declaration typename <yType> specifies the form of solution variables and errors used in interpolation calculations. In general, the <yType> variables should be the equal or superset of the <xType> variables.

Equations

This section outlines a brief description of the equations used to optimize multi-dimensional interpolation tables with calc::OptIntp::optimize(). Modifications and improvement are encouraged.

The objective of the optimization function is to modify the values of the points in an interpolation table such that the table can estimate the behavior of the user-provided function with minimal errors. In the optimization, the number of interpolation points remains fixed along with the interval of interpolation.

For this application, interpolation table optimization is measured by the difference in integral errors (ei) in the intervals on either side of an interpolation point (i). If the interval error on one side of a point is significantly higher than the other side, this function assumes that the interpolation point can be displaced into the higher error interval, until the error difference across the point is near zero. Optimization will halt when all interval errors are roughly equal, or no further point displacement can reduce the overall table error.

\[ e_{i} = \frac{1}{x_{i} - x_{i-1}} \int_{x_{i-1}}^{x_{i}} \left| y_{table}(x) - y_{basis}(x) \right| dx \]

\[ \sum \Delta e_{i} = \sum \left( e_{i} - e_{i-1} \right) \rightarrow 0 \]

To relate interpolation point position change with table error, each point (xi) is moved slightly to determine its influence on the total table error (E). The small error change has correlation with a partial derivative since all other points are held in their original positions.

\[ \frac {\partial E}{\partial x_{i}} \approx \frac {\Delta E}{\Delta x_{i}} = \frac {\Delta e_{i}}{K_{i} \left( x_{i} \right)} \]

From the single point displacement, a constant can be estimated relating the total change in error (E) with the local error (ei) change on either side of the point. For small interpolation point displacements, the requirement of a constant (Ki) should hold. The optimization assumes that the term of local error delta times point displacement over total error delta will be roughly constant.

\[ K_{i} = \frac {\Delta e_{i}}{\Delta E} \Delta x_{i} \]

To optimize an interpolation table, the constants (Ki) are calculated for all interpolation points. Then, at each point (i), the current local change in error (ei) and total change in error (Elast) for the previous iteration are used to estimate displacement for each point.

\[ \Delta x_{i} = K_{i} \frac {\Delta E_{last}}{\Delta e_{i}} \]

In software application, interpolation points are displaced with the same set of constants (Ki), then, errors are recalculated, until no more total error reduction is possible. At this point, the constants are calculated again and the process repeated, until no further error reduction is possible with new constants.

Author
efgeorge
Date
2006/07/19 13:21:43
Revision
1.3
Examples:

example_NIntp.txt.


Member Enumeration Documentation

enum PTYPE

Enumeration assigns an index to an optimized interpolation parameter.

Enumerator:
GRID_SAMPLE  test point count per dimension used in error calculations through grid selection (OptIntp::gridError())
RANDOM_COUNT  total test point count used in error calculations through random selection (OptIntp::randomError())
RANDOM_SEED  inital seed value used in error calculations through random selection (OptIntp::randomError())
LOOP_MAXIMUM  inital do-loop value used in optimization iterations (OptIntp::optimize())
PTYPE_CNT  parameter index count

enum VTYPE

Enumeration assigns an index to an optimized interpolation error variable.

Enumerator:
GRID_AVG  average absolute error through table grid selection (OptIntp::gridError())
GRID_DEV  standard deviation absolute error through table grid selection (OptIntp::gridError())
GRID_MAX  maximum absolute error through table grid selection (OptIntp::gridError())
RANDOM_AVG  average absolute error through random selection (OptIntp::randomError())
RANDOM_DEV  standard deviation absolute error through random selection (OptIntp::randomError())
RANDOM_MAX  maximum absolute error through random selection (OptIntp::randomError())
VTYPE_CNT  variable index count


Constructor & Destructor Documentation

OptIntp ( yType(&)(const xType *)  rFn,
NIntp< xType, yType > &  ni 
)

Constructor initializes an n-Dimension interpolation table error calculation object.

Parameters:
rFn a reference to a basis function that supplies exact values for interpolation error calculations over the intervals of interest (see calc::OptIntp::setBasis()) (y units)
ni a reference to an n-Dimension interpolation object to analyze
Remarks:
  • The interpolation object ni must be initialized with data.

OptIntp ( const OptIntp< xType, yType > &  ei  ) 

Copy constructor initializes an n-Dimension interpolation error object from the specified existing error object.

Parameters:
ei a reference to an n-Dimension interpolation error object

~OptIntp ( void   ) 

Destructor frees allocated memory.


Member Function Documentation

yType evalBasis ( const xType *  vXn  )  const throw (IntpErr)

Function evaluates the user-specified basis function at the specified independent vector vXn.

Parameters:
vXn a pointer to an n-Dimension independent data point vector (x units)
Returns:
a calculated dependent data point value (y units)
Exceptions:
IntpErr type of object thrown
Remarks:
  • The basis function provides exact values for interpolation table error calculations (see calc::OptIntp::setBasis()).
  • If the optimization object is not initialized, a zero value is returned.

yType evalTable ( const xType *  vXn  )  throw (IntpErr)

Function determines the interpolated dependent data point value at the specified independent data vector.

Parameters:
vXn a pointer to an independent data point vector (x units)
Returns:
a calculated dependent data point value (y units)
Exceptions:
IntpErr type of object thrown
Remarks:
  • This function evaluates the interpolation table supplied by the user.
  • If the optimization object is not initialized, a zero value is returned.

yType(* getBasis (  ) 

Function returns a pointer to the basis function of the error deviation object.

Returns:
the data evaluation function pointer

xType getError ( enum OptIntp< xType, yType >::VTYPE  vType  )  const

Function returns the indicated error value between the error object's n-Dimension interpolation object and the error object's basis function. estimated through random point or grid selection.

Parameters:
vType variable index indentifying the type of data
Returns:
the current variable value of the interpolation table error calculations (|y| units)
Remarks:

NIntp<xType,yType>* getNIntp ( void   ) 

Function returns a pointer to the error deviation object's n-Dimension interpolation object.

Returns:
a pointer to a multi-dimension interpolation object
Remarks:
  • This object was specified with the error deviation object's instantiation, and can not be changed.

int getParameter ( enum OptIntp< xType, yType >::PTYPE  pType  )  const

Function returns the indicated error method parameter for optimization interpolation object.

Parameters:
pType parameter index indentifying the type of data
Returns:
the current parameter value of the interpolation table error analysis
Remarks:
  • If a valid paramater index is not identified, -1 is returned.
  • OptIntp::GRID_SAMPLE
    • The test point count per dimension indicates the number of equally spaced sample error measurements taken between independent interpolation points to determine average error.
    • The total number of sample points within an interval equals the dimensional test point count raised to the power of the number of dimensions.
    • The function OptIntp::gridError() uses the specified parameter, and the function's execution time may be significantly affected.
    • If the value of the seed variable is not specified, the variable is assigned the value OptIntp::DEF_GRID_SAMPLE.
  • OptIntp::RANDOM_COUNT
    • The test point count must be greater than zero.
    • The function OptIntp::randomError()uses the specified parameter and the function's execution time may be significantly affected.
    • If the value of the seed variable is not specified, the variable is assigned the value OptIntp::DEF_RANDOM_COUNT.
  • OptIntp::RANDOM_SEED
  • OptIntp::LOOP_MAXIMUM

bool getPrintStatus ( void   )  const

Function returns the display status of progress printed to the primary console stream cout for selected function calculations.

Returns:
status flag
  • false (calculation progress is not displayed)
  • true (calculation progress is displayed)
Remarks:
  • The overloaded function OptIntp::randomError() is capable of displaying calculation progress for especially long program executions.
  • By default, progress of this function's calculations is not displayed to the console.

bool gridError ( xType **  yErr = (xType**)(0)  ) 

Function determines averaged and data point interval error values using a grid selection between each data point interval.

Parameters:
yErr a pointer to a calculated error by data point interval array (|y| units)
Returns:
status flag
  • false (successful execution)
  • true (execution error, calculations not made)
Remarks:
  • The values returned by OptIntp::getError() using the enumerators OptIntp::GRID_AVG, OptIntp::GRID_DEV, and OptIntp::GRID_MAX are calculated from current data through this function call.
  • The object variable set by OptIntp::setParameter() with the enumerator OptIntp::GRID_SAMPLE influences the accuracy of this function's calculations.
  • The array pointer yErr may be set to null to exclude this information.
  • The number of pointers in the array yErr equals the number of dimensions of the interpolation object.
  • The number of values for each array pointer of yErr is one less than the number stored in the interpolation object's data counts by dimension array.
  • If the data count for a dimension is one, the interval error value in yErr for that dimension is the total table error.

bool optimize ( const xType *  xTol,
xType  yTol 
)

Function optimizes an n-Dimension independent interpolation array (calc::NIntp) by adjusting data point placement to minimize error.

Parameters:
xTol a pointer to an incremental tolerance array of independent data values (x units)
yTol incremental error tolerance of the dependent error values (|y| units)
Returns:
status flag
  • false (successful execution)
  • true (execution error)
Remarks:
  • The specified optimization tolerance array xTol must have values greater than zero.
  • The number of values in the array xTol equals the number of dimensions in the interpolation table to be analyzed.
  • The specified optimization tolerance value yTol must be greater than zero.
  • The yTol value is used to compare error tolerances between the basis function OptIntp::evalBasis() and the interpolation function OptIntp::evalTable(). Dependent delta errors less than this tolerance are set to 0.
  • This function is capable of displaying calculation progress text for especially long program executions. Progress of this function's calculations is displayed to the console depending on the state of the value returned by OptIntp::getPrintStatus().
  • The parameter set by OptIntp::setParameter() with the enumerator OptIntp::LOOP_MAXIMUM may influence this function's calculations.

bool optimize ( xType  xTol,
xType  yTol 
)

Function optimizes an n-Dimension independent interpolation array (calc::NIntp) by adjusting data point placement to minimize error.

Parameters:
xTol an incremental error tolerance of the independent data values (x units)
yTol incremental error tolerance of the dependent error values (|y| units)
Returns:
status flag
  • false (successful execution)
  • true (execution error)
Remarks:
  • The specified optimization tolerance value xTol must have values greater than zero.
  • The specified optimization tolerance value yTol must be greater than zero.
  • The yTol value is used to compare error tolerances between the basis function OptIntp::evalBasis() and the interpolation function OptIntp::evalTable(). Dependent delta errors less than this tolerance are set to 0.
  • This function is capable of displaying calculation progress text for especially long program executions. Progress of this function's calculations is displayed to the console depending on the state of the value returned by OptIntp::getPrintStatus().
  • The parameter set by OptIntp::setParameter() with the enumerator OptIntp::LOOP_MAXIMUM may influence this function's calculations.

bool randomError ( void   ) 

Function estimates the averaged error between the n-Dimension interpolation object and the error object's basis function through random point selection.

Returns:
status flag
  • false (successful execution)
  • true (execution error, calculations not made)
Remarks:

bool setBasis ( yType(&)(const xType *)  rFn  ) 

Function sets the specified function as the basis function for calculating interpolation errors.

Parameters:
rFn a reference to a function that supplies exact values for interpolation error calculations (y units)
Returns:
status flag
  • false (successful execution)
  • true (execution error, parameter not set)
Remarks:
  • The specified function rFn(vXn) calculates an exact value to interpolate given an independent variable vector vXn.
  • If the function rFn(vXn) can not calculate the dependent data point at a given independent data point, the function should throw an exception.
  • The function rFn(vXn) accepts a pointer vXn (x units) to an n-Dimension independent array.
  • The function rFn(vXn) returns a single value (y units) at the specified vector vXn.
  • rFn(vXn) declaration: yType fn(const xType *vXn);
  • This function calls calc::OptIntp::update() on implementation.

bool setParameter ( enum OptIntp< xType, yType >::PTYPE  pType,
int  param 
)

Function returns the indicated error method parameter for optimization interpolation object.

Parameters:
pType parameter index indentifying the type of data to store
param value to store
Returns:
status flag
  • false (successful execution)
  • true (execution error, parameter not set)
Remarks:

bool setPrintStatus ( bool  flag  ) 

Function sets the display status of progress printed to the primary console stream cout for selected function calculations.

Parameters:
flag status flag
  • false (calculation progress is not displayed)
  • true (calculation progress is displayed)
Returns:
status flag
  • false (successful execution)
  • true (execution error, parameter not set)
Remarks:
  • The overloaded function calc::OptIntp::randTest() is capable of displaying calculation progress for especially long program executions.
  • By default, progress of this function's calculations is not displayed to the console.

bool setSpanX ( bType **  arXn,
const bType *  arXLo,
const bType *  arXHi,
const int *  arNn,
int  nDimen 
) [static]

Function initializes an n-Dimension independent interpolation array at equally spaced intervals across the specified indepedent bounds.

Parameters:
arXLo a pointer to an n-Dimension independent value lower bound array (x units)
arXHi a pointer to an n-Dimension independent value upper bound array (x units)
arNn a pointer to an array containing data counts by dimension for the specified array arXn
nDimen number of dimensions of the interpolation table to analyze
arXn a pointer to a calculated n-Dimension independent value interpolation array (x units)
Returns:
status flag
  • false (successful execution)
  • true (execution error, parameters not set)
Remarks:
  • The declaration typename <bType> specifies the form of independent variables used in interpolation calculations.
  • All entries in the data counts by dimension array arNn must be greater than zero, and correspond to the point count of the independent interpolation array arXn.
  • The independent value upper and lower bound arrays arXLo and arXHi must have the same value count as the number of dimensions value nDimen and inherent in the arXn array.

bool setSpanX ( bType **  arXn,
bType  vXLo,
bType  vXHi,
const int *  arNn,
int  nDimen 
) [static]

Function initializes an n-Dimension independent interpolation array at equally spaced intervals across the specified indepedent bounds.

Parameters:
vXLo an independent value lower bound constant across dimensions (x units)
vXHi an independent value upper bound constant across dimensions (x units)
arNn a pointer to an array containing data counts by dimension for the specified array arXn
nDimen number of dimensions of the interpolation table to analyze
arXn a pointer to a calculated n-Dimension independent value interpolation array (x units)
Returns:
status flag
  • false (successful execution)
  • true (execution error, parameters not set)
Remarks:
  • The declaration typename <bType> specifies the form of independent variables used in interpolation calculations.
  • All entries in the data counts by dimension array arNn must be greater than zero, and correspond to the point count of the independent interpolation array arXn.

bool update ( const xType *const *  arXn = (xType**)(0),
const yType *  arYn = (yType*)(0) 
)

Function performs preparatory calculations for error analysis.

Parameters:
arXn a pointer to an n-Dimension independent value interpolation array (x units)
arYn a pointer to an n-Dimension dependent value interpolation array (y units)
Returns:
status flag
  • false (successful execution)
  • true (execution error, parameters not set)
Remarks:
This function should be called whenever interpolation parameters of the interpolation object change.


Member Data Documentation

const int DEF_GRID_SAMPLE = 1 [static]

default test point count per dimension used in error calculations through grid selection (OptIntp::gridError())

const int DEF_LOOP_MAX = 1000 [static]

default inital value used in optimization iterations (OptIntp::optimize())

const int DEF_RANDOM_COUNT = 2000 [static]

default total test point count used in error calculations through random selection (OptIntp::randomError())

const int DEF_RANDOM_SEED = 1 [static]

default inital value used in error calculations through random selection (OptIntp::randomError())


The documentation for this class was generated from the following files:
Generated on Wed Jul 19 09:24:20 2006 for CalcLib by  doxygen 1.4.7