ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_a44.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 void DF_dvsquare(void);
14 
20 {
21  //dvector cv1=value(v1);
22  int min = v1.indexmin();
23  int max = v1.indexmax();
24 
25  dvar_vector vtmp(min, max);
26 
27  double_and_int* pvtmp = vtmp.va + min;
28  double_and_int* pv1 = v1.va + min;
29  for (int i = min; i <= max; ++i)
30  {
31  //double x = v1.elem_value(i);
32  double x = pv1->x;
33  //vtmp.elem_value(i) = x * x;
34  pvtmp->x = x * x;
35 
36  ++pv1;
37  ++pvtmp;
38  }
39 
42  save_identifier_string("sddd");
43  fp->save_dvar_vector_value(v1);
45  fp->save_dvar_vector_position(vtmp);
47  GRAD_STACK1->set_gradient_stack(DF_dvsquare);
48  return vtmp;
49 }
50 
55 void DF_dvsquare(void)
56 {
58 
59  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
66 
67  int min = dfvtmp.indexmin();
68  int max = dfvtmp.indexmax();
69  dvector dfv1(min, max);
70 
71  double* pv1 = v1.get_v() + min;
72  double* pdfv1 = dfv1.get_v() + min;
73  double* pdfvtmp = dfvtmp.get_v() + min;
74  for (int i = min; i <= max; ++i)
75  {
76  //vtmp.elem(i)=sin(value(v1.elem(i))));
77  //double x=v1.elem(i);
78  double x = *pv1;
79  //dfv1(i)=dfvtmp(i)*2*x;
80  *pdfv1 = *pdfvtmp * 2.0 * x;
81  ++pv1;
82  ++pdfvtmp;
83  ++pdfv1;
84  }
85  dfv1.save_dvector_derivatives(v1pos);
86  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
87 }
88 
89 
90 void DF_dvcube(void);
91 
97 {
98  //dvector cv1=value(v1);
99 
100  dvar_vector vtmp(v1.indexmin(),v1.indexmax());
101  for (int i=v1.indexmin();i<=v1.indexmax();i++)
102  {
103  double x=v1.elem_value(i);
104  vtmp.elem_value(i)=x*x*x;
105  }
106 
109  save_identifier_string("sssd");
110  fp->save_dvar_vector_value(v1);
112  fp->save_dvar_vector_position(vtmp);
113  save_identifier_string("tee");
115  return vtmp;
116 }
117 
122 void DF_dvcube(void)
123 {
125 
126  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
132  verify_identifier_string("sssd");
133  dvector dfv1(dfvtmp.indexmin(),dfvtmp.indexmax());
134  for (int i=dfvtmp.indexmin();i<=dfvtmp.indexmax();i++)
135  {
136  //vtmp.elem(i)=sin(value(v1.elem(i))));
137  double x=v1.elem(i);
138  dfv1(i)=dfvtmp(i)*3*x*x;
139  }
140  dfv1.save_dvector_derivatives(v1pos);
141  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
142 }
143 
144 void DF_dvfourth(void);
145 
151 {
152  //dvector cv1=value(v1);
153 
154  dvar_vector vtmp(v1.indexmin(),v1.indexmax());
155  for (int i=v1.indexmin();i<=v1.indexmax();i++)
156  {
157  double x=v1.elem_value(i);
158  double x2=x*x;
159  vtmp.elem_value(i)=x2*x2;
160  }
161 
164  save_identifier_string("ssf");
165  fp->save_dvar_vector_value(v1);
167  fp->save_dvar_vector_position(vtmp);
168  save_identifier_string("gee");
170  return vtmp;
171 }
172 
177 void DF_dvfourth(void)
178 {
180 
181  // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
188  dvector dfv1(dfvtmp.indexmin(),dfvtmp.indexmax());
189  for (int i=dfvtmp.indexmin();i<=dfvtmp.indexmax();i++)
190  {
191  //vtmp.elem(i)=sin(value(v1.elem(i))));
192  double x=v1.elem(i);
193  dfv1(i)=dfvtmp(i)*4*x*x*x;
194  }
195  dfv1.save_dvector_derivatives(v1pos);
196  //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
197 }
Description not yet available.
Definition: fvar.hpp:920
double & elem(int i)
Definition: dvector.h:152
double & elem_value(int i)
Definition: fvar.hpp:2226
#define x
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
void DF_dvsquare(void)
Description not yet available.
Definition: fvar_a44.cpp:55
void DF_dvfourth(void)
Description not yet available.
Definition: fvar_a44.cpp:177
void save_dvector_derivatives(const dvar_vector_position &pos) const
Puts the derivative values in a dvector into a dvar_vector&#39;s guts.
Definition: cmpdif5.cpp:212
Description not yet available.
Definition: fvar.hpp:4814
d3_array cube(const d3_array &m)
Description not yet available.
Definition: d3arr5.cpp:17
ADMB variable vector.
Definition: fvar.hpp:2172
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
Holds the data for the prevariable class.
Definition: fvar.hpp:191
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
void save_dvar_vector_value(const dvar_vector &v)
Definition: cmpdif4.cpp:106
dvar_vector_position restore_dvar_vector_position()
Definition: cmpdif4.cpp:69
#define min(a, b)
Definition: cbivnorm.cpp:188
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void DF_dvcube(void)
Description not yet available.
Definition: fvar_a44.cpp:122
static _THREAD gradient_structure * _instance
int save_identifier_string(const char *)
Writes a gradient stack verification string.
Definition: cmpdif2.cpp:315
dvector restore_dvar_vector_value(const dvar_vector_position &tmp)
Restores the size, address, and value information for a dvar_vector.
Definition: cmpdif4.cpp:227
int indexmin() const
Definition: fvar.hpp:2287
void save_dvar_vector_position(const dvar_vector &v)
Definition: cmpdif3.cpp:214
static _THREAD DF_FILE * fp
Stores the adjoint gradient data that will be processed by gradcalc.
dvector restore_dvar_vector_derivatives(const dvar_vector_position &tmp)
Description not yet available.
Definition: cmpdif5.cpp:150
double_and_int * va
Definition: fvar.hpp:2175
static _THREAD grad_stack * GRAD_STACK1
#define max(a, b)
Definition: cbivnorm.cpp:189
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
double *& get_v(void)
Definition: dvector.h:148
int indexmax() const
Definition: fvar.hpp:2292
double square(const double value)
Return square of value; constant object.
Definition: d3arr4.cpp:16
double fourth(const double m)
Fourth power of a number; constant objects.
Definition: dvector.cpp:704
double x
&lt; value of the variable
Definition: fvar.hpp:195