All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
exprinterpret_cppad.cpp
Go to the documentation of this file.
22 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
33 /* defining NO_CPPAD_USER_ATOMIC disables the use of our own implementation of derivaties of power operators
35 * our customized implementation should give better results (tighter intervals) for the interval data type
46 * we need to include the intervalarithext.h very early and require the interval operations to be in the CppAD namespace */
54 * It is wise to set it to a power of 2, so that if the tape id overflows, it is likely to start at 0 again, which avoids difficult to debug errors.
68 * To run it in a multithreading environment, a special CppAD memory allocator that is aware of the multiple threads has to be used.
70 * To implement this, we follow the team_pthread example of CppAD, which uses pthread's thread-specific data management.
75 /* workaround error message regarding missing implementation of tanh during initialization of static variables (see cppad/local/erf.hpp) */
122 * we store the thread number incremented by one, to distinguish the absence of data (=0) from existing data
128 SCIPdebugMessage("Assigning thread number %lu to thread %p.\n", (long unsigned int)ncurthreads, (void*)pthread_self());
167 * the purpose is to make sure that init_parallel() is called before any multithreading is started
362 * For a 1 x q matrix R, we have to return the sparsity pattern of the 1 x q matrix S(x) = f'(x) * R.
381 * For a q x 1 matrix S, we have to return the sparsity pattern of the q x 1 matrix R(x) = S * f'(x).
405 const CppAD::vector<bool>& vx, /**< indicates whether argument is a variable, or empty vector */
436 * This class implements forward and reverse operations for the function x -> x^p for use within CppAD.
437 * While CppAD would implement integer powers as a recursion of multiplications, we still use pow functions as they allow us to avoid overestimation in interval arithmetics.
439 * @todo treat the exponent as a (variable) argument to the function, with the assumption that we never differentiate w.r.t. it (this should make the approach threadsafe again)
480 const CppAD::vector<bool>& vx, /**< indicates whether argument is a variable, or empty vector */
481 CppAD::vector<bool>& vy, /**< vector to store which function values depend on variables, or empty vector */
515 // ty[2] = exponent * (exponent-1) * pow(tx[0], exponent-2) * tx[1] * tx[1] + exponent * pow(tx[0], exponent-1) * tx[2];
540 * Then in the reverse sweep we have to compute the elements of \f$\partial h / \partial x^[l], l = 0, ..., k,\f$
541 * where x^[l] is the l'th taylor coefficient (x, x', x'', ...) and h(x) = g(y(x)) for some function g:R^k -> R.
544 * px[l] = \partial h / \partial x^[l] = (\partial g / \partial y) * (\partial y / \partial x^[l])
588 // px[0] = py[0] * exponent * pow(tx[0], exponent-1) + py[1] * exponent * (exponent-1) * pow(tx[0], exponent-2) * tx[1];
608 * For a 1 x q matrix R, we have to return the sparsity pattern of the 1 x q matrix S(x) = f'(x) * R.
623 * For a q x 1 matrix S, we have to return the sparsity pattern of the q x 1 matrix R(x) = S * f'(x).
642 const CppAD::vector<bool>& vx, /**< indicates whether argument is a variable, or empty vector */
688 * This class implements forward and reverse operations for the function x -> sign(x)abs(x)^p for use within CppAD.
689 * While we otherwise would have to use discontinuous sign and abs functions, our own implementation allows to provide
692 * @todo treat the exponent as a (variable) argument to the function, with the assumption that we never differentiate w.r.t. it (this should make the approach threadsafe again)
733 const CppAD::vector<bool>& vx, /**< indicates whether argument is a variable, or empty vector */
734 CppAD::vector<bool>& vy, /**< vector to store which function values depend on variables, or empty vector */
792 * Then in the reverse sweep we have to compute the elements of \f$\partial h / \partial x^[l], l = 0, ..., k,\f$
793 * where x^[l] is the l'th taylor coefficient (x, x', x'', ...) and h(x) = g(y(x)) for some function g:R^k -> R.
796 * px[l] = \partial h / \partial x^[l] = (\partial g / \partial y) * (\partial y / \partial x^[l])
842 // px[0] = py[0] * p * abs(tx[0])^(p-1) + py[1] * p * (p-1) * abs(tx[0])^(p-2) * sign(tx[0]) * tx[1]
873 * For a 1 x q matrix R, we have to return the sparsity pattern of the 1 x q matrix S(x) = f'(x) * R.
888 * For a q x 1 matrix S, we have to return the sparsity pattern of the q x 1 matrix R(x) = S * f'(x).
907 const CppAD::vector<bool>& vx, /**< indicates whether argument is a variable, or empty vector */
954 const CppAD::vector<bool>& vx, /**< indicates whether argument is a variable, or empty vector */
955 CppAD::vector<bool>& vy, /**< vector to store which function values depend on variables, or empty vector */
1018 CppAD::vector<SCIPInterval>& px, /**< vector to store partial derivatives of h(x) = g(y(x)) w.r.t. x */
1038 // px[0] = py[0] * p * abs(tx[0])^(p-1) + py[1] * p * (p-1) * abs(tx[0])^(p-2) * sign(tx[0]) * tx[1]
1069 * For a 1 x q matrix R, we have to return the sparsity pattern of the 1 x q matrix S(x) = f'(x) * R.
1084 * For a q x 1 matrix S, we have to return the sparsity pattern of the q x 1 matrix R(x) = S * f'(x).
1099 * Assume V(x) = (g(f(x)))'' R with f(x) = sign(x)abs(x)^p for a function g:R->R and a matrix R.
1103 const CppAD::vector<bool>& vx, /**< indicates whether argument is a variable, or empty vector */
1502 /* for each argument, we collect it's linear index from lincoefs, it's square coefficients and all factors from bilinear terms
1509 /* there are no quadratic terms with argidx in its first argument, that should be easy to handle */
1618 * this may be the case if the evaluation sequence depends on values of operands (e.g., in case of abs, sign, signpower, ...)
1650 * we do not want to stop execution in such a case, since the calling routine should check for nan's and decide what to do
1663 SCIPdebugMessage("ignore CppAD error from %sknown source %s:%d: msg: %s exp: %s\n", known ? "" : "un", file, line, msg, exp);
1678 return "Algorithmic Differentiation of C++ algorithms developed by B. Bell (www.coin-or.org/CppAD)";
1935 SCIP_Bool new_varvals, /**< have variable values changed since last call to a point evaluation routine? */
1937 SCIP_Real* gradient /**< buffer to store expression gradient, need to have length at least SCIPexprtreeGetNVars(tree) */
1966 SCIPdebugMessage("x ="); for (int i = 0; i < n; ++i) printf("\t %g", data->x[i]); printf("\n");
1967 SCIPdebugMessage("grad ="); for (int i = 0; i < n; ++i) printf("\t %g", gradient[i]); printf("\n");
1979 SCIP_INTERVAL* varvals, /**< interval values of variables, can be NULL if new_varvals is FALSE */
1980 SCIP_Bool new_varvals, /**< have variable interval values changed since last call to an interval evaluation routine? */
1982 SCIP_INTERVAL* gradient /**< buffer to store expression interval gradient, need to have length at least SCIPexprtreeGetNVars(tree) */
2009 SCIPdebugMessage("x ="); for (int i = 0; i < n; ++i) printf("\t [%g,%g]", SCIPintervalGetInf(data->int_x[i]), SCIPintervalGetSup(data->int_x[i])); printf("\n");
2010 SCIPdebugMessage("grad ="); for (int i = 0; i < n; ++i) printf("\t [%g,%g]", SCIPintervalGetInf(gradient[i]), SCIPintervalGetSup(gradient[i])); printf("\n");
2025 SCIP_Bool* sparsity /**< buffer to store sparsity pattern of Hessian, sparsity[i+n*j] indicates whether entry (i,j) is nonzero in the hessian */
2048 SCIPdebugMessage("HessianSparsityDense for "); SCIPexprtreePrint(tree, NULL, NULL, NULL); printf("\n");
2079 SCIPdebugMessage("HessianSparsityDense for "); SCIPexprtreePrint(tree, NULL, NULL, NULL); printf("\n");
2080 SCIPdebugMessage("sparsity ="); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (sparsity[i*n+j]) printf(" (%d,%d)", i, j); printf("\n");
2094 SCIP_Bool new_varvals, /**< have variable values changed since last call to an evaluation routine? */
2125 SCIPdebugMessage("HessianDense for "); SCIPexprtreePrint(tree, NULL, NULL, NULL); printf("\n");
2126 SCIPdebugMessage("x ="); for (int i = 0; i < n; ++i) printf("\t %g", data->x[i]); printf("\n");
|