ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_fn.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  */
11 #include "fvar.hpp"
12 
13 #ifdef __TURBOC__
14  #pragma hdrstop
15  #include <iostream.h>
16  #include <iomanip.h>
17 #endif
18 
19 #ifdef __ZTC__
20  #include <iostream.hpp>
21  #include <iomanip.hpp>
22 #endif
23 
24 #include <stdio.h>
25 #include <math.h>
26 
31 prevariable& pow(const prevariable& v1, const double u)
32 {
33 #ifndef OPT_LIB
34  if (v1.v->x == 0)
35  {
36  cerr << "Error -- base = 0 in function"
37  " prevariable& pow(const prevariable& v1, const double u)" << endl;
38  }
39 #endif
41 
42  double x=::pow(v1.v->x,u-1);
43  double y=x* v1.v->x;
44 
45  RETURN_PTR->v->x=y;
47  &(RETURN_PTR->v->x), &(v1.v->x), u * x );
48 
49  return *RETURN_PTR;
50 }
51 
57  {
58  *this = 0.0;
59  }
60 
66 {
68 
69  RETURN_PTR->v->x=::sin(v1.v->x);
71  &(RETURN_PTR->v->x), &(v1.v->x), ::cos(v1.v->x) );
72 
73  return *RETURN_PTR;
74 }
75 
81 {
83 
84  double tmp=v1.v->x;
85 
86  //gradient_structure::RETURN_PTR->v->x=atan(tmp)/1.5708;
87  RETURN_PTR->v->x=::atan(tmp)/2.8;
88 
90  &(RETURN_PTR->v->x), &(v1.v->x),
91  // 1./((1.+tmp*tmp)*1.5708));
92  1./((1.+tmp*tmp)*2.8));
93  return *RETURN_PTR;
94 }
95 
96 
106 {
108 
109  double tmp=v1.v->x;
110  RETURN_PTR->v->x=fabs(tmp);
112  default_evaluation,&(RETURN_PTR->v->x),
113  &(v1.v->x), tmp >= 0.0 ? 1.0 : -1.0);
114 
115  return *RETURN_PTR;
116 }
117 
126 {
127  #define cutoff 0.001 // h
128  #define cutoff2 0.000001
129  double a = 2./cutoff; // 2.0/h
130  double b = 1./cutoff2; // 1.0/(h*h)
131 
133 
134  double tmp1=v1.v->x;
135  double tmp=::fabs(tmp1);
136 
137  if (tmp > cutoff)
138  {
139  RETURN_PTR->v->x=tmp;
140  if (tmp1 >=0)
141  {
143  default_evaluation,&(RETURN_PTR->v->x),
144  &(v1.v->x),1);
145  }
146  else
147  {
149  default_evaluation,&(RETURN_PTR->v->x),
150  &(v1.v->x),-1);
151  }
152  }
153  else
154  {
155  double t2 = tmp * tmp;
156  if (tmp1 >=0)
157  {
158  RETURN_PTR->v->x=t2*(a-b*tmp1);
160  default_evaluation,&(RETURN_PTR->v->x),
161  &(v1.v->x),tmp*(2*a-3*b*tmp1) );
162  }
163  else
164  {
165  RETURN_PTR->v->x=t2*(a+b*tmp1);
167  default_evaluation,&(RETURN_PTR->v->x),
168  &(v1.v->x),tmp1*(2*a+3*b*tmp1));
169  }
170  }
171  return *RETURN_PTR;
172 }
173 
179 {
181 
182  RETURN_PTR->v->x=::cos(v1.v->x);
184  default_evaluation,&(RETURN_PTR->v->x),
185  &(v1.v->x),-::sin(v1.v->x) );
186 
187  return *RETURN_PTR;
188 }
189 
195 {
197 
198  RETURN_PTR->v->x=::log(v1.v->x);
200  default_evaluation,&(RETURN_PTR->v->x),
201  &(v1.v->x),1./(v1.v->x) );
202 
203  return *RETURN_PTR;
204 }
205 
211 {
213 
214  RETURN_PTR->v->x=::log10(v1.v->x);
216  &(RETURN_PTR->v->x),&(v1.v->x),
217  1./(v1.v->x)/2.3025851);
218 
219  return *RETURN_PTR;
220 }
Base class for dvariable.
Definition: fvar.hpp:1315
double sigmoid(const double v1)
Returns computed sigmoid value at v1.
Definition: dvar.cpp:31
dvector log10(const dvector &vec)
Returns dvector with the common (base-10) logarithm of vec.
Definition: dvect6.cpp:273
#define x
void initialize(void)
Description not yet available.
Definition: fvar_fn.cpp:56
#define cutoff2
df1_one_variable atan(const df1_one_variable &x)
Definition: df11fun.cpp:312
d3_array sin(const d3_array &arr3)
Returns d3_array results with computed sin from elements in arr3.
Definition: d3arr2a.cpp:43
df1_two_variable fabs(const df1_two_variable &x)
Definition: df12fun.cpp:891
void set_gradient_stack(void(*func)(void), double *dep_addr, double *ind_addr1=NULL, double mult1=0, double *ind_addr2=NULL, double mult2=0)
Description not yet available.
Definition: fvar.hpp:1045
double sfabs(const double v1)
Description not yet available.
Definition: dvect14.cpp:20
prnstream & endl(prnstream &)
static dvariable * next_RETURN_PTR()
Definition: gradstrc.cpp:457
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void default_evaluation(void)
Description not yet available.
Definition: def_eval.cpp:61
double_and_int * v
pointer to the data
Definition: fvar.hpp:1333
#define cutoff
d3_array cos(const d3_array &arr3)
Returns d3_array results with computed cos from elements in arr3.
Definition: d3arr2a.cpp:58
static _THREAD grad_stack * GRAD_STACK1
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13
double x
&lt; value of the variable
Definition: fvar.hpp:195
d3_array pow(const d3_array &m, int e)
Description not yet available.
Definition: d3arr6.cpp:17