ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
posfunv.cpp
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Author: David Fournier
5  * Copyright (c) 2008-2012 Regents of the University of California
6  */
7 
12 #include <fvar.hpp>
13 
32 dvariable posfun(const dvariable &x, const double eps, const prevariable& _pen)
33 {
34  dvariable& pen= (dvariable&) _pen;
35  if (x>=eps)
36  {
37  return x;
38  }
39  else
40  {
41  //dvariable y=1.0-x/eps;
42  pen+=.01*square(x-eps);
43  return eps/(2-x/eps);
44  }
45 }
46 
52 dvariable posfun(const dvariable &x, const double eps, const dvariable& _pen)
53 {
54  dvariable& pen= (dvariable&) _pen;
55  if (x>=eps)
56  {
57  return x;
58  }
59  else
60  {
61  //dvariable y=1.0-x/eps;
62  pen+=.01*square(x-eps);
63  return eps/(2-x/eps);
64  }
65 }
66 
88 dvariable posfun2(const dvariable &x, const double eps, const prevariable& _pen)
89 {
90  dvariable& pen= (dvariable&) _pen;
91  if (x>=eps)
92  {
93  return x;
94  }
95  else
96  {
97  dvariable y=eps-x;
98  dvariable tmp=y/eps;
99  dvariable tmp2=tmp*tmp;
100  dvariable tmp3=tmp2*tmp;
101  pen+=.01*cube(tmp3);
102  return eps/(1.0+tmp+tmp2+tmp3);
103  }
104 }
105 
110 dvariable dfposfun(const prevariable&x,const double eps)
111 {
112  if (x>=eps)
113  {
114  return 1;
115  }
116  else
117  {
118  //double z=eps/(2-x/eps);
119  dvariable dfx=1.0/square(2-x/eps);
120  return dfx;
121  }
122 }
Base class for dvariable.
Definition: fvar.hpp:1315
double dfposfun(const double &x, const double eps)
Adjoint code for posfun; possibly not used.
Definition: posfunc.cpp:19
#define x
d3_array cube(const d3_array &m)
Description not yet available.
Definition: d3arr5.cpp:17
dvar_vector posfun(const dvar_vector &x, double eps, const prevariable &pen)
Description not yet available.
Definition: fvar_a62.cpp:17
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
double eps
Definition: ftweak.cpp:13
dvariable posfun2(const dvariable &x, const double eps, const prevariable &pen)
Retuns a positive function of the argument and sets a penalty for .
Definition: posfunv.cpp:88
double square(const double value)
Return square of value; constant object.
Definition: d3arr4.cpp:16
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518