|
| ChebyMap (ConstArray2D const &coeff_f, ConstArray2D const &coeff_i, std::vector< double > const &lbnd_f, std::vector< double > const &ubnd_f, std::vector< double > const &lbnd_i, std::vector< double > const &ubnd_i, std::string const &options="") |
| Construct a ChebyMap with a specified forward and/or inverse transforms.
|
|
| ChebyMap (ConstArray2D const &coeff_f, int nout, std::vector< double > const &lbnd_f, std::vector< double > const &ubnd_f, std::string const &options="IterInverse=0") |
| Construct a ChebyMap with only the forward transform specified.
|
|
virtual | ~ChebyMap () |
|
| ChebyMap (ChebyMap const &)=default |
| Copy constructor: make a deep copy.
|
|
| ChebyMap (ChebyMap &&)=default |
|
ChebyMap & | operator= (ChebyMap const &)=delete |
|
ChebyMap & | operator= (ChebyMap &&)=default |
|
std::shared_ptr< ChebyMap > | copy () const |
| Return a deep copy of this object.
|
|
ChebyDomain | getDomain (bool forward) const |
| Return the bounding box of the domain of a ChebyMap.
|
|
ChebyMap | polyTran (bool forward, double acc, double maxacc, int maxorder, std::vector< double > const &lbnd, std::vector< double > const &ubnd) const |
| This function creates a new ChebyMap which is a copy of this one, in which a specified transformation (forward or inverse) has been replaced by a new Chebyshev polynomial transformation.
|
|
ChebyMap | polyTran (bool forward, double acc, double maxacc, int maxorder) const |
| This method is the same as polyTran except that the bounds are those originally provided when the polynomial whose inverse is being fit was specified.
|
|
int | getNIn () const |
| Get NIn: the number of input axes.
|
|
int | getNOut () const |
| Get NOut: the number of output axes.
|
|
bool | getIsSimple () const |
| Get IsSimple: has the mapping been simplified?
|
|
bool | isInverted () const |
| Is this an inverted mapping?
|
|
bool | getIsLinear () const |
| Get IsLinear: is the Mapping linear?
|
|
bool | getReport () const |
| Get Report: report transformed coordinates to stdout?
|
|
bool | hasForward () const |
| Is the forward transform available?
|
|
bool | hasInverse () const |
| Is the inverse transform available?
|
|
std::shared_ptr< Mapping > | inverted () const |
| Get an inverse mapping.
|
|
Array2D | linearApprox (PointD const &lbnd, PointD const &ubnd, double tol) const |
| Compute a linear approximation to the forward transformation.
|
|
SeriesMap | then (Mapping const &next) const |
| Return a series compound mapping this(first(input)) containing shallow copies of the original.
|
|
ParallelMap | under (Mapping const &next) const |
| Return a parallel compound mapping containing shallow copies of the original.
|
|
double | rate (PointD const &at, int ax1, int ax2) const |
| Evaluate the rate of change of the Mapping with respect to a specified input, at a specified position.
|
|
void | setReport (bool report) |
| Set Report: report transformed coordinates to stdout?
|
|
std::shared_ptr< Mapping > | simplified () const |
| Return a simplied version of the mapping (which may be a compound Mapping such as a CmpMap).
|
|
void | applyForward (ConstArray2D const &from, Array2D const &to) const |
| Perform a forward transformation on 2-D array, putting the results into a pre-allocated 2-D array.
|
|
Array2D | applyForward (ConstArray2D const &from) const |
| Perform a forward transformation on a 2-D array, returning the results as a new array.
|
|
std::vector< double > | applyForward (std::vector< double > const &from) const |
| Perform a forward transformation on a vector, returning the results as a new vector.
|
|
void | applyInverse (ConstArray2D const &from, Array2D const &to) const |
| Perform an inverse transformation on a 2-D array, putting the results into a pre-allocated 2-D array.
|
|
Array2D | applyInverse (ConstArray2D const &from) const |
| Perform an inverse transformation on a 2-D array, returning the results as a new 2-D array.
|
|
std::vector< double > | applyInverse (std::vector< double > const &from) const |
| Perform an inverse transformation on a vector, returning the results as a new vector.
|
|
void | tranGridForward (PointI const &lbnd, PointI const &ubnd, double tol, int maxpix, Array2D const &to) const |
| Transform a grid of points in the forward direction.
|
|
Array2D | tranGridForward (PointI const &lbnd, PointI const &ubnd, double tol, int maxpix, int nPts) const |
| Transform a grid of points in the inverse direction, returning the results as a new Array2D.
|
|
void | tranGridInverse (PointI const &lbnd, PointI const &ubnd, double tol, int maxpix, Array2D const &to) const |
| Transform a grid of points in the inverse direction.
|
|
Array2D | tranGridInverse (PointI const &lbnd, PointI const &ubnd, double tol, int maxpix, int nPts) const |
| Transform a grid of points in the inverse direction.
|
|
bool | operator== (Object const &rhs) const |
| Return True if this and rhs are the equal.
|
|
bool | operator!= (Object const &rhs) const |
| Return True if this and rhs are not equal.
|
|
void | clear (std::string const &attrib) |
| Clear the values of a specified set of attributes for an Object.
|
|
bool | hasAttribute (std::string const &attrib) const |
| Does this object have an attribute with the specified name?
|
|
std::string | getClassName () const |
| Get Class: the name of the class (e.g.
|
|
std::string | getID () const |
| Get ID: object identification string that is not copied.
|
|
std::string | getIdent () const |
| Get Ident: object identification string that is copied.
|
|
int | getNObject () const |
| Get NObject: number of AST objects in existence of the same type as the underlying AST class.
|
|
int | getObjSize () const |
| Get ObjSize: the in-memory size of the AST object in bytes.
|
|
int | getRefCount () const |
| Get RefCount: number of active pointers to the underlying AST object.
|
|
bool | getUseDefs () const |
| Get UseDefs: allow use of default values for Object attributes?
|
|
void | lock (bool wait) |
| Lock this object for exclusive use by the calling thread.
|
|
bool | same (Object const &other) const |
| Does this contain the same AST object as another?
|
|
void | setID (std::string const &id) |
| Set ID: object identification string that is not copied.
|
|
void | setIdent (std::string const &ident) |
| Set Ident: object identification string that is copied.
|
|
void | setUseDefs (bool usedefs) |
| Set UseDefs: allow use of default values for Object attributes?
|
|
void | show (std::ostream &os, bool showComments=true) const |
| Print a textual description the object to an ostream.
|
|
std::string | show (bool showComments=true) const |
| Return a textual description the object as a string.
|
|
bool | test (std::string const &attrib) const |
| Has this attribute been explicitly set (and not subsequently cleared)?
|
|
void | unlock (bool report=false) |
| Unlock this object previously locked using lock, so that other threads can use this object.
|
|
|
AstObject const * | getRawPtr () const |
| Get the raw AST pointer.
|
|
AstObject * | getRawPtr () |
| Get the raw AST pointer.
|
|
|
virtual std::shared_ptr< Object > | copyPolymorphic () const override |
| Return a deep copy of this object.
|
|
| ChebyMap (AstChebyMap *map) |
| Construct a ChebyMap from an raw AST pointer.
|
|
template<typename Class > |
std::shared_ptr< Class > | decompose (int i, bool copy) const |
| Return a deep copy of one of the two component mappings.
|
|
template<typename T , typename AstT > |
std::shared_ptr< T > | copyImpl () const |
| Implementation of deep copy.
|
|
bool | getB (std::string const &attrib) const |
| Get the value of an attribute as a bool.
|
|
std::string const | getC (std::string const &attrib) const |
| Get the value of an attribute as a string.
|
|
double | getD (std::string const &attrib) const |
| Get the value of an attribute as a double.
|
|
float | getF (std::string const &attrib) const |
| Get the value of an attribute as a float.
|
|
int | getI (std::string const &attrib) const |
| Get the value of an attribute as an int.
|
|
long int | getL (std::string const &attrib) const |
| Get the value of an attribute as a long int.
|
|
void | set (std::string const &setting) |
| Assign a set of attribute values, over-riding any previous values.
|
|
void | setB (std::string const &attrib, bool value) |
| Set the value of an attribute as a bool.
|
|
void | setC (std::string const &attrib, std::string const &value) |
| Set the value of an attribute as a string.
|
|
void | setD (std::string const &attrib, double value) |
| Set the value of an attribute as a double.
|
|
void | setF (std::string const &attrib, float value) |
| Set the value of an attribute as a float.
|
|
void | setI (std::string const &attrib, int value) |
| Set the value of an attribute as an int.
|
|
void | setL (std::string const &attrib, long int value) |
| Set the value of an attribute as a long int.
|
|
A ChebyMap is a form of Mapping which performs a Chebyshev polynomial transformation.
Each output coordinate is a linear combination of Chebyshev polynomials of the first kind, of order zero up to a specified maximum order, evaluated at the input coordinates. The coefficients to be used in the linear combination are specified separately for each output coordinate.
For a 1-dimensional ChebyMap, the forward transformation is defined as follows:
f(x) = c0 T0(x') + c1 T1(x') + c2 T2(x') + ...
where:
- Tn(x') is the nth Chebyshev polynomial of the first kind:
- T0(x') = 1
- T1(x') = x'
- Tn+1(x') = 2.x'.Tn(x') + Tn-1(x')
- x' is the inpux axis value, x, offset and scaled to the range [-1, 1] as x ranges over a specified bounding box, given when the ChebyMap is created. The input positions, x, supplied to the forward transformation must fall within the bounding box - nans are generated for points outside the bounding box.
For an N-dimensional ChebyMap, the forward transformation is a generalisation of the above form. Each output axis value is the sum of ncoeff
terms, where each term is the product of a single coefficient value and N factors of the form ‘Tn(x’_i), where
x'_i` is the normalised value of the i'th input axis value.
The forward and inverse transformations are defined independantly by separate sets of coefficients, supplied when the ChebyMap is created. If no coefficients are supplied to define the inverse transformation, the polyTran method can instead be used to create an inverse transformation. The inverse transformation so generated will be a Chebyshev polynomial with coefficients chosen to minimise the residuals left by a round trip (forward transformation followed by inverse transformation).
Attributes
All those of Mapping. In addition, the forward and inverse bounds can be retrieved using getDomain
Strictly speaking, ChebyMap it has all the attributes of PolyMap, but the only attributes PolyMap adds to Mapping are iterative inverse parameters and those are ignored by ChebyMap because it does not (yet) support an iterative inverse.
Definition at line 97 of file ChebyMap.h.
Construct a ChebyMap with a specified forward and/or inverse transforms.
The two sets of coefficients are independent of each other: the inverse transform need not undo the forward transform.
- Parameters
-
[in] | coeff_f | A matrix of coefficients describing the forward transformation. If coeff_f is empty then no forward transformation is provided. |
[in] | coeff_i | A matrix of coefficients describing the inverse transformation. If coeff_i is empty then no inverse transformation is provided, unless you specify suitable options to request an iterative inverse; see the other constructor for details. |
[in] | lbnd_f | Lower bounds for input data; one element per input axis |
[in] | ubnd_f | Upper bounds for input data; one element per input axis |
[in] | lbnd_i | Lower bounds for output data; one element per output axis |
[in] | ubnd_i | Upper bounds for output data; one element per output axis |
[in] | options | Comma-separated list of attribute assignments. |
If a transform is not specified then the corresponding bounds are ignored (not even length-checked) and can be empty. For example if coeff_f
is empty then lbnd_f
and ubnd_f
are ignored.
- Exceptions
-
std::invalid_argument | if neither transform is specified (coeff_f and coeff_i are both empty). |
std::invalid_argument | if the forward transform is specified (coeff_f is not empty) and lbnd_f or ubnd_f do not have nin elements. |
std::invalid_argument | if the inverse transform is specified (coeff_i is not empty) and lbnd_i or ubnd_i do not have nout elements. |
Coefficient Matrices
The coefficients describing a forward transformation are specified as 2-dimensional ndarray, with one row per coefficient. Each row contains the following consecutive (2 + nin)
values:
- The first element is the coefficient value.
- The next element is the integer index of the ChebyMap output which uses the coefficient within its defining polynomial (the first output has index 1).
- The remaining elements give the Chebyshev order to use with each corresponding input coordinate value, or 0 to ignore that input coordinate. Powers must not be negative and floating point values are rounded to the nearest integer.
For example, suppose you want to make a ChebyMap with 3 inputs and 2 outputs. Then each row of coeff_f
must have 5 = 2 + nin elements. A row with values (1.2, 2, 6, 3, 0)
describes a coefficient that increments output 2 as follows:
`out2 += 1.2 * T6(in1') * T3(in2') * T0(in3')`
and a row with values (-1.5, 1, 0, 0, 0)
describes a coefficient that increments output 1 with a constant value of -1.5 (since all powers are 0):
`out1 += -1.5 * T0(in1') * T0(in2') * T0(in3')`
where inI' is the normalized value of input axis I.
The final value of each output coordinate is the sum of all values specified by coefficients which increment that output coordinate, or 0 if there are no such coefficients.
The coefficients describing the inverse transformation work the same way, of course, but each coefficient is described by (2 + nout)
values.
Definition at line 161 of file ChebyMap.h.
ChebyMap ast::ChebyMap::polyTran |
( |
bool | forward, |
|
|
double | acc, |
|
|
double | maxacc, |
|
|
int | maxorder, |
|
|
std::vector< double > const & | lbnd, |
|
|
std::vector< double > const & | ubnd ) const |
This function creates a new ChebyMap which is a copy of this one, in which a specified transformation (forward or inverse) has been replaced by a new Chebyshev polynomial transformation.
The coefficients of the new transformation are estimated by sampling the other transformation and performing a least squares polynomial fit in the opposite direction to the sampled positions and values.
This method can only be used on (1-input,1-output) or (2-input, 2-output) ChebyMaps.
- Parameters
-
[in] | forward | If true the forward transformation is replaced. Otherwise the inverse transformation is replaced. |
[in] | acc | The target accuracy, expressed as a geodesic distance within the ChebyMap's input space (if forward is false) or output space (if forward is true). |
[in] | maxacc | The maximum allowed accuracy for an acceptable polynomial, expressed as a geodesic distance within the ChebyMap's input space (if forward is false) or output space (if forward is true). |
[in] | maxorder | The maximum allowed polynomial order. This is one more than the maximum power of either input axis. So for instance, a value of 3 refers to a quadratic polynomial. Note, cross terms with total powers greater than or equal to maxorder are not inlcuded in the fit. So the maximum number of terms in each of the fitted polynomials is maxorder*(maxorder + 1)/2. |
[in] | lbnd | A vector holding the lower bounds of a rectangular region within the ChebyMap's input space (if forward is false) or output space (if forward is true). If both lbnd and ubnd are empty (the default) then they will be estimated. The new polynomial will be evaluated over this rectangle. The length should equal getNIn() or getNOut(), depending on forward . |
[in] | ubnd | A vector holding the upper bounds of a rectangular region within the ChebyMap's input space (if forward is false) or output space (if forward is true). If both lbnd and ubnd are empty (the default) then they will be estimated. The new polynomial will be evaluated over this rectangle. The length should equal getNIn() or getNOut(), depending on forward . |
- Exceptions
-
The variant that takes omits the lbnd
and ubnd
arguments uses the full domain of the polynomial whose inverse is being fit.
- Note
The transformation to create is specified by the forward
parameter. In what follows "X" refers to the inputs of the ChebyMap, and "Y" to the outputs of the ChebyMap. The forward transformation transforms input values (X) into output values (Y), and the inverse transformation transforms output values (Y) into input values (X). Within a ChebyMap, each transformation is represented by an independent set of polynomials, P_f or P_i: Y=P_f(X) for the forward transformation and X=P_i(Y) for the inverse transformation.
The forward
parameter specifies the transformation to be replaced. If it is true, a new forward transformation is created by first finding the input values (X) using the inverse transformation (which must be available) at a regular grid of points (Y) covering a rectangular region of the ChebyMap's output space. The coefficients of the required forward polynomial, Y=P_f(X), are chosen in order to minimise the sum of the squared residuals between the sampled values of Y and P_f(X).
If forward
is false (probably the most likely case), a new inverse transformation is created by first finding the output values (Y) using the forward transformation (which must be available) at a regular grid of points (X) covering a rectangular region of the ChebyMap's input space. The coefficients of the required inverse polynomial, X=P_i(Y), are chosen in order to minimise the sum of the squared residuals between the sampled values of X and P_i(Y).
This fitting process is performed repeatedly with increasing polynomial orders (starting with linear) until the target accuracy is achieved, or a specified maximum order is reached. If the target accuracy cannot be achieved even with this maximum-order polynomial, the best fitting maximum-order polynomial is returned so long as its accuracy is better than "maxacc". If it is not, an error is reported.
Definition at line 30 of file ChebyMap.cc.