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

Go to the documentation of this file.
00001 # ifndef CPPAD_LOG_OP_INCLUDED
00002 # define CPPAD_LOG_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 ForLogOp$$ $comment CppAD Developer Documentation$$
00017 $spell
00018         Log
00019         Taylor
00020         const
00021         inline
00022         Op
00023 $$
00024 
00025 
00026 $index forward, log$$
00027 $index log, forward$$
00028 $index ForLogOp$$
00029 
00030 $section Forward Mode Logarithm Function$$
00031 
00032 $head Syntax$$
00033 
00034 $syntax%inline void ForLogOp(size_t %d%,
00035         %Base% *%z%, const %Base% *%x%)%$$
00036 
00037 $head Description$$
00038 Computes the $italic d$$ order Taylor coefficient for $latex Z$$ where
00039 $syntax%
00040         %Z% = Log(%X%)
00041 %$$
00042 
00043 $head x$$
00044 The vector $italic x$$ has length $latex d+1$$ and contains the
00045 $th d$$ order Taylor coefficient row vector for $italic X$$.
00046 
00047 $head z$$
00048 The vector $italic z$$ has length $latex d+1$$.
00049 On input it contains the
00050 $th d-1$$ order Taylor coefficient row vector for $italic Z$$.
00051 On output it contains the
00052 $th d$$ order Taylor coefficient row vector for $italic Z$$; i.e.,
00053 $syntax%%z%[%d%]%$$ is set equal to the $th d$$ Taylor coefficient for
00054 the function $italic Z$$.
00055 
00056 $end
00057 ------------------------------------------------------------------------------
00058 $begin RevLogOp$$ $comment CppAD Developer Documentation$$
00059 $spell
00060         Log
00061         Taylor
00062         const
00063         inline
00064         Op
00065         px
00066         py
00067         pz
00068 $$
00069 
00070 
00071 $index reverse, log$$
00072 $index log, reverse$$
00073 $index RevLogOp$$
00074 
00075 $section Reverse Mode Logarithm Function$$
00076 
00077 $head Syntax$$
00078 
00079 $syntax%inline void RevLogOp(size_t %d%,
00080         const %Base% *%z%, const %Base% *%x%,
00081          %Base% *%pz%, %Base% *%px%)%$$
00082 
00083 $head Description$$
00084 We are given the partial derivatives for a function
00085 $latex G(z, x)$$ and we wish to compute the partial derivatives for
00086 the function
00087 $latex \[
00088         H(x) = G [ Z(x) , x ]
00089 \]$$
00090 where $latex Z(x)$$ is defined as the 
00091 $th d$$ order Taylor coefficient row vector for $italic Z$$ as
00092 a function of the corresponding row vector for $italic X$$ 
00093 and
00094 $latex \[
00095         Z = Log(X)
00096 \]$$
00097 Note that $italic Z$$ has been used both the original logarithm 
00098 function and for the corresponding mapping of Taylor coefficients.
00099 
00100 $head x$$
00101 The vector $italic x$$ has length $latex d+1$$ and contains the
00102 $th d$$ order Taylor coefficient row vector for $italic X$$.
00103 
00104 
00105 $head z$$
00106 The vector $italic z$$ has length $latex d+1$$ and contains
00107 $th d$$ order Taylor coefficient row vector for $italic Z$$.
00108 
00109 
00110 $head On Input$$
00111 
00112 $subhead px$$
00113 The vector $italic px$$ has length $latex d+1$$ and 
00114 $syntax%%px%[%j%]%$$ contains the partial for $italic G$$
00115 with respect to the $th j$$ order Taylor coefficient for $italic X$$.
00116 
00117 $subhead pz$$
00118 The vector $italic pz$$ has length $latex d+1$$ and 
00119 $syntax%%pz%[%j%]%$$ contains the partial for $italic G$$
00120 with respect to the $th j$$ order Taylor coefficient for $italic Z$$.
00121 
00122 $head On Output$$
00123 
00124 $subhead px$$
00125 The vector $italic px$$ has length $latex d+1$$ and 
00126 $syntax%%px%[%j%]%$$ contains the partial for $italic H$$
00127 with respect to the $th j$$ order Taylor coefficient for $italic X$$.
00128 
00129 $subhead pz$$
00130 The vector $italic pz$$ has length $latex d+1$$ and 
00131 its contents are no longer specified; i.e., it has
00132 been used for work space.
00133 
00134 $end
00135 ------------------------------------------------------------------------------
00136 */
00137 
00138 // BEGIN CppAD namespace
00139 namespace CppAD {
00140 
00141 template <class Base>
00142 inline void ForLogOp(size_t j, 
00143         Base *z, const Base *x)
00144 {       size_t k;
00145 
00146         if( j == 0 )
00147                 z[j] = log( x[0] );
00148         else
00149         {
00150                 z[j] = Base(0);
00151                 for(k = 1; k < j; k++)
00152                         z[j] -= Base(k) * z[k] * x[j-k];
00153                 z[j] /= Base(j);
00154                 z[j] += x[j];
00155                 z[j] /= x[0];
00156         }
00157 }
00158 
00159 template <class Base>
00160 inline void RevLogOp(size_t d, 
00161         const Base  *z, const Base *x,
00162               Base *pz,      Base *px)
00163 {       size_t k;
00164 
00165         // number of indices to access
00166         size_t j = d;
00167 
00168         while(j)
00169         {       // scale partial w.r.t z[j]
00170                 pz[j]   /= x[0];
00171 
00172                 px[0]   -= pz[j] * z[j];
00173                 px[j]   += pz[j];
00174 
00175                 // further scale partial w.r.t. z[j]
00176                 pz[j]   /= Base(j);
00177 
00178                 for(k = 1; k < j; k++)
00179                 {       pz[k]   -= pz[j] * Base(k) * x[j-k];
00180                         px[j-k] -= pz[j] * Base(k) * z[k];
00181                 }
00182                 --j;
00183         }
00184         px[0] += pz[0] / x[0];
00185 }
00186 
00187 } // END CppAD namespace
00188 
00189 # endif

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