ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fvar_m41.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 void dfbltsolve(void);
13 
19  const dvar_vector &v)
20 {
21  int bw=m.bandwidth();
22  int imin=m.indexmin();
23  int imax=m.indexmax();
24  dvar_vector x(imin,imax);
25  x.elem_value(imin)=v.elem_value(imin)/m.elem_value(imin,imin);
26  for (int i=imin+1;i<=imax;i++)
27  {
28  int jmin=admax(imin,i-bw+1);
29  double ssum=0.0;
30  for (int j=jmin;j<=i-1;j++)
31  {
32  ssum+=m.elem_value(i,j)*x.elem_value(j);
33  }
34  x.elem_value(i)=(v.elem_value(i)-ssum)/m.elem_value(i,i);
35  }
36 
46  GRAD_STACK1->set_gradient_stack(dfbltsolve);
47 
48  return x;
49 }
50 
51 /*
52 dvar_vector solve(const banded_lower_triangular_dvar_matrix& m,
53  const dvar_vector &v, dvariable& lndet)
54 {
55  int bw=m.bandwidth();
56  int imin=m.indexmin();
57  int imax=m.indexmax();
58  dvar_vector x(imin,imax);
59  value(x(imin))=value(v(1))/value(m(1,1));
60  for (int i=2;i<=imax;i++)
61  {
62  int jmin=admax(1,i-bw+1);
63  double ssum=0.0;
64  for (int j=jmin;j<=i-1;j++)
65  {
66  ssum+=value(m(i,j))*value(x(j));
67  }
68  value(x(i))=(value(v(i))-ssum)/value(m(i,i));
69  }
70  gradient_structure* gs = gradient_structure::get();
71  DF_FILE* fp = gs->fp;
72  save_identifier_string("rt");
73  m.save_dvar_matrix_value();
74  m.save_dvar_matrix_position();
75  v.save_dvar_vector_value(fp);
76  v.save_dvar_vector_position(fp);
77  x.save_dvar_vector_position(fp);
78  save_identifier_string("ww");
79  gs->GRAD_STACK1->set_gradient_stack(dfbltsolve);
80  return x;
81 }
82 */
83 
88 void dfbltsolve(void)
89 {
91 
100  dvector dfx=
102 
103  int bw=m.bandwidth();
104  int imin=m.indexmin();
105  int imax=m.indexmax();
106 
107  banded_lower_triangular_dmatrix dfm(imin,imax,bw);
108  dvector x(imin,imax);
109  dvector dfv(imin,imax);
110  dfm.initialize();
111  dfv.initialize();
112  x(imin)=v(1)/m(1,1);
113  dvector dfsum(imin,imax);
114  dfsum.initialize();
115  dvector ssum(imin,imax);
116  ssum.initialize();
117  int i;
118  for (i=2;i<=imax;i++)
119  {
120  int jmin=admax(1,i-bw+1);
121  for (int j=jmin;j<=i-1;j++)
122  {
123  ssum(i)+=m(i,j)*x(j);
124  }
125  x(i)=(v(i)-ssum(i))/m(i,i);
126  }
127 
128  for (i=imax;i>=2;i--)
129  {
130  int jmin=admax(1,i-bw+1);
131  //x(i)=(v(i)-ssum(i))/m(i,i);
132  dfv(i)+=dfx(i)/m(i,i);
133  dfsum(i)-=dfx(i)/m(i,i);
134  dfm(i,i)-=dfx(i)*(v(i)-ssum(i))/(m(i,i)*m(i,i));
135  dfx(i)=0.0;
136  for (int j=i-1;j>=jmin;j--)
137  {
138  //ssum(i)+=m(i,j)*x(j);
139  dfm(i,j)+=dfsum(i)*x(j);
140  dfx(j)+=dfsum(i)*m(i,j);
141  }
142  }
143  //x(imin)=v(1)/m(1,1);
144  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
145  //dfm(imax,imax)=0.0;
146  // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
147  //x.elem_value(imin)=v.elem_value(imin)/m.elem_value(imin,imin);
148  dfv(imin)+=dfx(imin)/m(imin,imin);
149  dfm(imin,imin)-=dfx(imin)*v(imin)/(m(imin,imin)*m(imin,imin));
150  dfx(imin)=0.0;
151 
152  dfm.save_dmatrix_derivatives(mpos);
153  dfv.save_dvector_derivatives(vpos);
154 }
Description not yet available.
Definition: fvar.hpp:920
int admax(int i, int j)
Definition: fvar.hpp:8979
double & elem_value(int i)
Definition: fvar.hpp:2226
void save_dmatrix_derivatives(const dvar_matrix_position &) const
Description not yet available.
Definition: cmpdif11.cpp:144
#define x
Vector of double precision numbers.
Definition: dvector.h:50
Description not yet available.
Definition: fvar.hpp:8190
int bandwidth(void) const
Definition: fvar.hpp:8127
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
double & elem_value(int i, int j)
Definition: fvar.hpp:8246
void initialize(void)
Description not yet available.
Definition: dmat41.cpp:29
ADMB variable vector.
Definition: fvar.hpp:2172
void verify_identifier_string(const char *)
Verifies gradient stack string.
Definition: cmpdif3.cpp:149
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
dvector solve(const dmatrix &aa, const dvector &z)
Solve a linear system using LU decomposition.
Definition: dmat34.cpp:46
void save_dvar_vector_value(const dvar_vector &v)
Definition: cmpdif4.cpp:106
dvar_vector_position restore_dvar_vector_position()
Definition: cmpdif4.cpp:69
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Description not yet available.
Definition: fvar.hpp:8120
void dfbltsolve(void)
Description not yet available.
Definition: fvar_m41.cpp:88
int indexmin(void) const
Definition: fvar.hpp:8131
void initialize(void)
Initialze all elements of dvector to zero.
Definition: dvect5.cpp:10
int indexmax(void) const
Definition: fvar.hpp:8135
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 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
void save_dvar_matrix_position(const dvar_matrix &m)
Definition: cmpdif5.cpp:345
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
void save_dvar_matrix_value(const dvar_matrix &m)
Definition: cmpdif4.cpp:252
static _THREAD grad_stack * GRAD_STACK1
banded_lower_triangular_dmatrix restore_banded_lower_triangular_dvar_matrix_value(const dvar_matrix_position &mpos)
Description not yet available.
Definition: cmpdif11.cpp:78
Description not yet available.
Definition: fvar.hpp:4843