ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_ma6.cpp
Go to the documentation of this file.
1 
9 #include "fvar.hpp"
10 
12 
18  const imatrix& _missflags)
19  {
20  dvar_matrix& v1 = (dvar_matrix&) (_v1);
21  imatrix& missflags=(imatrix&) (_missflags);
22  int mmin=v1(v1.indexmin()).indexmin();
23  int mmax=v1(v1.indexmin()).indexmax();
24  dvar_matrix tmp(mmin,mmax,mmin,mmax);
25  int rmin=v1.indexmin();
26  int rmax=v1.indexmax();
27  int nobs=rmax-rmin+1;
28 
29  tmp.initialize();
30  for (int ii=rmin; ii<=rmax; ii++)
31  {
32  for (int i=mmin; i<=mmax; i++)
33  {
34  if (!missflags(ii,i))
35  {
36  for (int j=mmin; j<=mmax; j++)
37  {
38  if (!missflags(ii,j))
39  {
40  tmp.elem_value(i,j)+=v1.elem_value(ii,i)*v1.elem_value(ii,j);
41  }
42  }
43  }
44  }
45  }
46  for (int i=mmin; i<=mmax; i++)
47  {
48  for (int j=mmin; j<=mmax; j++)
49  {
50  tmp.elem_value(i,j)/=nobs;
51  }
52  }
53 
56 
58  fp->save_imatrix_value(missflags);
59  fp->save_imatrix_position(missflags);
60  fp->save_int_value(nobs);
62  fp->save_dvar_matrix_value(v1);
66  return(tmp);
67  }
68 
74 {
76 
79  dmatrix v1=fp->restore_dvar_matrix_value(v1pos);
82  int nobs=fp->restore_int_value();
84  imatrix missflags=fp->restore_imatrix_value(mfpos);
86  int mmin=v1(v1.indexmin()).indexmin();
87  int mmax=v1(v1.indexmin()).indexmax();
88  int rmin=v1.indexmin();
89  int rmax=v1.indexmax();
90 
91  dmatrix dfv1(rmin,rmax,mmin,mmax);
92  dfv1.initialize();
93  for (int i=mmin; i<=mmax; i++)
94  {
95  for (int j=mmin; j<=mmax; j++)
96  {
97  //tmp.elem_value(i,j)/=nobs;
98  dftmp(i,j)/=nobs;
99  }
100  }
101  for (int ii=rmin; ii<=rmax; ii++)
102  {
103  for (int i=mmin; i<=mmax; i++)
104  {
105  if (!missflags(ii,i))
106  {
107  for (int j=mmin; j<=mmax; j++)
108  {
109  if (!missflags(ii,j))
110  {
111  //tmp.elem_value(i,j)+=v1.elem_value(ii,i)*v1.elem_value(ii,j);
112  dfv1(ii,i)+=dftmp(i,j)*v1(ii,j);
113  dfv1(ii,j)+=dftmp(i,j)*v1(ii,i);
114  }
115  }
116  }
117  }
118  }
119  dfv1.save_dmatrix_derivatives(v1pos);
120 }
121 
122 void dfempirical_covarv(void);
123 
129  {
130  int mmin=v1(v1.indexmin()).indexmin();
131  int mmax=v1(v1.indexmin()).indexmax();
132  dvar_matrix tmp(mmin,mmax,mmin,mmax);
133  int rmin=v1.indexmin();
134  int rmax=v1.indexmax();
135 
136  tmp.initialize();
137  int nobs=rmax-rmin+1;
138  for (int ii=rmin; ii<=rmax; ii++)
139  {
140  for (int i=mmin; i<=mmax; i++)
141  {
142  for (int j=mmin; j<=mmax; j++)
143  {
144  tmp.elem_value(i,j)+=v1.elem_value(ii,i)*v1.elem_value(ii,j);
145  }
146  }
147  }
148  for (int i=mmin; i<=mmax; i++)
149  {
150  for (int j=mmin; j<=mmax; j++)
151  {
152  tmp.elem_value(i,j)/=double(nobs);
153  }
154  }
155 
158 
160  fp->save_dvar_matrix_position(tmp);
161  fp->save_dvar_matrix_value(v1);
165 
166  return(tmp);
167  }
168 
174 {
176 
179  dmatrix v1=fp->restore_dvar_matrix_value(v1pos);
183  int mmin=v1(v1.indexmin()).indexmin();
184  int mmax=v1(v1.indexmin()).indexmax();
185  int rmin=v1.indexmin();
186  int rmax=v1.indexmax();
187 
188  dmatrix dfv1(rmin,rmax,mmin,mmax);
189  dfv1.initialize();
190  int nobs=rmax-rmin+1;
191  for (int i=mmin; i<=mmax; i++)
192  {
193  for (int j=mmin; j<=mmax; j++)
194  {
195  //tmp.elem_value(i,j)/=double(nobs);
196  dftmp(i,j)/=double(nobs);
197  }
198  }
199  for (int ii=rmin; ii<=rmax; ii++)
200  {
201  for (int i=mmin; i<=mmax; i++)
202  {
203  for (int j=mmin; j<=mmax; j++)
204  {
205  //tmp.elem_value(i,j)+=v1.elem_value(ii,i)*v1.elem_value(ii,j);
206  dfv1(ii,i)+=dftmp(i,j)*v1(ii,j);
207  dfv1(ii,j)+=dftmp(i,j)*v1(ii,i);
208  }
209  }
210  }
211  dfv1.save_dmatrix_derivatives(v1pos);
212 }
213 
214 void dfouter_prodvv(void);
215 
221 {
222  int imin = v1.indexmin();
223  int imax = v1.indexmax();
224  int jmin = v2.indexmin();
225  int jmax = v2.indexmax();
226 
227  dvar_matrix tmp(imin, imax, jmin, jmax);
228 
229  dvar_vector* ptmpi = &tmp(imin);
230  double_and_int* pv1i = v1.va + imin;
231  for (int i = imin; i <= imax; ++i)
232  {
233  double_and_int* ptmpij = ptmpi->va + jmin;
234  double_and_int* pv2j = v2.va + jmin;
235  for (int j = jmin; j <= jmax; ++j)
236  {
237  ptmpij->x = pv1i->x * pv2j->x;
238 
239  ++ptmpij;
240  ++pv2j;
241  }
242  ++ptmpi;
243  ++pv1i;
244  }
245 
248 
250  fp->save_dvar_matrix_position(tmp);
251  fp->save_dvar_vector_value(v1);
253  fp->save_dvar_vector_value(v2);
256  GRAD_STACK1->set_gradient_stack(dfouter_prodvv);
257 
258  return tmp;
259 }
260 
265 void dfouter_prodvv(void)
266 {
268 
277 
278  int imin = v1.indexmin();
279  int imax = v1.indexmax();
280  int jmin = v2.indexmin();
281  int jmax = v2.indexmax();
282  dvector dfv1(imin, imax);
283  dvector dfv2(jmin, jmax);
284  dfv1.initialize();
285  dfv2.initialize();
286 
287  double* pv1i = v1.get_v() + imin;
288  double* pdfv1i = dfv1.get_v() + imin;
289  dvector* pdftmpi = &dftmp(imin);
290  for (int i = imin; i <= imax; ++i)
291  {
292  double* pv2j = v2.get_v() + jmin;
293  double* pdfv2j = dfv2.get_v() + jmin;
294  double* pdftmpij = pdftmpi->get_v() + jmin;
295  for (int j = jmin; j <= jmax; ++j)
296  {
297  //tmp.elem_value(i,j)=v1.elem_value(i)*v2.elem_value(j);
298  *pdfv1i += *pdftmpij * *pv2j;
299  *pdfv2j += *pdftmpij * *pv1i;
300 
301  ++pv2j;
302  ++pdfv2j;
303  ++pdftmpij;
304  }
305  ++pv1i;
306  ++pdfv1i;
307  ++pdftmpi;
308  }
309  dfv1.save_dvector_derivatives(v1pos);
310  dfv2.save_dvector_derivatives(v2pos);
311 }
312 
320 {
323 
324  int imin = v1.indexmin();
325  int imax = v1.indexmax();
326  int jmin = v2.indexmin();
327  int jmax = v2.indexmax();
328 
329  dvar_matrix tmp(imin, imax, jmin, jmax);
330 
331  dvar_vector* ptmpi = &tmp(imin);
332  double* pv1i = v1.get_v() + imin;
333  for (int i = imin; i <= imax; ++i)
334  {
335  for (int j = jmin; j <= jmax; ++j)
336  {
337  ptmpi->elem(j) = *pv1i * v2.elem(j);
338  }
339  ++ptmpi;
340  ++pv1i;
341  }
343  return tmp;
344 }
352 {
355 
356  int imin = v1.indexmin();
357  int imax = v1.indexmax();
358  int jmin = v2.indexmin();
359  int jmax = v2.indexmax();
360 
361  dvar_matrix tmp(imin, imax, jmin, jmax);
362 
363  dvar_vector* ptmpi = &tmp(imin);
364  for (int i = imin; i <= imax; ++i)
365  {
366  double* pv2j = v2.get_v() + jmin;
367  for (int j = jmin; j <= jmax; ++j)
368  {
369  ptmpi->elem(j) = v1.elem(i) * *pv2j;
370  ++pv2j;
371  }
372 
373  ++ptmpi;
374  }
376 
377  return(tmp);
378 }
Description not yet available.
Definition: fvar.hpp:920
Description not yet available.
Definition: imatrix.h:69
double & elem_value(int i, int j)
Definition: fvar.hpp:2676
Description not yet available.
Definition: imatrix.h:48
void save_imatrix_position(const imatrix &m)
Definition: cmpdif9.cpp:39
Vector of double precision numbers.
Definition: dvector.h:50
int indexmin() const
Get minimum valid index.
Definition: dvector.h:199
int indexmin() const
Definition: fvar.hpp:2917
dmatrix restore_dvar_matrix_derivatives(const dvar_matrix_position &_pos)
Description not yet available.
Definition: cmpdif6.cpp:178
void initialize(void)
Zero initialize allocated dvar_matrix, then saves adjoint function and position data.
Definition: fvar_ma7.cpp:48
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
prevariable elem(int i)
Definition: fvar.hpp:2221
imatrix restore_imatrix_value(const imatrix_position &mpos)
Definition: cmpdif9.cpp:89
ADMB variable vector.
Definition: fvar.hpp:2172
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
void save_int_value(int x)
Definition: cmpdif8.cpp:108
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
dmatrix restore_dvar_matrix_value(const dvar_matrix_position &mpos)
Definition: cmpdif5.cpp:74
void save_dvar_vector_value(const dvar_vector &v)
Definition: cmpdif4.cpp:106
dvar_vector_position restore_dvar_vector_position()
Definition: cmpdif4.cpp:69
void RETURN_ARRAYS_INCREMENT()
Definition: gradstrc.cpp:478
dvar_matrix empirical_covariance(const dvar_matrix &v1)
Description not yet available.
Definition: fvar_ma6.cpp:128
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 save_dmatrix_derivatives(const dvar_matrix_position &pos) const
Description not yet available.
Definition: cmpdif5.cpp:285
static _THREAD gradient_structure * _instance
dmatrix outer_prod(const dvector &v1, const dvector &v2)
Description not yet available.
Definition: dmat23.cpp:17
int restore_int_value()
Definition: cmpdif8.cpp:201
Description not yet available.
Definition: fvar.hpp:2819
void initialize(void)
Initialze all elements of dvector to zero.
Definition: dvect5.cpp:10
void dfouter_prodvv(void)
Description not yet available.
Definition: fvar_ma6.cpp:265
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
void dfempirical_covarv(void)
Description not yet available.
Definition: fvar_ma6.cpp:173
int indexmax() const
Definition: fvar.hpp:2921
int indexmin() const
Definition: fvar.hpp:2287
void save_dvar_vector_position(const dvar_vector &v)
Definition: cmpdif3.cpp:214
dvar_matrix_position restore_dvar_matrix_position()
Definition: cmpdif6.cpp:114
static _THREAD DF_FILE * fp
int indexmax(void) const
Definition: fvar.hpp:2572
void save_dvar_matrix_position(const dvar_matrix &m)
Definition: cmpdif5.cpp:345
void dfempirical_covarv_partial(void)
Description not yet available.
Definition: fvar_ma6.cpp:73
Class definition of matrix with derivitive information .
Definition: fvar.hpp:2480
Stores the adjoint gradient data that will be processed by gradcalc.
void save_dvar_matrix_value(const dvar_matrix &m)
Definition: cmpdif4.cpp:252
void RETURN_ARRAYS_DECREMENT()
Definition: gradstrc.cpp:511
double_and_int * va
Definition: fvar.hpp:2175
void save_imatrix_value(const imatrix &m)
Definition: cmpdif9.cpp:24
static _THREAD grad_stack * GRAD_STACK1
class for things related to the gradient structures, including dimension of arrays, size of buffers, etc.
imatrix_position restore_imatrix_position()
Definition: cmpdif9.cpp:63
void initialize(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat7.cpp:12
double *& get_v(void)
Definition: dvector.h:148
int indexmin(void) const
Definition: fvar.hpp:2568
int indexmax() const
Definition: fvar.hpp:2292
double x
&lt; value of the variable
Definition: fvar.hpp:195
Description not yet available.
Definition: fvar.hpp:4843