#include <LinInterpolatedTableND.h>
Public Types | |
typedef Axis | axis_type |
typedef Numeric | value_type |
Public Member Functions | |
void | getCoords (unsigned long linearIndex, double *coords, unsigned coordsBufferSize) const |
template<class Functor1 , class Functor2 > | |
CPP11_auto_ptr < LinInterpolatedTableND > | invertRatioResponse (unsigned axisNumber, const Axis &replacementAxis, bool newAxisLeftLinear, bool newAxisRightLinear, Functor1 invg, Functor2 invh, const char *functionLabel=0) const |
template<typename ConvertibleToUnsigned > | |
CPP11_auto_ptr < LinInterpolatedTableND > | invertWRTAxis (ConvertibleToUnsigned axisNumber, const Axis &replacementAxis, bool newAxisLeftLinear, bool newAxisRightLinear, const char *functionLabel=0) const |
bool | isUniformlyBinned () const |
bool | isWithinLimits (const double *point, unsigned dim) const |
LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const char *functionLabel=0) | |
LinInterpolatedTableND (const std::vector< Axis > &axes, const std::vector< std::pair< bool, bool > > &extrapolationType, const char *functionLabel=0) | |
LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const char *functionLabel=0) | |
LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const Axis &tAxis, bool leftT, bool rightT, const char *functionLabel=0) | |
LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const char *functionLabel=0) | |
template<class Num2 > | |
LinInterpolatedTableND (const LinInterpolatedTableND< Num2, Axis > &) | |
LinInterpolatedTableND (const Axis &xAxis, bool leftX, bool rightX, const Axis &yAxis, bool leftY, bool rightY, const Axis &zAxis, bool leftZ, bool rightZ, const Axis &tAxis, bool leftT, bool rightT, const Axis &vAxis, bool leftV, bool rightV, const char *functionLabel=0) | |
bool | operator!= (const LinInterpolatedTableND &r) const |
Numeric | operator() (const double *point, unsigned dim) const |
bool | operator== (const LinInterpolatedTableND &) const |
void | setFunctionLabel (const char *newlabel) |
Numeric | operator() (const double &x0) const |
Numeric | operator() (const double &x0, const double &x1) const |
Numeric | operator() (const double &x0, const double &x1, const double &x2) const |
Numeric | operator() (const double &x0, const double &x1, const double &x2, const double &x3) const |
Numeric | operator() (const double &x0, const double &x1, const double &x2, const double &x3, const double &x4) const |
unsigned | dim () const |
const std::vector< Axis > & | axes () const |
const Axis & | axis (const unsigned i) const |
unsigned long | length () const |
bool | leftInterpolationLinear (unsigned i) const |
bool | rightInterpolationLinear (unsigned i) const |
std::vector< std::pair< bool, bool > > | interpolationType () const |
const std::string & | functionLabel () const |
const ArrayND< Numeric > & | table () const |
ArrayND< Numeric > & | table () |
gs::ClassId | classId () const |
bool | write (std::ostream &of) const |
Static Public Member Functions | |
static const char * | classname () |
static LinInterpolatedTableND * | read (const gs::ClassId &id, std::istream &in) |
static unsigned | version () |
Private Member Functions | |
bool | allConstInterpolated () const |
LinInterpolatedTableND () | |
LinInterpolatedTableND (const ArrayND< Numeric > &data, const std::vector< Axis > &axes, const char *leftInterpolation, const char *rightInterpolation, const std::string &label) | |
Static Private Member Functions | |
template<class Functor1 > | |
static void | invert1DResponse (const ArrayND< Numeric > &fromSlice, const Axis &fromAxis, const Axis &toAxis, bool newLeftLinear, bool newRightLinear, Functor1 invg, const double *rawx, const double *rawf, double *workspace, ArrayND< Numeric > *toSlice) |
template<class Functor1 > | |
static double | solveForRatioArg (double xmin, double xmax, double rmin, double rmax, double fval, Functor1 invg) |
Private Attributes | |
bool | allConstInterpolated_ |
std::vector< Axis > | axes_ |
ArrayND< Numeric > | data_ |
unsigned | dim_ |
std::string | functionLabel_ |
char | leftInterpolationLinear_ [CHAR_BIT *sizeof(unsigned long)] |
char | rightInterpolationLinear_ [CHAR_BIT *sizeof(unsigned long)] |
Friends | |
class | LinInterpolatedTableND |
Template for multilinear interpolation/extrapolation of values provided on a rectangular coordinate grid. "Numeric" is the type stored in the table. "Axis" should be one of GridAxis, UniformAxis, or DualAxis classes or a user-provided class with a similar set of methods.
Definition at line 31 of file LinInterpolatedTableND.h.
typedef Axis npstat::LinInterpolatedTableND< Numeric, Axis >::axis_type |
Definition at line 38 of file LinInterpolatedTableND.h.
typedef Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::value_type |
Definition at line 37 of file LinInterpolatedTableND.h.
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND | ( | const std::vector< Axis > & | axes, |
const std::vector< std::pair< bool, bool > > & | extrapolationType, | ||
const char * | functionLabel = 0 |
||
) |
Main constructor for arbitrary-dimensional interpolators.
"axes" are the axes of the rectangular coordinate grid.
In each pair provided by the "extrapolationType" argument, the first element of the pair specifies whether the extrapolation to negative infinity should be linear (if "true") or constant (if "false"). The second element of the pair specifies whether to extrapolate linearly to positive infinity.
"functionLabel" is an arbitrary string which can potentially be used by plotting programs and such.
Definition at line 566 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::interpolationType(), npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.
: data_(Private::makeTableShape(axes)), axes_(axes), functionLabel_(label ? label : ""), dim_(axes.size()) { if (dim_ == 0 || dim_ >= CHAR_BIT*sizeof(unsigned long)) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND constructor: requested " "table dimensionality is not supported"); if (dim_ != interpolationType.size()) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND constructor: " "incompatible number of interpolation specifications"); for (unsigned i=0; i<dim_; ++i) { const std::pair<bool,bool>& pair(interpolationType[i]); leftInterpolationLinear_[i] = pair.first; rightInterpolationLinear_[i] = pair.second; } allConstInterpolated_ = allConstInterpolated(); }
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND | ( | const Axis & | xAxis, |
bool | leftX, | ||
bool | rightX, | ||
const char * | functionLabel = 0 |
||
) |
Convenience constructor for 1-d interpolators
Definition at line 747 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.
: data_(Private::makeTableShape(xAxis)), functionLabel_(label ? label : ""), dim_(1U) { axes_.reserve(dim_); axes_.push_back(xAxis); leftInterpolationLinear_[0] = leftX; rightInterpolationLinear_[0] = rightX; allConstInterpolated_ = allConstInterpolated(); }
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND | ( | const Axis & | xAxis, |
bool | leftX, | ||
bool | rightX, | ||
const Axis & | yAxis, | ||
bool | leftY, | ||
bool | rightY, | ||
const char * | functionLabel = 0 |
||
) |
Convenience constructor for 2-d interpolators
Definition at line 724 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.
: data_(Private::makeTableShape(xAxis, yAxis)), functionLabel_(label ? label : ""), dim_(2U) { axes_.reserve(dim_); axes_.push_back(xAxis); axes_.push_back(yAxis); unsigned i = 0; leftInterpolationLinear_[i] = leftX; rightInterpolationLinear_[i++] = rightX; leftInterpolationLinear_[i] = leftY; rightInterpolationLinear_[i++] = rightY; assert(i == dim_); allConstInterpolated_ = allConstInterpolated(); }
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND | ( | const Axis & | xAxis, |
bool | leftX, | ||
bool | rightX, | ||
const Axis & | yAxis, | ||
bool | leftY, | ||
bool | rightY, | ||
const Axis & | zAxis, | ||
bool | leftZ, | ||
bool | rightZ, | ||
const char * | functionLabel = 0 |
||
) |
Convenience constructor for 3-d interpolators
Definition at line 697 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.
: data_(Private::makeTableShape(xAxis, yAxis, zAxis)), functionLabel_(label ? label : ""), dim_(3U) { axes_.reserve(dim_); axes_.push_back(xAxis); axes_.push_back(yAxis); axes_.push_back(zAxis); unsigned i = 0; leftInterpolationLinear_[i] = leftX; rightInterpolationLinear_[i++] = rightX; leftInterpolationLinear_[i] = leftY; rightInterpolationLinear_[i++] = rightY; leftInterpolationLinear_[i] = leftZ; rightInterpolationLinear_[i++] = rightZ; assert(i == dim_); allConstInterpolated_ = allConstInterpolated(); }
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND | ( | const Axis & | xAxis, |
bool | leftX, | ||
bool | rightX, | ||
const Axis & | yAxis, | ||
bool | leftY, | ||
bool | rightY, | ||
const Axis & | zAxis, | ||
bool | leftZ, | ||
bool | rightZ, | ||
const Axis & | tAxis, | ||
bool | leftT, | ||
bool | rightT, | ||
const char * | functionLabel = 0 |
||
) |
Convenience constructor for 4-d interpolators
Definition at line 666 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.
: data_(Private::makeTableShape(xAxis, yAxis, zAxis, tAxis)), functionLabel_(label ? label : ""), dim_(4U) { axes_.reserve(dim_); axes_.push_back(xAxis); axes_.push_back(yAxis); axes_.push_back(zAxis); axes_.push_back(tAxis); unsigned i = 0; leftInterpolationLinear_[i] = leftX; rightInterpolationLinear_[i++] = rightX; leftInterpolationLinear_[i] = leftY; rightInterpolationLinear_[i++] = rightY; leftInterpolationLinear_[i] = leftZ; rightInterpolationLinear_[i++] = rightZ; leftInterpolationLinear_[i] = leftT; rightInterpolationLinear_[i++] = rightT; assert(i == dim_); allConstInterpolated_ = allConstInterpolated(); }
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND | ( | const Axis & | xAxis, |
bool | leftX, | ||
bool | rightX, | ||
const Axis & | yAxis, | ||
bool | leftY, | ||
bool | rightY, | ||
const Axis & | zAxis, | ||
bool | leftZ, | ||
bool | rightZ, | ||
const Axis & | tAxis, | ||
bool | leftT, | ||
bool | rightT, | ||
const Axis & | vAxis, | ||
bool | leftV, | ||
bool | rightV, | ||
const char * | functionLabel = 0 |
||
) |
Convenience constructor for 5-d interpolators
Definition at line 631 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.
: data_(Private::makeTableShape(xAxis, yAxis, zAxis, tAxis, vAxis)), functionLabel_(label ? label : ""), dim_(5U) { axes_.reserve(dim_); axes_.push_back(xAxis); axes_.push_back(yAxis); axes_.push_back(zAxis); axes_.push_back(tAxis); axes_.push_back(vAxis); unsigned i = 0; leftInterpolationLinear_[i] = leftX; rightInterpolationLinear_[i++] = rightX; leftInterpolationLinear_[i] = leftY; rightInterpolationLinear_[i++] = rightY; leftInterpolationLinear_[i] = leftZ; rightInterpolationLinear_[i++] = rightZ; leftInterpolationLinear_[i] = leftT; rightInterpolationLinear_[i++] = rightT; leftInterpolationLinear_[i] = leftV; rightInterpolationLinear_[i++] = rightV; assert(i == dim_); allConstInterpolated_ = allConstInterpolated(); }
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND | ( | const LinInterpolatedTableND< Num2, Axis > & | r | ) |
Converting copy constructor from interpolator with another storage type
Definition at line 595 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND | ( | ) | [private] |
npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND | ( | const ArrayND< Numeric > & | data, |
const std::vector< Axis > & | axes, | ||
const char * | leftInterpolation, | ||
const char * | rightInterpolation, | ||
const std::string & | label | ||
) | [private] |
Definition at line 611 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated(), npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.
: data_(data), axes_(axes), functionLabel_(label), dim_(data.rank()) { for (unsigned i=0; i<dim_; ++i) { leftInterpolationLinear_[i] = leftInterpolation[i]; rightInterpolationLinear_[i] = rightInterpolation[i]; } allConstInterpolated_ = allConstInterpolated(); }
bool npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated | ( | ) | const [private] |
Definition at line 444 of file LinInterpolatedTableND.h.
References i.
Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND().
{ for (unsigned i=0; i<dim_; ++i) if (leftInterpolationLinear_[i] || rightInterpolationLinear_[i]) return false; return true; }
const std::vector<Axis>& npstat::LinInterpolatedTableND< Numeric, Axis >::axes | ( | ) | const [inline] |
Definition at line 118 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_.
{return axes_;}
const Axis& npstat::LinInterpolatedTableND< Numeric, Axis >::axis | ( | const unsigned | i | ) | const [inline] |
Definition at line 119 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_.
gs::ClassId npstat::LinInterpolatedTableND< Numeric, Axis >::classId | ( | ) | const [inline] |
Definition at line 205 of file LinInterpolatedTableND.h.
Referenced by npstat::StorableInterpolationFunctor< Numeric, Axis, Converter >::write().
{return gs::ClassId(*this);}
const char * npstat::LinInterpolatedTableND< Numeric, Axis >::classname | ( | ) | [static] |
Definition at line 471 of file LinInterpolatedTableND.h.
References AlCaHLTBitMon_QueryRunRegistry::string.
{ static const std::string myClass(gs::template_class_name<Numeric,Axis>( "npstat::LinInterpolatedTableND")); return myClass.c_str(); }
unsigned npstat::LinInterpolatedTableND< Numeric, Axis >::dim | ( | ) | const [inline] |
Examine interpolator contents
Definition at line 117 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::dim_.
Referenced by npstat::StorableInterpolationFunctor< Numeric, Axis, Converter >::minDim().
{return dim_;}
const std::string& npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel | ( | ) | const [inline] |
Definition at line 125 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel_.
{return functionLabel_;}
void npstat::LinInterpolatedTableND< Numeric, Axis >::getCoords | ( | unsigned long | linearIndex, |
double * | coords, | ||
unsigned | coordsBufferSize | ||
) | const |
Convenience function for getting coordinates of the grid points
Definition at line 920 of file LinInterpolatedTableND.h.
References i, and getHLTprescales::index.
{ if (coordsBufferSize < dim_) throw npstat::NpstatInvalidArgument( "In LinInterpolatedTableND::getCoords: " "insufficient buffer size"); assert(coords); unsigned index[CHAR_BIT*sizeof(unsigned long)]; data_.convertLinearIndex(linearIndex, index, dim_); for (unsigned i=0; i<dim_; ++i) coords[i] = axes_[i].coordinate(index[i]); }
std::vector< std::pair< bool, bool > > npstat::LinInterpolatedTableND< Numeric, Axis >::interpolationType | ( | ) | const |
Definition at line 555 of file LinInterpolatedTableND.h.
References i.
Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND().
{ std::vector<std::pair<bool,bool> > vec; vec.reserve(dim_); for (unsigned i=0; i<dim_; ++i) vec.push_back(std::pair<bool, bool>(leftInterpolationLinear_[i], rightInterpolationLinear_[i])); return vec; }
void npstat::LinInterpolatedTableND< Numeric, Axis >::invert1DResponse | ( | const ArrayND< Numeric > & | fromSlice, |
const Axis & | fromAxis, | ||
const Axis & | toAxis, | ||
bool | newLeftLinear, | ||
bool | newRightLinear, | ||
Functor1 | invg, | ||
const double * | rawx, | ||
const double * | rawf, | ||
double * | workspace, | ||
ArrayND< Numeric > * | toSlice | ||
) | [static, private] |
Definition at line 1168 of file LinInterpolatedTableND.h.
References npstat::ArrayND< Numeric, StackLen, StackDim >::data(), i, npstat::ArrayND< Numeric, StackLen, StackDim >::length(), npstat::ArrayND< Numeric, StackLen, StackDim >::rank(), x, detailsBasic3DVector::y, and zero.
{ assert(toSlice); assert(fromSlice.rank() == 1U); assert(toSlice->rank() == 1U); const Numeric zero = Numeric(); const Numeric* fromData = fromSlice.data(); const unsigned fromLen = fromSlice.length(); assert(fromLen > 1U); assert(fromLen == fromAxis.nCoords()); Numeric* toD = const_cast<Numeric*>(toSlice->data()); const unsigned nAxisPoints = toAxis.nCoords(); assert(toSlice->length() == nAxisPoints); for (unsigned i=0; i<fromLen; ++i) { if (fromData[i] <= zero) throw npstat::NpstatDomainError( "In LinInterpolatedTableND::invert1DResponse: " "non-positive response found. This ratio " "response table is not invertible."); workspace[i] = rawx[i]*fromData[i]; } const double yfirst = workspace[0]; const double ylast = workspace[fromLen - 1U]; bool adjustZero = false; unsigned nBelow = 0; for (unsigned ipt=0; ipt<nAxisPoints; ++ipt) { const double y = rawf[ipt]; unsigned i0 = 0; bool solve = false; if (y == 0.0) { assert(ipt == 0U); if (newLeftLinear) adjustZero = true; } else if (y <= yfirst) { ++nBelow; solve = newLeftLinear; } else if (y >= ylast) { solve = newRightLinear; i0 = solve ? fromLen-2 : fromLen-1; } else { solve = true; i0 = static_cast<unsigned>(std::lower_bound( workspace,workspace+fromLen,y) - workspace) - 1U; } if (solve) { const double x = solveForRatioArg(fromAxis.coordinate(i0), fromAxis.coordinate(i0+1), fromData[i0], fromData[i0+1], y, invg); toD[ipt] = invg(x)/y; } else toD[ipt] = 1.0/fromData[i0]; } if (adjustZero && nBelow) toD[0] = toD[1]; }
CPP11_auto_ptr< LinInterpolatedTableND< Numeric, Axis > > npstat::LinInterpolatedTableND< Numeric, Axis >::invertRatioResponse | ( | unsigned | axisNumber, |
const Axis & | replacementAxis, | ||
bool | newAxisLeftLinear, | ||
bool | newAxisRightLinear, | ||
Functor1 | invg, | ||
Functor2 | invh, | ||
const char * | functionLabel = 0 |
||
) | const |
This method inverts the ratio response. That is, we assume that the table encodes r(x) for some function f(x) = x*r(x). We also assume that the original axis does not represent x directly -- instead, axis coordinates are given by g(x) (in practice, g is often the natural log). We will also assume that the new axis is not going to represent f(x) directly -- it will be h(f(x)) instead. The functors "invg" and "invh" below must do the inverse: taking the axes coordinates to the actual values of x and f(x). Both "invg" and "invh" must be monotonously increasing functions. The code assumes that x*r(x) -> 0 when x->0 (that is, r(x) is bounded at 0) and it also assumes (but does not check explicitly) that x*r(x) is monotonously increasing with x.
The returned interpolation table encodes the values of x/f(x). Of course, they are just 1/r(x), but the trick is to be able to look them up quickly as a function of h(f(x)). Naturally, this whole operation is meaningful only in case "Numeric" type is either float or double.
Definition at line 827 of file LinInterpolatedTableND.h.
References prof2calltree::count, f, i, npstat::ArrayNDScanner::isValid(), and x.
{ if (axisNumber >= dim_) throw npstat::NpstatOutOfRange( "In npstat::LinInterpolatedTableND::invertRatioResponse: " "axis number is out of range"); // Generate the new set of axes std::vector<Axis> newAxes(axes_); newAxes[axisNumber] = replacementAxis; std::vector<std::pair<bool,bool> > iType(interpolationType()); iType[axisNumber] = std::pair<bool,bool>(leftLinear, rightLinear); // Transform the original axis to the raw x values const Axis& oldAxis(axes_[axisNumber]); std::vector<double> rawx; const unsigned nCoords = oldAxis.nCoords(); rawx.reserve(nCoords); for (unsigned i=0; i<nCoords; ++i) { const double x = invg(oldAxis.coordinate(i)); if (x < 0.0) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND::invertRatioResponse: " "invalid original axis definition (negative transformed " "coordinate)"); rawx.push_back(x); } // Transform the new axis to the raw f(x) values std::vector<double> rawf; const unsigned nFuncs = replacementAxis.nCoords(); rawf.reserve(nFuncs); for (unsigned i=0; i<nFuncs; ++i) { const double f = invh(replacementAxis.coordinate(i)); if (f < 0.0) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND::invertRatioResponse: " "invalid new axis definition (negative transformed " "coordinate)"); rawf.push_back(f); } // Workspace needed for the inversion code std::vector<double> workspace(nCoords); // Create the new table CPP11_auto_ptr<LinInterpolatedTableND> pTable( new LinInterpolatedTableND(newAxes, iType, functionLabel)); if (dim_ > 1U) { // Prepare array slices unsigned sliceIndex[CHAR_BIT*sizeof(unsigned long)]; unsigned fixedIndices[CHAR_BIT*sizeof(unsigned long)]; unsigned count = 0; for (unsigned i=0; i<dim_; ++i) if (i != axisNumber) { sliceIndex[count] = data_.span(i); fixedIndices[count++] = i; } ArrayND<Numeric> parentSlice(data_, fixedIndices, count); ArrayND<Numeric> dauSlice(pTable->data_, fixedIndices, count); // Cycle over the slices for (ArrayNDScanner scan(sliceIndex,count); scan.isValid(); ++scan) { scan.getIndex(sliceIndex, count); data_.exportSlice(&parentSlice, fixedIndices, sliceIndex, count); invert1DResponse(parentSlice, oldAxis, replacementAxis, leftLinear, rightLinear, invg, &rawx[0], &rawf[0], &workspace[0], &dauSlice); pTable->data_.importSlice(dauSlice, fixedIndices, sliceIndex, count); } } else invert1DResponse(data_, oldAxis, replacementAxis, leftLinear, rightLinear, invg, &rawx[0], &rawf[0], &workspace[0], &pTable->data_); return pTable; }
CPP11_auto_ptr< LinInterpolatedTableND< Numeric, Axis > > npstat::LinInterpolatedTableND< Numeric, Axis >::invertWRTAxis | ( | ConvertibleToUnsigned | axisNumber, |
const Axis & | replacementAxis, | ||
bool | newAxisLeftLinear, | ||
bool | newAxisRightLinear, | ||
const char * | functionLabel = 0 |
||
) | const |
Invert the function w.r.t. the variable represented by one of the axes. The function values must change monotonously along the chosen axis. Note that this operation is meaningful only in case "Numeric" type is either float or double.
Definition at line 766 of file LinInterpolatedTableND.h.
References prof2calltree::count, i, npstat::ArrayNDScanner::isValid(), and npstat::Private::lind_invert1DSlice().
{ const unsigned axisNumber = static_cast<unsigned>(axisNumC); if (axisNumber >= dim_) throw npstat::NpstatOutOfRange( "In npstat::LinInterpolatedTableND::invertAxis: " "axis number is out of range"); // Generate the new set of axes std::vector<Axis> newAxes(axes_); newAxes[axisNumber] = replacementAxis; std::vector<std::pair<bool,bool> > iType(interpolationType()); iType[axisNumber] = std::pair<bool,bool>(leftLinear, rightLinear); // Create the new table CPP11_auto_ptr<LinInterpolatedTableND> pTable( new LinInterpolatedTableND(newAxes, iType, functionLabel)); if (dim_ > 1U) { // Prepare array slices unsigned sliceIndex[CHAR_BIT*sizeof(unsigned long)]; unsigned fixedIndices[CHAR_BIT*sizeof(unsigned long)]; unsigned count = 0; for (unsigned i=0; i<dim_; ++i) if (i != axisNumber) { sliceIndex[count] = data_.span(i); fixedIndices[count++] = i; } ArrayND<Numeric> parentSlice(data_, fixedIndices, count); ArrayND<Numeric> dauSlice(pTable->data_, fixedIndices, count); // Cycle over the slices for (ArrayNDScanner scan(sliceIndex,count); scan.isValid(); ++scan) { scan.getIndex(sliceIndex, count); data_.exportSlice(&parentSlice, fixedIndices, sliceIndex, count); Private::lind_invert1DSlice( parentSlice, axes_[axisNumber], replacementAxis, leftLinear, rightLinear, &dauSlice); pTable->data_.importSlice(dauSlice, fixedIndices, sliceIndex, count); } } else Private::lind_invert1DSlice( data_, axes_[0], replacementAxis, leftLinear, rightLinear, &pTable->data_); return pTable; }
bool npstat::LinInterpolatedTableND< Numeric, Axis >::isUniformlyBinned | ( | ) | const |
bool npstat::LinInterpolatedTableND< Numeric, Axis >::isWithinLimits | ( | const double * | point, |
unsigned | dim | ||
) | const |
This method will return "true" if the point is inside the grid limits or on the boundary
Definition at line 935 of file LinInterpolatedTableND.h.
bool npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear | ( | unsigned | i | ) | const |
Definition at line 525 of file LinInterpolatedTableND.h.
References i.
{ if (i >= dim_) throw npstat::NpstatOutOfRange( "In npstat::LinInterpolatedTableND::leftInterpolationLinear: " "index out of range"); return leftInterpolationLinear_[i]; }
unsigned long npstat::LinInterpolatedTableND< Numeric, Axis >::length | ( | ) | const [inline] |
Definition at line 121 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::data_, and npstat::ArrayND< Numeric, StackLen, StackDim >::length().
{return data_.length();}
bool npstat::LinInterpolatedTableND< Numeric, Axis >::operator!= | ( | const LinInterpolatedTableND< Numeric, Axis > & | r | ) | const [inline] |
Logical negation of operator==
Definition at line 200 of file LinInterpolatedTableND.h.
References alignCSCRings::r.
{return !(*this == r);}
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() | ( | const double & | x0, |
const double & | x1, | ||
const double & | x2 | ||
) | const |
Definition at line 1057 of file LinInterpolatedTableND.h.
References tmp.
{ const unsigned nArgs = 3U; if (dim_ != nArgs) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND::operator(): number of " "arguments, 3, is incompatible with the interpolator dimensionality"); double tmp[nArgs]; tmp[0] = x0; tmp[1] = x1; tmp[2] = x2; return operator()(tmp, nArgs); }
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() | ( | const double & | x0 | ) | const |
Convenience function for low-dimensional interpolators
Definition at line 1030 of file LinInterpolatedTableND.h.
References tmp.
{ const unsigned nArgs = 1U; if (dim_ != nArgs) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND::operator(): number of " "arguments, 1, is incompatible with the interpolator dimensionality"); double tmp[nArgs]; tmp[0] = x0; return operator()(tmp, nArgs); }
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() | ( | const double & | x0, |
const double & | x1, | ||
const double & | x2, | ||
const double & | x3 | ||
) | const |
Definition at line 1072 of file LinInterpolatedTableND.h.
References tmp.
{ const unsigned nArgs = 4U; if (dim_ != nArgs) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND::operator(): number of " "arguments, 4, is incompatible with the interpolator dimensionality"); double tmp[nArgs]; tmp[0] = x0; tmp[1] = x1; tmp[2] = x2; tmp[3] = x3; return operator()(tmp, nArgs); }
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() | ( | const double * | point, |
unsigned | dim | ||
) | const |
Basic interpolation result. Argument point dimensionality must be compatible with the interpolator dimensionality.
Definition at line 951 of file LinInterpolatedTableND.h.
References i, max(), min, w(), and histoStyle::weight.
{ typedef typename ProperDblFromCmpl<Numeric>::type proper_double; if (len != dim_) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND::operator(): " "incompatible point dimensionality"); assert(point); bool interpolateArray = true; if (!allConstInterpolated_) for (unsigned i=0; i<dim_; ++i) if ((leftInterpolationLinear_[i] && point[i] < axes_[i].min()) || (rightInterpolationLinear_[i] && point[i] > axes_[i].max())) { interpolateArray = false; break; } if (interpolateArray) { // Translate coordinates into the array system and // simply use the ArrayND interpolation facilities double buf[CHAR_BIT*sizeof(unsigned long)]; for (unsigned i=0; i<dim_; ++i) { const std::pair<unsigned,double>& pair = axes_[i].getInterval(point[i]); buf[i] = pair.first + 1U - pair.second; } return data_.interpolate1(buf, dim_); } else { unsigned ix[CHAR_BIT*sizeof(unsigned long)]; double weight[CHAR_BIT*sizeof(unsigned long)]; for (unsigned i=0; i<dim_; ++i) { const bool linear = (leftInterpolationLinear_[i] && point[i] < axes_[i].min()) || (rightInterpolationLinear_[i] && point[i] > axes_[i].max()); const std::pair<unsigned,double>& pair = linear ? axes_[i].linearInterval(point[i]) : axes_[i].getInterval(point[i]); ix[i] = pair.first; weight[i] = pair.second; } Numeric sum = Numeric(); const unsigned long maxcycle = 1UL << dim_; const unsigned long* strides = data_.strides(); const Numeric* dat = data_.data(); for (unsigned long icycle=0UL; icycle<maxcycle; ++icycle) { double w = 1.0; unsigned long icell = 0UL; for (unsigned i=0; i<dim_; ++i) { if (icycle & (1UL << i)) { w *= (1.0 - weight[i]); icell += strides[i]*(ix[i] + 1U); } else { w *= weight[i]; icell += strides[i]*ix[i]; } } sum += dat[icell]*static_cast<proper_double>(w); } return sum; } }
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() | ( | const double & | x0, |
const double & | x1, | ||
const double & | x2, | ||
const double & | x3, | ||
const double & | x4 | ||
) | const |
Definition at line 1089 of file LinInterpolatedTableND.h.
References tmp.
{ const unsigned nArgs = 5U; if (dim_ != nArgs) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND::operator(): number of " "arguments, 5, is incompatible with the interpolator dimensionality"); double tmp[nArgs]; tmp[0] = x0; tmp[1] = x1; tmp[2] = x2; tmp[3] = x3; tmp[4] = x4; return operator()(tmp, nArgs); }
Numeric npstat::LinInterpolatedTableND< Numeric, Axis >::operator() | ( | const double & | x0, |
const double & | x1 | ||
) | const |
Definition at line 1043 of file LinInterpolatedTableND.h.
References tmp.
{ const unsigned nArgs = 2U; if (dim_ != nArgs) throw npstat::NpstatInvalidArgument( "In npstat::LinInterpolatedTableND::operator(): number of " "arguments, 2, is incompatible with the interpolator dimensionality"); double tmp[nArgs]; tmp[0] = x0; tmp[1] = x1; return operator()(tmp, nArgs); }
bool npstat::LinInterpolatedTableND< Numeric, Axis >::operator== | ( | const LinInterpolatedTableND< Numeric, Axis > & | r | ) | const |
Comparison for equality
Definition at line 453 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::axes_, npstat::LinInterpolatedTableND< Numeric, Axis >::data_, npstat::LinInterpolatedTableND< Numeric, Axis >::dim_, npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel_, i, npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_, and npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_.
{ if (dim_ != r.dim_) return false; for (unsigned i=0; i<dim_; ++i) { if (leftInterpolationLinear_[i] != r.leftInterpolationLinear_[i]) return false; if (rightInterpolationLinear_[i] != r.rightInterpolationLinear_[i]) return false; } return data_ == r.data_ && axes_ == r.axes_ && functionLabel_ == r.functionLabel_; }
LinInterpolatedTableND< Numeric, Axis > * npstat::LinInterpolatedTableND< Numeric, Axis >::read | ( | const gs::ClassId & | id, |
std::istream & | in | ||
) | [static] |
Definition at line 495 of file LinInterpolatedTableND.h.
References cond::rpcobimon::current, data, diffTwoXMLs::label, npstat::ArrayND< Numeric, StackLen, StackDim >::rank(), npstat::ArrayND< Numeric, StackLen, StackDim >::restore(), and AlCaHLTBitMon_QueryRunRegistry::string.
{ static const gs::ClassId current( gs::ClassId::makeId<LinInterpolatedTableND<Numeric,Axis> >()); current.ensureSameId(id); gs::ClassId ida(in, 1); ArrayND<Numeric> data; ArrayND<Numeric>::restore(ida, in, &data); std::vector<Axis> axes; gs::read_heap_obj_vector_as_placed(in, &axes); const unsigned dim = axes.size(); if (dim > CHAR_BIT*sizeof(unsigned long) || data.rank() != dim) throw gs::IOInvalidData( "In npstat::LinInterpolatedTableND::read: " "read back invalid dimensionality"); char leftInterpolation[CHAR_BIT*sizeof(unsigned long)]; gs::read_pod_array(in, leftInterpolation, dim); char rightInterpolation[CHAR_BIT*sizeof(unsigned long)]; gs::read_pod_array(in, rightInterpolation, dim); std::string label; gs::read_pod(in, &label); if (in.fail()) throw gs::IOReadFailure( "In npstat::LinInterpolatedTableND::read: input stream failure"); return new LinInterpolatedTableND( data, axes, leftInterpolation, rightInterpolation, label); }
bool npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear | ( | unsigned | i | ) | const |
Definition at line 535 of file LinInterpolatedTableND.h.
References i.
{ if (i >= dim_) throw npstat::NpstatOutOfRange( "In npstat::LinInterpolatedTableND::rightInterpolationLinear: " "index out of range"); return rightInterpolationLinear_[i]; }
void npstat::LinInterpolatedTableND< Numeric, Axis >::setFunctionLabel | ( | const char * | newlabel | ) | [inline] |
Modifier for the function label
Definition at line 152 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel_.
{functionLabel_ = newlabel ? newlabel : "";}
double npstat::LinInterpolatedTableND< Numeric, Axis >::solveForRatioArg | ( | double | xmin, |
double | xmax, | ||
double | rmin, | ||
double | rmax, | ||
double | fval, | ||
Functor1 | invg | ||
) | [static, private] |
Definition at line 1108 of file LinInterpolatedTableND.h.
References abs, npstat::Private::lind_interpolateSimple(), relval_parameters_module::step, SiStripMonitorClusterAlca_cfi::xmax, and SiStripMonitorClusterAlca_cfi::xmin.
{ // Find two values of x so that f(x0) <= fval <= f(x1) double x0 = xmin; double x1 = xmax; double fmin = invg(xmin)*rmin; double fmax = invg(xmax)*rmax; const double step = xmax - xmin; assert(fmin < fmax); assert(step > 0.0); unsigned stepcount = 0; const unsigned maxSteps = 1000U; for (double stepfactor = 1.0; (fval < fmin || fval > fmax) && stepcount < maxSteps; stepfactor *= 2.0, ++stepcount) if (fval < fmin) { x1 = x0; fmax = fmin; x0 -= stepfactor*step; fmin = invg(x0)*Private::lind_interpolateSimple( xmin, xmax, rmin, rmax, x0); } else { x0 = x1; fmin = fmax; x1 += stepfactor*step; fmax = invg(x1)*Private::lind_interpolateSimple( xmin, xmax, rmin, rmax, x1); } if (stepcount == maxSteps) throw npstat::NpstatRuntimeError( "In LinInterpolatedTableND::solveForRatioArg: " "faled to bracket the root"); assert(x1 >= x0); while ((x1 - x0)/(std::abs(x1) + std::abs(x0) + DBL_EPSILON) > 4.0*DBL_EPSILON) { const double xhalf = (x1 + x0)/2.0; const double fhalf = invg(xhalf)*Private::lind_interpolateSimple( xmin, xmax, rmin, rmax, xhalf); if (fval < fhalf) { x1 = xhalf; fmax = fhalf; } else { x0 = xhalf; fmin = fhalf; } } return (x1 + x0)/2.0; }
ArrayND<Numeric>& npstat::LinInterpolatedTableND< Numeric, Axis >::table | ( | ) | [inline] |
Definition at line 132 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::data_.
{return data_;}
const ArrayND<Numeric>& npstat::LinInterpolatedTableND< Numeric, Axis >::table | ( | ) | const [inline] |
Access the interpolator table data
Definition at line 131 of file LinInterpolatedTableND.h.
References npstat::LinInterpolatedTableND< Numeric, Axis >::data_.
Referenced by npstat::StorableInterpolationFunctor< Numeric, Axis, Converter >::table().
{return data_;}
static unsigned npstat::LinInterpolatedTableND< Numeric, Axis >::version | ( | ) | [inline, static] |
Definition at line 210 of file LinInterpolatedTableND.h.
{return 1;}
bool npstat::LinInterpolatedTableND< Numeric, Axis >::write | ( | std::ostream & | of | ) | const |
Definition at line 479 of file LinInterpolatedTableND.h.
References ntuplemaker::status.
Referenced by npstat::StorableInterpolationFunctor< Numeric, Axis, Converter >::write().
{ const bool status = data_.classId().write(of) && data_.write(of) && gs::write_obj_vector(of, axes_); if (status) { gs::write_pod_array(of, leftInterpolationLinear_, dim_); gs::write_pod_array(of, rightInterpolationLinear_, dim_); gs::write_pod(of, functionLabel_); } return status && !of.fail(); }
friend class LinInterpolatedTableND [friend] |
Definition at line 34 of file LinInterpolatedTableND.h.
bool npstat::LinInterpolatedTableND< Numeric, Axis >::allConstInterpolated_ [private] |
Definition at line 232 of file LinInterpolatedTableND.h.
Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND().
std::vector<Axis> npstat::LinInterpolatedTableND< Numeric, Axis >::axes_ [private] |
Definition at line 227 of file LinInterpolatedTableND.h.
Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::axes(), npstat::LinInterpolatedTableND< Numeric, Axis >::axis(), npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND(), and npstat::LinInterpolatedTableND< Numeric, Axis >::operator==().
ArrayND<Numeric> npstat::LinInterpolatedTableND< Numeric, Axis >::data_ [private] |
Definition at line 226 of file LinInterpolatedTableND.h.
Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::length(), npstat::LinInterpolatedTableND< Numeric, Axis >::operator==(), and npstat::LinInterpolatedTableND< Numeric, Axis >::table().
unsigned npstat::LinInterpolatedTableND< Numeric, Axis >::dim_ [private] |
std::string npstat::LinInterpolatedTableND< Numeric, Axis >::functionLabel_ [private] |
char npstat::LinInterpolatedTableND< Numeric, Axis >::leftInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)] [private] |
Definition at line 229 of file LinInterpolatedTableND.h.
Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND(), and npstat::LinInterpolatedTableND< Numeric, Axis >::operator==().
char npstat::LinInterpolatedTableND< Numeric, Axis >::rightInterpolationLinear_[CHAR_BIT *sizeof(unsigned long)] [private] |
Definition at line 230 of file LinInterpolatedTableND.h.
Referenced by npstat::LinInterpolatedTableND< Numeric, Axis >::LinInterpolatedTableND(), and npstat::LinInterpolatedTableND< Numeric, Axis >::operator==().