MC++
|
A \(q\)th-order Taylor model of a multivariate function \(f:\mathbb{R}^n\to\mathbb{R}\) that is (at least) \((q+1)\)-times continuously differentiable on the domain \(D\), consists of the \(q^{\rm th}\)-order multivariate Taylor polynomial \(\mathcal P\), expanded around a point \(\hat{x}\in D\), plus a remainder term \(\mathcal R\), so that
\begin{align*} f({x}) \in \mathcal P({x}-\hat{x}) \oplus \mathcal R, \quad \forall {x}\in D. \end{align*}
The polynomial part \(\mathcal P\) is propagated symbolically and accounts for functional dependencies. The remainder term \(\mathcal R\), on the other hand, is traditionally computed using interval analysis [Neumaier, 2002; Makino & Berz, 2003]; see figure below. More generally, convex/concave bounds for the remainder term can be propagated using McCormick relaxations, leading to so-called McCormick-Taylor models [Sahlodin & Chachuat, 2011], and ellipsoidal enclosure can be computed for the remainder term of vector-valued functions too [Houska et al., 2013]. In particular, it can be established that the remainder term has convergence order (no less than) \(q+1\) with respect to the diameter of the domain set \(D\) under mild conditions [Bompadre et al., 2012].
![]() |
The classes mc::TModel and mc::TVar provide an implementation of Taylor model arithmetic. We note that mc::TModel / mc::TVar is not a verified implementation in the sense that rounding errors are not accounted for in propagating the coefficients in the multivariate polynomial part, which are treated as floating-point numbers.
The implementation of mc::TModel and mc::TVar relies on the operator/function overloading mechanism of C++. This makes the computation of Taylor models both simple and intuitive, similar to computing function values in real arithmetics or function bounds in interval arithmetic (see Non-Verified Interval Arithmetic for Factorable Functions). Moreover, mc::TVar can be used as the template parameter of other available types in MC++; for instance, mc::McCormick can be used in order to propagate the underlying interval bounds. Likewise, mc::McCormick can be used as the template parameter of the types fadbad::F, fadbad::B and fadbad::T of FADBAD++ for computing Taylor models of either the partial derivatives or the Taylor coefficients of a factorable function (see How do I compute Taylor models of the partial derivatives or the Taylor coefficients of a factorable function using FADBAD++?).
mc::TModel and mc::TVar themselves are templated in the type used to propagate bounds on the remainder term. By default, mc::TModel and mc::TVar can be used with the non-verified interval type mc::Interval of MC++. For reliability, however, it is strongly recommended to use verified interval arithmetic such as PROFIL (header file mcprofil.hpp
) or FILIB++ (header file mcfilib.hpp
). As already noted, convex/concave bounds on the remainder term can also be propagated by using the type mc::McCormick of MC++, thereby enabling McCormick-Taylor models.
As well as propagating Taylor models for factorable functions, mc::TModel and mc::TVar provide support for computing bounds on the Taylor model range (multivariate polynomial part). We note that computing exact bounds for multivariate polynomials is a hard problem in general. Instead, a number of computationally tractable, yet typically conservative, bounding approaches are implemented in mc::TModel and mc::TVar, which include:
Examples of Taylor and McCormick-Taylor models (blue lines) constructed with mc::TModel and mc::TVar are shown on the left and right plots of the figure below, respectively, for the factorable function \(f(x)=x \exp(-x^2)\) (red line) for \(x\in [-0.5,1]\). Also shown on these plots are the bounds, either interval or convex/concave bounds, computed from the Taylor models.
![]() | ![]() |
Suppose we want to compute a 4th-order Taylor model for the real-valued function \(f(x,y)=x\exp(x+y^2)-y^2\) with \((x,y)\in [1,2]\times[0,1]\). For simplicity, bounds on the remainder terms are computed using the default interval type mc::Interval here:
First, the number of independent variables in the factorable function ( \(x\) and \(y\) here) as well as the order of the Taylor model (4th order here) are specified by defining an mc::TModel object as:
Next, the variables \(x\) and \(y\) are defined as follows:
Essentially, the first line means that X
is a variable of class mc::TVar, participating in the Taylor model mod
, belonging to the interval \([1,2]\), and having index 0 (indexing in C/C++ start at 0 by convention!). The same holds for the Taylor variable Y
, participating in the model mod
, belonging to the interval \([0,1]\), and having index 1.
Having defined the variables, a Taylor model of \(f(x,y)=x\exp(x+y^2)-y^2\) on \([1,2]\times[0,1]\) at the mid-point \((\frac{3}{2},\frac{1}{2})\) is simply computed as:
This model can be displayed to the standard output as:
which produces the following output:
f Taylor model: a0 = 8.38199e+00 0 0 a1 = 1.90755e+00 0 1 a2 = 3.59621e+00 1 0 a3 = 7.47482e-01 0 2 a4 = 9.00782e-01 1 1 a5 = 6.30186e-01 2 0 a6 = 1.56945e-01 0 3 a7 = 3.35238e-01 1 2 a8 = 1.55141e-01 2 1 a9 = 6.67468e-02 3 0 a10 = 3.49519e-02 0 4 a11 = 6.58449e-02 1 3 a12 = 6.04330e-02 2 2 a13 = 1.80397e-02 3 1 a14 = 5.41191e-03 4 0 R = [ -2.09182e+00 : 2.22652e+00 ] B = [ -1.02564e+01 : 3.93973e+01 ]
a0
,...,a14
refer to the coefficients of the monomial terms in the Taylor model, with the corresponding variable orders given in the subsequent columns. The remainder term as well as the Taylor model range estimator are reported next.
Other operations involve retreiving the remainder bound, centering the remainder term in a Taylor model, or computing the value of its polynomial part at a given point:
See the documentations of mc::TModel and mc::TVar for a complete list of member functions.
Instead of using standard interval arithmetic for propagating bounds on the remainder term of the Taylor expansion, or for bounding the range of the multivariate polynomial part, one can also make use of the McCormick relaxation technique to propagate convex/concave bounds. Such McCormick-Taylor models are enabled in MC++ simply by selecting mc::McCormick as the template parameter in mc::TModel and mc::TVar:
Then, the procedure for computing the Taylor model remains essentially the same as described in the previous section. In order to compute a 4th-order McCormick-Taylor model of \(f(x,y)=x\exp(x+y^2)-y^2\) for \((x,y)\in[1,2]\times[0,1]\) and obtain convex/concave bounds for the resulting McCormick-Taylor model at \((1.5,0.5)\), we proceed as follows:
The only difference here concerns the initialization of the McCormick variables inside the Taylor variables X
and Y
, which passes the bounds for the variable as well as the point at which the convex/concave bounds are computed—See How do I compute McCormick relaxations of a factorable function?
More information on the Taylor model and the corresponding bounds can again be obtained as:
In this case, the following information is displayed:
f McCormick-Taylor model: a0 = 8.38199e+00 0 0 a1 = 1.90755e+00 0 1 a2 = 3.59621e+00 1 0 a3 = 7.47482e-01 0 2 a4 = 9.00782e-01 1 1 a5 = 6.30186e-01 2 0 a6 = 1.56945e-01 0 3 a7 = 3.35238e-01 1 2 a8 = 1.55141e-01 2 1 a9 = 6.67468e-02 3 0 a10 = 3.49519e-02 0 4 a11 = 6.58449e-02 1 3 a12 = 6.04330e-02 2 2 a13 = 1.80397e-02 3 1 a14 = 5.41191e-03 4 0 R = [ -2.09182e+00 : 2.22652e+00 ] [ -1.70505e+00 : 1.80226e+00 ] B = [ -1.02564e+01 : 3.93973e+01 ] [ -2.63875e+00 : 2.66234e+01 ]
As expected, the McCormick-Taylor model coefficients are identical to their Taylor model counterparts, and so are the interval bounds of the remainder term and Taylor model range estimator. The convex/concave bounds at \((1.5,0.5)\) come as additional information and are seen to be tighter than the interval bounds. Naturally, subgradients of the resulting convex and concave relaxations can also be propagated as explained at How do I compute a subgradient of the McCormick relaxations?.
Finally, the McCormick relaxation of the Taylor model can also be obtained as:
Naturally, subgradients of the convex/concave remainder bounds can also be propagated, e.g., by seeding the subgradients of X
and Y
as follows:
See How do I compute a subgradient of the McCormick relaxations? for more details.
The combination of mc::TVar with the classes fadbad::F, and fadbad::B of FADBAD++ to compute Taylor models of the partial derivatives or the Taylor coefficients of a factorable function is essentially the same as with mc::McCormick (see How do I compute McCormick relaxations of the partial derivatives or the Taylor coefficients of a factorable function using FADBAD++?).
We present the case of fadbad::F only. Continuing the previous example, McCormick-Taylor models of the partial derivatives of \(f(x,y)=x\exp(x+y^2)-y^2\) for \((x,y)\in [1,2]\times[0,1]\) can be computed as follows:
producing the output:
f McCormick-Taylor model with subgradients at (1.5,0.5): a0 = 8.38199e+00 0 0 a1 = 1.90755e+00 0 1 a2 = 3.59621e+00 1 0 a3 = 7.47482e-01 0 2 a4 = 9.00782e-01 1 1 a5 = 6.30186e-01 2 0 a6 = 1.56945e-01 0 3 a7 = 3.35238e-01 1 2 a8 = 1.55141e-01 2 1 a9 = 6.67468e-02 3 0 a10 = 3.49519e-02 0 4 a11 = 6.58449e-02 1 3 a12 = 6.04330e-02 2 2 a13 = 1.80397e-02 3 1 a14 = 5.41191e-03 4 0 R = [ -2.09182e+00 : 2.22652e+00 ] [ -1.70505e+00 : 1.80226e+00 ] [ (-7.35405e-01, 1.52576e-02) : ( 8.33268e-01, 1.52576e-02) ] B = [ -1.02564e+01 : 3.93973e+01 ] [ -2.63875e+00 : 2.66234e+01 ] [ ( 7.24415e+00, 2.32253e+00) : ( 8.81282e+00, 1.67350e+01) ] df/dx McCormick-Taylor model with subgradients at (1.5,0.5): a0 = 1.43867e+01 0 0 a1 = 3.59591e+00 0 1 a2 = 5.03458e+00 1 0 a3 = 1.34997e+00 0 2 a4 = 1.26158e+00 1 1 a5 = 8.10583e-01 2 0 a6 = 2.61575e-01 0 3 a7 = 4.68731e-01 1 2 a8 = 1.98437e-01 2 1 a9 = 8.11786e-02 3 0 a10 = 5.82532e-02 0 4 a11 = 9.23031e-02 1 3 a12 = 7.84726e-02 2 2 a13 = 2.28503e-02 3 1 a14 = 6.61455e-03 4 0 R = [ -1.34116e+00 : 1.40851e+00 ] [ -1.32972e+00 : 1.39325e+00 ] [ ( 1.52576e-02, 1.52576e-02) : ( 1.52576e-02, 1.52576e-02) ] B = [ -1.11441e+01 : 5.89599e+01 ] [ 1.45326e-01 : 3.96272e+01 ] [ ( 1.10351e+01, 7.44520e+00) : ( 1.10351e+01, 2.76304e+01) ] df/dy McCormick-Taylor model with subgradients at (1.5,0.5): a0 = 7.63199e+00 0 0 a1 = 5.97354e+00 0 1 a2 = 3.59621e+00 1 0 a3 = 1.88876e+00 0 2 a4 = 2.69889e+00 1 1 a5 = 6.30186e-01 2 0 a6 = 5.61936e-01 0 3 a7 = 7.85628e-01 1 2 a8 = 4.70235e-01 2 1 a9 = 6.67468e-02 3 0 a10 = 1.13425e-01 0 4 a11 = 2.33464e-01 1 3 a12 = 1.38004e-01 2 2 a13 = 5.14131e-02 3 1 a14 = 5.41191e-03 4 0 R = [ -7.13855e+00 : 7.40794e+00 ] [ -5.04673e+00 : 5.18142e+00 ] [ (-2.68232e+00,-1.50133e+00) : ( 2.81702e+00, 1.63602e+00) ] B = [ -3.93313e+01 : 7.87946e+01 ] [ -2.40726e+01 : 5.36565e+01 ] [ (-9.08762e+00, 7.54498e+00) : (-3.58827e+00, 5.38645e+01) ]
mc::TVar overloads the usual functions exp
, log
, sqr
, sqrt
, pow
, inv
, cos
, sin
, tan
, acos
, asin
, atan
. Unlike mc::Interval and mc::McCormick, the functions min
, max
and fabs
are not overloaded in mc::TVar as they are nonsmooth. Moreover, mc::TVar defines the following functions:
inter(x,y,z)
, computing a Taylor model of the intersection \(x = y\cap z\) of two Taylor models and returning true/false if the intersection is nonempty/empty. With Taylor models \(\mathcal P_y\oplus\mathcal R_y\) and \(\mathcal P_z\oplus\mathcal R_z\), this intersection is computed as follows: \begin{align*} \mathcal P_{x} =\ & (1-\eta) \mathcal P_y^{\rm C} + \eta \mathcal P_z^{\rm C}\\ \mathcal R_{x} =\ & [\mathcal R_y^{\rm C}\oplus\eta\mathcal{B}(\mathcal P_y^{\rm C}-\mathcal P_z^{\rm C})] \cap [\mathcal R_z^{\rm C}\oplus (1-\eta)\mathcal{B}(\mathcal P_z^{\rm C}-\mathcal P_y^{\rm C})]\,. \end{align*}
with \(\mathcal{B}(\cdot)\) the Taylor model range bounder, and \(\eta\) a real scalar in \([0,1]\). Choosing \(\eta=1\) amounts to setting the polynomial part \(\mathcal P_{x}\) as \(\mathcal P_y\), whereas \(\eta=0\) sets \(\mathcal P_{x}\) as \(\mathcal P_z\). The parameter \(\eta\) can be defined in mc::TModel::Options::REF_POLY.hull(x,y)
, computing a Taylor model of the union \(x = y\cup z\) of two Taylor models. With Taylor models \(\mathcal P_y\oplus\mathcal R_y\) and \(\mathcal P_z\oplus\mathcal R_z\), this union is computed as follows: \begin{align*} \mathcal P_{x} =\ & (1-\eta) \mathcal P_y^{\rm C} + \eta \mathcal P_z^{\rm C}\\ \mathcal R_{x} =\ & {\rm hull}\{\mathcal R_y^{\rm C}\oplus\eta\mathcal{B}(\mathcal P_y^{\rm C}-\mathcal P_z^{\rm C}), \mathcal R_z^{\rm C}\oplus (1-\eta)\mathcal{B}(\mathcal P_z^{\rm C}-\mathcal P_y^{\rm C})\}\,. \end{align*}
with \(\mathcal{B}(\cdot)\) and \(\eta\) as previously.The class mc::TModel has a public member called mc::TModel::options that can be used to set/modify the options; e.g.,
The available options are the following:
Name | Type | Default | Description |
---|---|---|---|
BOUNDER_TYPE | mc::TModel::Options::BOUNDER | mc::TModel::Options::LSB | Taylor model range bounder. |
BOUNDER_ORDER | unsigned int | 0 | Order of Bernstein polynomial for Taylor model range bounding, when mc::TModel::options::BOUNDER_TYPE = mc::TModel::options::BERNSTEIN is selected. Only values greater than the actual Taylor model order are accounted for; see [Lin & Rokne, 1996]. |
SCALE_VARIABLES | bool | false | Whether to scale the variable ranges to [-1,1] internally. |
CENTER_REMAINDER | bool | false | Whether to center the remainder term during Taylor model propagation. |
REF_MIDPOINT | bool | false | Whether to take the midpoint of the inner range as the reference in the outer composition with a univariate function (true), as opposed to taking the constant coefficient of the inner Taylor model (false). |
REF_POLY | double | 0. | Scalar in \([0,1]\) related to the choice of the polynomial part in the overloaded functions mc::inter and mc::hull (see Which functions are overloaded for Taylor model arithmetic?). A value of 0. amounts to selecting the polynomial part of the left operand, whereas a value of 1. selects the right operand. |
BERNSTEIN_USE | bool | false | Whether to compute a Berstein model [Stancu, 1963] of the outer function in a univariate composition and use it instead of the Taylor model when its remainder term is smaller. This enables tighter Taylor models on wider variable ranges, while retaining the high-order convergence order of Taylor models, but incurs a computational overhead. |
BERNSTEIN_OPT | bool | true | Whether to compute exact remainder bounds for Berstein models of convex/concave univariates exp, log, inv and sqrt. This provides tighter estimators, but incurs an extra computational overhead. The exact remainder bounds are computed using the golden section search method. |
BERNSTEIN_TOL | double | 1e-10 | Termination tolerance for determination of the exact remainder bounds in a Berstein model of convex/concave univariates exp, log, inv and sqrt. |
BERNSTEIN_MAXIT | int | 100 | Maximum number of iterations for determination of the exact remainder bounds in a Berstein model of convex/concave univariates exp, log, inv and sqrt. |
DISPLAY_DIGITS | unsigned int | 5 | Number of digits in output stream for Taylor model coefficients. |
Errors are managed based on the exception handling mechanism of the C++ language. Each time an error is encountered, a class object of type mc::TModel::Exceptions is thrown, which contains the type of error. It is the user's responsibility to test whether an exception was thrown during the computation of a Taylor model, and then make the appropriate changes. Should an exception be thrown and not caught by the calling program, the execution will abort.
Possible errors encountered during the computation of a Taylor model are:
Number | Description |
---|---|
1 | Division by zero |
2 | Failed to compute eigenvalue decomposition in range bounder TModel::Options::EIGEN |
3 | Failed to compute the maximum gap between a univariate term and its Bernstein model |
-1 | Number of variable in Taylor model must be nonzero |
-2 | Failed to construct Taylor variable |
-3 | Taylor model bound does not intersect with bound in template parameter arithmetic |
-4 | Operation between Taylor variables linked to different Taylor models |
-5 | Maximum size of Taylor model reached (monomials indexed as unsigned int) |
-33 | Feature not yet implemented in mc::TModel |
Moreover, exceptions may be thrown by the template parameter class itself.