Revision 1143 trunk/src/linad99/posfunv.cpp
posfunv.cpp (revision 1143)  

11  11  
12  12 
#include <fvar.hpp> 
13  13  
14 
/** 

15 
Retuns a positive function of the argument \f$x\f$ and sets a penalty for 

14 
/**Retuns a positive function of the argument \f$x\f$ and sets a penalty for 

16  15 
\f$x<0\f$. The penalty should be added to the objective function. 
16 
This function is intended to keep model state variables in the positive 

17 
domain to avoid mathematical errors. See Section 2.3 of the ADMB Manual. 

17  18 
\param x Argument, \f$x\f$. 
18  19 
\param eps Threshold, \f$\epsilon\f$, 
19  20 
a double constant containing the minimum allowed value of \f$x\f$. 
21 
The choice of a value for \f$\epsilon\f$ is model dependent, 

22 
but \f$10^{3}\f$ is sufficient for some applications. 

20  23 
\param _pen The penalty value \b incremented by \f$ 0.01(x\epsilon)^2 \f$ 
21  24 
if \f$x<\epsilon\f$. 
22  25 
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} 
...  ...  
41  44 
} 
42  45  
43  46 
/** 
44 
Retuns a positive function of the argument \f$x\f$ and sets a penalty for 

45 
\f$x<0\f$. The penalty should be added to the objective function. 

46 
\param x Argument, \f$x\f$. 

47 
\param eps Threshold, \f$\epsilon\f$, 

48 
a double constant containing the minimum allowed value of \f$x\f$. 

49 
\param _pen The penalty value \b incremented by \f$ 0.01(x\epsilon)^2 \f$ 

50 
if \f$x<\epsilon\f$. 

51 
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} 

52 
x\ge\epsilon & x\\ 

53 
x<\epsilon & \frac{\epsilon}{2x/\epsilon} 

54 
\end{array}\right.\f$ 

55 
\ingroup misc 

56 
*/ 

47 
\brief \copybrief posfun(const dvariable&, const double, const prevariable&) 

48 
\details \copydetails posfun(const dvariable&, const double, const prevariable&) 

49 
\ingroup misc 

50 
*/ 

57  51 
dvariable posfun(const dvariable &x, const double eps, const dvariable& _pen) 
58  52 
{ 
59  53 
dvariable& pen= (dvariable&) _pen; 
...  ...  
71  65  
72  66 
/** 
73  67 
Retuns a positive function of the argument \f$x\f$ and sets a penalty for 
74 
\f$x<0\f$. The penalty should be added to the objective function. 

75 
A more coersive version. 

68 
\f$x<0\f$. A more coersive version. 

69 
The penalty should be added to the objective function. 

70 
This function is intended to keep model state variables in the positive 

71 
domain to avoid mathematical errors. See Section 2.3 of the ADMB Manual. 

76  72 
\param x Argument, \f$x\f$. 
77  73 
\param eps Threshold, \f$\epsilon\f$, 
78  74 
a double constant containing the minimum allowed value of \f$x\f$. 
79  75 
\param _pen The penalty value \b incremented by \f$ 0.01(x\epsilon)^3 \f$ 
80  76 
if \f$x<\epsilon\f$. 
77 
The choice of a value for \f$\epsilon\f$ is model dependent, 

78 
but \f$10^{3}\f$ is sufficient for some applications. 

81  79 
\return \f$\left\{\begin{array} {r@{\quad:\quad}l} 
82  80 
x\ge\epsilon & x\\ 
83  81 
x<\epsilon & \frac{\epsilon}{1+x/\epsilon 
...  ...  
105  103 
} 
106  104  
107  105 
/** 
108 
Adjoint code for posfun; possibly not used. 

109 
*/ 

106 
\brief \copybrief dfposfun(const double&, const double) 

107 
\details \copydetails dfposfun(const double&, const double) 

108 
*/ 

110  109 
dvariable dfposfun(const prevariable&x,const double eps) 
111  110 
{ 
112  111 
if (x>=eps) 
Also available in: Unified diff