ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dmat37.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 
18  const int& _ierr)
19 {
20  int & ierr=(int&)_ierr;
23  int mmin=m.indexmin();
24  m.shift(1);
25  v.shift(1);
27  dvector w=solve_trans(C,solve(C,v));
28  m.shift(mmin);
29  w.shift(mmin);
30  v.shift(mmin);
31  return w;
32 }
33 
39 {
40  int ierr=0;
41  return solve(m,v,ierr);
42 }
43 
49  const int& _ierr)
50 {
51  int& ierr=(int&) _ierr;
52  ierr=0;
53  dmatrix tmp=trans(n);
55  int mmin=tmp.indexmin();
56  int mmax=tmp.indexmax();
57  dmatrix w(mmin,mmax);
58  for (int i=mmin;i<=mmax;i++)
59  {
60  w(i)=solve_trans(C,solve(C,tmp(i)));
61  }
62  return trans(w);
63 }
64 
70 {
71  int ierr=0;
72  return solve(m,n,ierr);
73 }
74 
80 {
81  int bw=m.bandwidth();
82  int imin=m.indexmin();
83  int imax=m.indexmax();
84  if (v.indexmin() != imin || v.indexmax() != imax)
85  {
86  cerr << " Incompatible vector and matrix sizes in solve " << endl;
87  ad_exit(1);
88  }
89  dvector x(imin,imax);
90  x(imin)=v(imin)/m(imin,imin);
91  for (int i=imin;i<=imax;i++)
92  {
93  int jmin=admax(imin,i-bw+1);
94  double ssum=0.0;
95  for (int j=jmin;j<=i-1;j++)
96  {
97  ssum+=m(i,j)*x(j);
98  }
99  x(i)=(v(i)-ssum)/m(i,i);
100  }
101  return x;
102 }
103 
109 {
110  int mmin=M.indexmin();
111  int mmax=M.indexmax();
112  int bw=M.bandwidth();
113 
114  if (y.indexmin() !=mmin || y.indexmax() !=mmax)
115  {
116  cerr << "incompatible size in solve_trans" << endl;
117  ad_exit(1);
118  }
119  dvector x(mmin,mmax);
120  int i,j;
121 
122  for (i=mmax;i>=mmin;i--)
123  {
124  double sum=0.0;
125  int jmax=admin(mmax,i+bw-1);
126  for (j=i+1;j<=jmax;j++)
127  {
128  sum+=M(j,i)*x(j);
129  }
130  x(i)=(y(i)-sum)/M(i,i);
131  }
132 
133  return x;
134 }
135 
141 {
142  int mmin=M.indexmin();
143  int mmax=M.indexmax();
144 
145  if (y.indexmin() !=mmin || y.indexmax() !=mmax)
146  {
147  cerr << "incompatible size in solve_trans" << endl;
148  ad_exit(1);
149  }
150  dvector x(mmin,mmax);
151  int i,j;
152 
153  for (i=mmax;i>=mmin;i--)
154  {
155  double sum=0.0;
156  int jmax=mmax;
157  for (j=i+1;j<=jmax;j++)
158  {
159  sum+=M(j,i)*x(j);
160  }
161  x(i)=(y(i)-sum)/M(i,i);
162  }
163  return x;
164 }
165 
171 {
172  int imin=m.indexmin();
173  int imax=m.indexmax();
174  if (v.indexmin() != imin || v.indexmax() != imax)
175  {
176  cerr << " Incompatible vector and matrix sizes in solve " << endl;
177  ad_exit(1);
178  }
179  dvector x(imin,imax);
180  x(imin)=v(imin)/m(imin,imin);
181  for (int i=imin;i<=imax;i++)
182  {
183  int jmin=imin;
184  double ssum=0.0;
185  for (int j=jmin;j<=i-1;j++)
186  {
187  ssum+=m(i,j)*x(j);
188  }
189  x(i)=(v(i)-ssum)/m(i,i);
190  }
191  return x;
192 }
193 
199 {
200  dmatrix C=choleski_decomp_error(M,ierror);
201 
202  if (ierror==1)
203  {
204  return v;
205  }
206  else
207  {
209  }
210 }
211 
217 {
219 
220  if (ierror==1)
221  {
222  return v;
223  }
224  else
225  {
227  }
228 }
Description not yet available.
Definition: fvar.hpp:7981
dvector lower_triangular_solve(const dmatrix &m, const dvector &v)
Description not yet available.
Definition: dmat37.cpp:170
int admax(int i, int j)
Definition: fvar.hpp:8979
dmatrix trans(const dmatrix &m1)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: dmat2.cpp:13
#define x
#define ADUNCONST(type, obj)
Creates a shallow copy of obj that is not CONST.
Definition: fvar.hpp:140
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
dvector choleski_solve_neghess_error(dmatrix M, dvector &v, int &ierror)
Description not yet available.
Definition: dmat37.cpp:216
dmatrix choleski_decomp_neghess_error(const dmatrix &MM, int &ierror)
Description not yet available.
Definition: dmat15.cpp:176
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
int bandwidth(void) const
Definition: fvar.hpp:8127
exitptr ad_exit
Definition: gradstrc.cpp:53
dvector lower_triangular_solve_trans(const dmatrix &M, const dvector &y)
Description not yet available.
Definition: dmat37.cpp:140
df1_one_matrix choleski_decomp(const df1_one_matrix &MM)
Definition: df11fun.cpp:606
dvector solve(const dmatrix &aa, const dvector &z)
Solve a linear system using LU decomposition.
Definition: dmat34.cpp:46
prnstream & endl(prnstream &)
dvector solve_trans(const lower_triangular_dmatrix &M, const dvector &y)
Description not yet available.
Definition: dmat36.cpp:80
int indexmax() const
Get maximum valid index.
Definition: dvector.h:204
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Description not yet available.
Definition: fvar.hpp:8120
dmatrix choleski_decomp_error(const dmatrix &MM, int &ierror)
Description not yet available.
Definition: dmat15.cpp:111
#define M
Definition: rngen.cpp:57
Description not yet available.
Definition: fvar.hpp:2819
int indexmin(void) const
Definition: fvar.hpp:8131
dvector & shift(int min)
Shift valid range of subscripts.
Definition: dvector.cpp:52
int indexmax(void) const
Definition: fvar.hpp:8135
int indexmax() const
Definition: fvar.hpp:2921
int admin(int i, int j)
Definition: fvar.hpp:8987
#define w
dvector choleski_solve_error(dmatrix M, dvector &v, int &ierror)
Description not yet available.
Definition: dmat37.cpp:198