ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2mat.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  */
7 #include <df1b2fun.h>
18 {
19  // kludge to deal with constantness
20  df1b2matrix & M= * (df1b2matrix *) &MM;
21  int rmin=M.indexmin();
22  int cmin=M(rmin).indexmin();
23  int rmax=M.indexmax();
24  int cmax=M(rmin).indexmax();
25 
26  if (rmin != cmin )
27  {
28  cerr << "minimum row and column inidices must equal 1 in "
29  "df1b2matrix choleski_decomp(const df1b2matrix& MM)"
30  << endl;
31  ad_exit(1);
32  }
33  if (rmax !=cmax)
34  {
35  cerr << "Error in df1b2matrix choleski_decomp(const df1b2matrix& MM)"
36  " Matrix not square" << endl;
37  ad_exit(1);
38  }
39 
40  //int n=rmax;
41  df1b2matrix L(rmin,rmax,rmin,rmax);
42 #ifndef SAFE_INITIALIZE
43  L.initialize();
44 #endif
45 
46  int i,j,k;
47  df1b2variable tmp;
48  if (value(M(rmin,rmin))<=0)
49  {
50  cerr << "Error matrix not positive definite in choleski_decomp"
51  <<endl;
52  ad_exit(1);
53  }
54 
55  L(rmin,rmin)=sqrt(M(rmin,rmin));
56  for (i=rmin+1;i<=rmax;i++)
57  {
58  L(i,rmin)=M(i,rmin)/L(rmin,rmin);
59  }
60 
61  for (i=rmin+1;i<=rmax;i++)
62  {
63  for (j=rmin+1;j<=i-1;j++)
64  {
65  tmp=M(i,j);
66  for (k=rmin;k<=j-1;k++)
67  {
68  tmp-=L(i,k)*L(j,k);
69  }
70  L(i,j)=tmp/L(j,j);
71  }
72  tmp=M(i,i);
73  for (k=rmin;k<=i-1;k++)
74  {
75  tmp-=L(i,k)*L(i,k);
76  }
77  if (value(tmp)<=0)
78  {
79  cerr << "Error matrix not positive definite in choleski_decomp"
80  <<endl;
81  ad_exit(1);
82  }
83  L(i,i)=sqrt(tmp);
84  }
85  return L;
86 }
87 
88 #undef HOME_VERSION
int indexmin(void) const
Definition: df1b2fun.h:1054
exitptr ad_exit
Definition: gradstrc.cpp:53
void initialize(void)
Description not yet available.
Definition: f1b2vc2.cpp:157
Description not yet available.
Definition: df1b2fun.h:266
df1_one_matrix choleski_decomp(const df1_one_matrix &MM)
Definition: df11fun.cpp:606
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
#define M
Definition: rngen.cpp:57
Description not yet available.
Definition: df1b2fun.h:1042
int indexmax(void) const
Definition: df1b2fun.h:1055
Description not yet available.
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69