ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dmat43.cpp
Go to the documentation of this file.
1 
6 #include "fvar.hpp"
7 
13  bw(mm.bw), d(mm.d)
14 {}
21 {
22  if (mm.bw!=bw)
23  {
24  cerr << "shape error" << endl;
25  ad_exit(1);
26  }
27  else
28  {
29  for (int i=0;i<=bw-1;i++)
30  {
31  d(i)=mm.d(i);
32  }
33  }
34  return *this;
35 }
36 
42  const banded_symmetric_dmatrix& _M,const int& _ierr)
43 {
44  int & ierr = (int &) _ierr;
46  int minsave=M.indexmin();
47  M.shift(1);
48  int n=M.indexmax();
49 
50  double delta=0.0;
51  int bw=M.bandwidth();
53 #ifndef SAFE_INITIALIZE
54  L.initialize();
55 #endif
56 
57  int i;
58  double tmp;
59  if (M(1,1)<=0)
60  {
61  if (ierr==0)
62  cerr << "Error matrix not positive definite in choleski_decomp"
63  <<endl;
64  ierr=1;
65  return L;
66  }
67  L(1,1)=sqrt(M(1,1));
68  for (i=2;i<=bw;i++)
69  {
70  L(i,1)=M(i,1)/L(1,1);
71  }
72 
73  for (i=2;i<=n;i++)
74  {
75  for (int j=i-bw+1;j<=i-1;j++)
76  {
77  if (j>1)
78  {
79  tmp=M(i,j);
80  for (int k=i-bw+1;k<=j-1;k++)
81  {
82  if (k>0 && k>j-bw)
83  tmp-=L(i,k)*L(j,k);
84  }
85  L(i,j)=tmp/L(j,j);
86  }
87  }
88  tmp=M(i,i);
89  for (int k=i-bw+1;k<=i-1;k++)
90  {
91  if (k>0)
92  tmp-=L(i,k)*L(i,k);
93  }
94  if (tmp<=0)
95  {
96  delta=-tmp;
97  ierr=1;
98  break;
99  }
100  L(i,i)=sqrt(tmp);
101  if (i==n)
102  {
103  ierr=0;
104  }
105  }
106  dvector v(1,n);
107  if (ierr==1)
108  {
109  int k=i;
110  v.initialize();
111  v(k)=1.0;
112  for (i=k-1;i>=1;i--)
113  {
114  double ssum=0.0;
115  int jmax=admin(n,i+bw-1);
116  for (int j=i+1;j<=jmax;j++)
117  {
118  ssum+=L(j,i)*v(j);
119  }
120  v(i)=-ssum/L(i,i);
121  }
122  L(1,1)=delta/norm2(v);
123  }
124 
125  M.shift(minsave);
126  L.shift(minsave);
127 
128  return L;
129 }
130 //***********************************************************
131 //***********************************************************
132 /*
133  int i,j;
134 
135  for (i=mmax;i>=mmin;i--)
136  {
137  double sum=0.0;
138  int jmax=admin(mmax,i+bw-1);
139  for (j=i+1;j<=jmax;j++)
140  {
141  sum+=M(j,i)*x(j);
142  }
143  x(i)=(y(i)-sum)/M(i,i);
144  }
145 
146  return x;
147 }
148 */
149 //***********************************************************
150 //***********************************************************
151 //***********************************************************
152 
Description not yet available.
Definition: fvar.hpp:7981
#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
exitptr ad_exit
Definition: gradstrc.cpp:53
void initialize(void)
Description not yet available.
Definition: dmat41.cpp:29
banded_lower_triangular_dmatrix & operator=(const banded_lower_triangular_dmatrix &)
Assigment operator.
Definition: dmat43.cpp:19
banded_lower_triangular_dmatrix choleski_decomp_trust_bound(const banded_symmetric_dmatrix &_M, const int &_ierr)
Description not yet available.
Definition: dmat43.cpp:41
prnstream & endl(prnstream &)
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2c.cpp:11
banded_lower_triangular_dmatrix(const dvar_matrix_position &mpos)
Description not yet available.
Definition: dmat28.cpp:165
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Description not yet available.
Definition: fvar.hpp:8120
#define M
Definition: rngen.cpp:57
void shift(int)
Description not yet available.
Definition: dmat28.cpp:125
void initialize(void)
Initialze all elements of dvector to zero.
Definition: dvect5.cpp:10
double norm2(const d3_array &a)
Return sum of squared elements in a.
Definition: d3arr2a.cpp:167
int admin(int i, int j)
Definition: fvar.hpp:8987