ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2lp7.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 <df1b2fun.h>
12 
13 #ifdef DEBUG
14  #include <cassert>
15  #include <climits>
16 #endif
17 
24  (const df1b2variable& ff)
25 {
26  //***********************************************************
27  //***********************************************************
32 
35  int num_local_re=0;
36  int num_local_fe=0;
37 
38 #ifdef DEBUG
39  assert(funnel_init_var::num_active_parameters <= INT_MAX);
40 #endif
42  ivector lfe_index(1,(int)funnel_init_var::num_active_parameters);
43 
44  for (int i=1;i<=(int)funnel_init_var::num_active_parameters;i++)
45  {
46  if (list(i,1)>xsize)
47  {
48  lre_index(++num_local_re)=i;
49  }
50  else if (list(i,1)>0)
51  {
52  lfe_index(++num_local_fe)=i;
53  }
54  }
55 
56  if (num_local_re > 0)
57  {
58  if (hesstype==3)
59  {
60  for (int i=1;i<=num_local_re;i++)
61  {
62  int lrei=lre_index(i);
63  int i1=list(lrei,1)-xsize;
64  int i2=list(lrei,2);
65  for (int j=1;j<=num_local_re;j++)
66  {
67  int lrej=lre_index(j);
68  int j1=list(lrej,1)-xsize;
69  int j2=list(lrej,2);
70  if (i1>=j1) (*bHess)(i1,j1)+=locy(i2).u_bar[j2-1];
71  }
72  }
73  }
74  else if (hesstype==4)
75  {
76  if (sparse_hessian_flag==0)
77  {
78  int* plre_indexi = lre_index.get_v() + 1;
79  for (int i=1;i<=num_local_re;i++)
80  {
81  int lrei = *plre_indexi;
82  ivector* plisti = &list(lrei);
83  int i1 = *(plisti->get_v() + 1) - xsize;
84  int i2 = *(plisti->get_v() + 2);
85 
86 
87  int* plre_indexj = lre_index.get_v() + 1;
88  for (int j=1;j<=num_local_re;j++)
89  {
90  int lrej = *plre_indexj;
91  ivector* plistj = &list(lrej);
92  int j1 = *(plistj->get_v() + 1) - xsize;
93  int j2 = *(plistj->get_v() + 2);
94  Hess(i1,j1)+=locy(i2).u_bar[j2-1];
95 
96  ++plre_indexj;
97  }
98 
99  ++plre_indexi;
100  }
101  }
102  else
103  {
104  for (int i=1;i<=num_local_re;i++)
105  {
106  int lrei=lre_index(i);
107  int i1=list(lrei,1)-xsize;
108  int i2=list(lrei,2);
109  for (int j=1;j<=num_local_re;j++)
110  {
111  int lrej=lre_index(j);
112  int j1=list(lrej,1)-xsize;
113  int j2=list(lrej,2);
114 
115  if (i1<=j1)
116  {
117  sparse_count++;
118  (*sparse_triplet2)((*sparse_iterator)(sparse_count))
119  +=locy(i2).u_bar[j2-1];
120  }
121  }
122  }
123  }
124  }
125  }
126 
127  // Now the adjoint code
128 
129  if (num_local_re > 0)
130  {
131  if (hesstype==3)
132  {
133  for (int i=1;i<=num_local_re;i++)
134  {
135  int lrei=lre_index(i);
136  int i1=list(lrei,1)-xsize;
137  int i2=list(lrei,2);
138  for (int j=1;j<=num_local_re;j++)
139  {
140  int lrej=lre_index(j);
141  int j1=list(lrej,1)-xsize;
142  int j2=list(lrej,2);
143  if (i1>=j1)
144  {
145  //(*bHess)(i1,j1)+=locy(i2).u_bar[j2-1];
146  locy(i2).get_u_bar_tilde()[j2-1]=(*bHessadjoint)(i1,j1);
147  }
148  }
149  }
150  }
151  else if (hesstype==4)
152  {
153  if (pmin->lapprox->sparse_hessian_flag==0)
154  {
155  for (int i=1;i<=num_local_re;i++)
156  {
157  int lrei=lre_index(i);
158  int i1=list(lrei,1)-xsize;
159  int i2=list(lrei,2);
160  for (int j=1;j<=num_local_re;j++)
161  {
162  int lrej=lre_index(j);
163  int j1=list(lrej,1)-xsize;
164  int j2=list(lrej,2);
165  {
166  //(*bHess)(i1,j1)+=locy(i2).u_bar[j2-1];
167  locy(i2).get_u_bar_tilde()[j2-1]=Hessadjoint(i1,j1);
168  }
169  }
170  }
171  }
172  else
173  {
174  dcompressed_triplet * vsparse_triplet_adjoint =
175  pmin->lapprox->vsparse_triplet_adjoint;
176  for (int i=1;i<=num_local_re;i++)
177  {
178  int lrei=lre_index(i);
179  int i1=list(lrei,1)-xsize;
180  int i2=list(lrei,2);
181  for (int j=1;j<=num_local_re;j++)
182  {
183  int lrej=lre_index(j);
184  int j1=list(lrej,1)-xsize;
185  int j2=list(lrej,2);
186  {
187  //(*bHess)(i1,j1)+=locy(i2).u_bar[j2-1];
188  //locy(i2).get_u_bar_tilde()[j2-1]=Hessadjoint(i1,j1);
189  if (i1<=j1)
190  {
191  //(*sparse_triplet2)((*sparse_iterator)(sparse_count_adjoint))
192  // +=locy(i2).u_bar[j2-1];
193  sparse_count_adjoint++;
194  locy(i2).get_u_bar_tilde()[j2-1]=
195  (*vsparse_triplet_adjoint)
196  ((*sparse_iterator)(sparse_count_adjoint));
197  }
198  }
199  }
200  }
201  }
202  }
203  }
204 
206  df1b2_gradcalc1();
207 
209  df1b2_gradcalc1();
210 
211  f1b2gradlist->reset();
218 
219 
220  for (int i=1;i<=num_local_fe;i++)
221  {
222  int lfei=lfe_index(i);
223  int i1=list(lfei,1);
224  //if (lfei - list(lfei,2))
225  // cout << lfei << " " << list(lfei,2) << endl;
226  local_dtemp(i1)+=*locy(lfei).get_u_tilde();
227 #if !defined(OPT_LIB)
228  int mmin=xadjoint.indexmin();
229  int mmax=xadjoint.indexmax();
230  if (i1<mmin || i1> mmax)
231  {
232  cerr << "this can't happen" << endl;
233  ad_exit(1);
234  }
235 #endif
236  }
237 
238  for (int i=1;i<=num_local_re;i++)
239  {
240  int i1=list(lre_index(i),1)-xsize;
241  int i2=list(lre_index(i),2);
242  uadjoint(i1)+=*locy(i2).get_u_tilde();
243  }
244 
245  f1b2gradlist->reset();
253  funnel_init_var::num_active_parameters=0;
255 }
void initialize(void)
Description not yet available.
Definition: df1b2f14.cpp:155
df1b2_gradlist * f1b2gradlist
Definition: df1b2glo.cpp:49
void set_dependent_variable(const df1b2variable &_x)
Description not yet available.
Definition: df1b2fn2.cpp:699
static void set_no_derivatives(void)
Definition: df1b2fun.h:760
Description not yet available.
Definition: imatrix.h:69
static int passnumber
Definition: df1b2fun.h:289
static int num_inactive_vars
Definition: df1b2fnl.h:66
exitptr ad_exit
Definition: gradstrc.cpp:53
void initialize(void)
Description not yet available.
Definition: df1b2f10.cpp:171
Description not yet available.
Definition: df1b2fun.h:266
fixed_smartlist nlist
Definition: df1b2fun.h:754
void initialize(void)
Description not yet available.
Definition: df1b2f13.cpp:158
int * get_v() const
Definition: ivector.h:114
prnstream & endl(prnstream &)
test_smartlist list
Definition: df1b2fun.h:753
Array of integers(int) with indexes from index_min to indexmax.
Definition: ivector.h:50
static unsigned int num_active_parameters
Definition: df1b2fnl.h:67
fixed_smartlist2 nlist3
Definition: df1b2fun.h:758
fixed_smartlist2 nlist2
Definition: df1b2fun.h:756
static imatrix * plist
Definition: df1b2fnl.h:69
Description not yet available.
Definition: fvar.hpp:9345
test_smartlist list3
Definition: df1b2fun.h:757
void do_separable_stuff_laplace_approximation_banded_adjoint(const df1b2variable &ff)
Description not yet available.
Definition: df1b2lp7.cpp:24
Description not yet available.
Definition: df1b2fun.h:373
Description not yet available.
static unsigned int num_vars
Definition: df1b2fnl.h:64
static init_df1b2vector * py
Definition: df1b2fnl.h:68
int indexmin(void) const
Definition: df1b2fun.h:388
void reset(void)
Description not yet available.
Definition: df1b2fn2.cpp:581
test_smartlist list2
Definition: df1b2fun.h:755
void df1b2_gradcalc1(void)
Description not yet available.
Definition: df1b2fun.cpp:145