Replies: 6 comments 5 replies
-
This closely connected to the following discussion There are some subtitle case issues and complicated interactions when it comes to the pow function. I have suggested in discussion 85 that someone write an atomic function that handles all the cases as a suggestion of how it should be changed. While this would work for the case where one takes the derivative of a Finally, I would mention that AD is only really works at points where the function is differentiable and the pow function is not differentiable at zero. What makes it complicated from the users perspective is that, when x is a dynamic parameter, one might think they only need differentiable w.r.t. y. |
Beta Was this translation helpful? Give feedback.
-
So what you are suggesting is a special instruction for computing derivaitves when y is a parameter and the pow function becomes a unary instead of binary function. This is not a bad idea. We would still need to consider the case where x is zero and we take the second derivative of x^2.0 or the third derivative of x^3, ... or the case where the exponent is an integer and x is negative. More generally, when both x and y are variables, these cases cause problems and should be handled. If it were not for wanting to handle the case where the derivatives are being computed using AD, it would not be so bad. Once I start adding conditional expressions to handle this, the code would slow down. Every time I think about how to do this efficiently and generally, it seems complicated. |
Beta Was this translation helpful? Give feedback.
-
Now that I think about it, of course I implemented that operator. So your suggestion is that for computing the k-th derivative of Z(t) = pow( X(t), y ) we use The problem with this representation is that the number of terms get out of hand as the order of the derivative increases. The central 'trick' in this representation is to find a differential equation of the form In this case the differential equation is The k-th order Taylor coefficient z^k is the the k-th derivative of Z(t) evaluated at t=0 and divided by k; i.e Zero order coefficients is computed using z^0 = pow( x^0, y). The second order coefficient would be calculated using As you can see, if x^0 is zero, then z^0 is zero and we are computing zero / zero. |
Beta Was this translation helpful? Give feedback.
-
I think the special cases are all sub-cases of x^0 = 0 as follows: If j < y, z^j = 0. If j = y, z^j = y! (x^1)**j If j an integer and j > y, z^j = 0 Otherwise, nan is a good result for z^j If it were just a simple if then else would be nice, but given the context, conditional expressions will need to be used. |
Beta Was this translation helpful? Give feedback.
-
I think this form of the operator would be about three times faster than using exp(y*log(x)), were it not for the conditional expressions. |
Beta Was this translation helpful? Give feedback.
-
I have taken a step toward improving pow(x,y). To be specific, in the case where y is a parameter, x is zero, and y is greater than the order of the derivative being calculated. See the heading If y is a Parameter on One of the things that makes this difficult is that any if then else logic in the evaluation of derivatives would require re-taping for different values of x or y (when the type used during the derivative calculation is an AD type). I was able to use conditional expressions for the case mentioned above, but further cases would require if then else logic. |
Beta Was this translation helpful? Give feedback.
-
x^1.875 is differentiable at x=0, but CppAD gives nan for the derivative.
The code
prints
This seems to be because powvp actually reformulates pow(x,p) as exp(log(x)*p) (https://github.com/coin-or/CppAD/blob/master/include/cppad/local/pow_op.hpp#L463), which fails for x=0.
Beta Was this translation helpful? Give feedback.
All reactions