/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/exp_op.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_EXP_OP_INCLUDED
00002 # define CPPAD_EXP_OP_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     Common Public License Version 1.0.
00010 
00011 A copy of this license is included in the COPYING file of this distribution.
00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00013 -------------------------------------------------------------------------- */
00014 
00015 /*
00016 $begin ForExpOp$$ $comment CppAD Developer Documentation$$
00017 $spell
00018         Exp
00019         Taylor
00020         const
00021         inline
00022         Op
00023 $$
00024 
00025 $index forward, exp$$
00026 $index exp, forward$$
00027 $index ForExpOp$$
00028 
00029 $section Forward Mode Exponential Function$$
00030 
00031 $head Syntax$$
00032 
00033 $syntax%inline void ForExpOp(size_t %d%,
00034         %Base% *%z%, const %Base% *%x%)%$$
00035 
00036 $head Description$$
00037 Computes the $italic d$$ order Taylor coefficient for $latex Z$$ where
00038 $syntax%
00039         %Z% = Exp(%X%)
00040 %$$
00041 
00042 $head x$$
00043 The vector $italic x$$ has length $latex d+1$$ and contains the
00044 $th d$$ order Taylor coefficient row vector for $italic X$$.
00045 
00046 $head z$$
00047 The vector $italic z$$ has length $latex d+1$$.
00048 On input it contains the
00049 $th d-1$$ order Taylor coefficient row vector for $italic Z$$.
00050 On output it contains the
00051 $th d$$ order Taylor coefficient row vector for $italic Z$$; i.e.,
00052 $syntax%%z%[%d%]%$$ is set equal to the $th d$$ Taylor coefficient for
00053 the function $italic Z$$.
00054 
00055 $end
00056 ------------------------------------------------------------------------------
00057 $begin RevExpOp$$ $comment CppAD Developer Documentation$$
00058 $spell
00059         Exp
00060         Taylor
00061         const
00062         inline
00063         Op
00064         px
00065         py
00066         pz
00067 $$
00068 
00069 $index reverse, exp$$
00070 $index exp, reverse$$
00071 $index RevExpOp$$
00072 
00073 $section Reverse Mode Exponential Function$$
00074 
00075 $head Syntax$$
00076 
00077 $syntax%inline void RevExpOp(size_t %d%,
00078         const %Base% *%z%, const %Base% *%x%,
00079          %Base% *%pz%, %Base% *%px%)%$$
00080 
00081 $head Description$$
00082 We are given the partial derivatives for a function
00083 $latex G(z, x)$$ and we wish to compute the partial derivatives for
00084 the function
00085 $latex \[
00086         H(x) = G [ Z(x) , x ]
00087 \]$$
00088 where $latex Z(x)$$ is defined as the 
00089 $th d$$ order Taylor coefficient row vector for $italic Z$$ as
00090 a function of the corresponding row vector for $italic X$$ 
00091 and
00092 $latex \[
00093         Z = Exp(X)
00094 \]$$
00095 Note that $italic Z$$ has been used both the original exponential 
00096 function and for the corresponding mapping of Taylor coefficients.
00097 
00098 $head x$$
00099 The vector $italic x$$ has length $latex d+1$$ and contains the
00100 $th d$$ order Taylor coefficient row vector for $italic X$$.
00101 
00102 
00103 $head z$$
00104 The vector $italic z$$ has length $latex d+1$$ and contains
00105 $th d$$ order Taylor coefficient row vector for $italic Z$$.
00106 
00107 
00108 $head On Input$$
00109 
00110 $subhead px$$
00111 The vector $italic px$$ has length $latex d+1$$ and 
00112 $syntax%%px%[%j%]%$$ contains the partial for $italic G$$
00113 with respect to the $th j$$ order Taylor coefficient for $italic X$$.
00114 
00115 $subhead pz$$
00116 The vector $italic pz$$ has length $latex d+1$$ and 
00117 $syntax%%pz%[%j%]%$$ contains the partial for $italic G$$
00118 with respect to the $th j$$ order Taylor coefficient for $italic Y$$.
00119 
00120 $head On Output$$
00121 
00122 $subhead px$$
00123 The vector $italic px$$ has length $latex d+1$$ and 
00124 $syntax%%px%[%j%]%$$ contains the partial for $italic H$$
00125 with respect to the $th j$$ order Taylor coefficient for $italic X$$.
00126 
00127 $subhead pz$$
00128 The vector $italic pz$$ has length $latex d+1$$ and 
00129 its contents are no longer specified; i.e., it has
00130 been used for work space.
00131 
00132 $end
00133 ------------------------------------------------------------------------------
00134 */
00135 
00136 // BEGIN CppAD namespace
00137 namespace CppAD {
00138 
00139 template <class Base>
00140 inline void ForExpOp(size_t j, 
00141         Base *z, const Base *x)
00142 {       size_t k;
00143 
00144         if( j == 0 )
00145                 z[j] = exp( x[0] );
00146         else
00147         {
00148                 z[j] = Base(0);
00149                 for(k = 1; k <= j; k++)
00150                         z[j] += Base(k) * x[k] * z[j-k];
00151                 z[j] /= Base(j);
00152         }
00153 }
00154 
00155 template <class Base>
00156 inline void RevExpOp(size_t d, 
00157         const Base  *z, const Base *x,
00158               Base *pz,      Base *px)
00159 {       size_t k;
00160 
00161         // number of indices to access
00162         size_t j = d;
00163 
00164         while(j)
00165         {       // scale partial w.r.t z[j]
00166                 pz[j] /= Base(j);
00167 
00168                 for(k = 1; k <= j; k++)
00169                 {       px[k]   += pz[j] * Base(k) * z[j-k];    
00170                         pz[j-k] += pz[j] * Base(k) * x[k];
00171                 }
00172                 --j;
00173         }
00174         px[0] += pz[0] * z[0];
00175 }
00176 
00177 } // END CppAD namespace
00178 
00179 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7