[CppAD] Discrete AD functions and linear interpolation

Brad Bell bradbell at apl.washington.edu
Thu Sep 13 18:03:53 EDT 2007


The interval corresponding to an interpolation may depend on the value of 
the independent variables. In this case, the the discrete AD function 
macro
 	http://www.coin-or.org/CppAD/Doc/discrete.xml
can be used to compute the interpolation so that one need not retape the 
operation sequence for the new value of the independent variables before 
taking derivatives.

On the other hand, there may be other decision variables in the code that 
cause the operation sequence to change (for different values of the 
independent variables). For example, the operation sequence corresponding 
to
 	http://www.coin-or.org/CppAD/Doc/exp_eps.hpp.xml
depends on the value of x and epsilon; see the heading Comparisons in
 	http://www.coin-or.org/CppAD/Doc/exp_eps_for0.xml

It is always simpler (but perhaps slower) to "retape" the operation 
sequence for each value of the independent variables. Thus, I would 
suggest that you start with this approach.

P.S.
I agree that global variables should be avoided. If you do end up using a 
discrete function and need data attached to it, I suggest using a C++ 
function object. The constructor for the function object could contain the 
data. This would avoid any global variables. Perhaps the example
 	http://www.coin-or.org/CppAD/Doc/piecewise.cpp.xml
should be changed to use this approach ?



On Thu, 13 Sep 2007, herve.martin.sc at libertysurf.fr wrote:

> Hi,
>
> I would like to rewrite a big simulation code to use CppAD. However, I 
> run into a problem with the discrete functions. My code uses a lot of 
> lookup tables with linear/spline interpolation. So it seems to me that 
> the natural choice in CppAD is to perform the linear interpolation with 
> discrete functions declared with the CPPAD_DISCRETE_FUNCTION macro.
>
> The problem is that the interface of this function does not allow to 
> pass additional data to compute the needed values, just a double 
> argument. So for each set of data, a new set of functions has to be 
> defined. More, in the example Piecewise.cpp, the lookup tables are 
> global variables. But my tables are read at runtime in many files. How 
> can I specify to CppAD which table to use in my code, so that the 
> correct table is chosen during a sweep of the tape ? I absolutely want 
> to avoid static / global variables to avoid reentrancy problems...
>
> I hope I was clear enough...
> Thanks in advance for any help.
>
> Hervé Martin
>
>
> ------------------------ ALICE C'EST ENCORE MIEUX AVEC CANAL+ LE BOUQUET ! ---------------
> Découvrez vite l'offre exclusive ALICEBOX et CANAL+ LE BOUQUET, en cliquant ici http://alicebox.fr
> Soumis à conditions.
>
>
>
> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cppad
>


More information about the CppAD mailing list