19 #include <iostream.hpp>
43 cerr <<
"Error in chol_decomp. Matrix not square" <<
endl;
49 return log(MM(mmin,mmin));
62 #ifndef SAFE_INITIALIZE
68 cerr <<
"Error matrix not positive definite in choleski_decomp"
73 for (
int i=2;i<=n;i++)
79 for (
int i=2;i<=n;i++)
81 for (
int j=2;j<=i-1;j++)
84 for (
int k=1;k<=j-1;k++)
91 for (
int k=1;k<=i-1;k++)
97 cerr <<
"Error matrix not positive definite in ln_det_choleski"
106 for (
int i=1;i<=n;i++)
108 log_det1+=
log(L(i,i));
120 double log_det=2.0*log_det1;
155 cerr <<
"Error in chol_decomp. Matrix not square" <<
endl;
177 #ifndef SAFE_INITIALIZE
183 cerr <<
"Error matrix not positive definite in choleski_decomp"
188 for (
int i=2;i<=n;i++)
190 L(i,1)=
M(i,1)/L(1,1);
193 for (
int i=2;i<=n;i++)
195 for (
int j=2;j<=i-1;j++)
198 for (
int k=1;k<=j-1;k++)
200 tmp1(i,j)-=L(i,k)*L(j,k);
202 L(i,j)=tmp1(i,j)/L(j,j);
205 for (
int k=1;k<=i-1;k++)
207 tmp(i)-=L(i,k)*L(i,k);
211 cerr <<
"Error matrix not positive definite in choleski_decomp"
218 for (
int i=1;i<=n;i++)
220 log_det1+=
log(L(i,i));
229 double dflog_det1=2.0*dflog_det;
230 for (
int i=1;i<=n;i++)
233 dfL(i,i)=dflog_det1/L(i,i);
236 for (
int i=n;i>=2;i--)
239 dftmp(i)+=dfL(i,i)/(2.0*L(i,i));
241 for (
int k=i-1;k>=1;k--)
244 dfL(i,k)-=2.*dftmp(i)*L(i,k);
249 for (
int j=i-1;j>=2;j--)
252 double linv=1./L(j,j);
253 dftmp1(i,j)+=dfL(i,j)*linv;
254 dfL(j,j)-=dfL(i,j)*tmp1(i,j)*linv*linv;
256 for (
int k=j-1;k>=1;k--)
259 dfL(i,k)-=dftmp1(i,j)*L(j,k);
260 dfL(j,k)-=dftmp1(i,j)*L(i,k);
263 dfM(i,j)+=dftmp1(i,j);
267 double linv=1./L(1,1);
268 for (
int i=n;i>=2;i--)
271 dfM(i,1)+=dfL(i,1)*linv;
272 dfL(1,1)-=dfL(i,1)*
M(i,1)*linv*linv;
276 dfM(1,1)+=dfL(1,1)/(2.*L(1,1));
311 cerr <<
"Error in chol_decomp. Matrix not square" <<
endl;
317 return log(MM(mmin,mmin));
330 #ifndef SAFE_INITIALIZE
339 for (
int i=2;i<=n;i++)
341 L(i,1)=
M(i,1)/L(1,1);
345 for (
int i=2;i<=n;i++)
347 for (
int j=2;j<=i-1;j++)
350 for (
int k=1;k<=j-1;k++)
357 for (
int k=1;k<=i-1;k++)
370 for (
int i=1;i<=n;i++)
372 log_det1+=
log(L(i,i));
382 double log_det=2.0*log_det1;
Description not yet available.
double restore_prevariable_derivative()
Vector of double precision numbers.
static dmatrix onerror(dmatrix &L, int &ierror)
Description not yet available.
dvar_vector nograd_assign(dvector tmp)
Description not yet available.
void verify_identifier_string(const char *)
Verifies gradient stack string.
unsigned int colsize() const
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.
void dfcholeski_decomp(void)
Description not yet available.
dvariable ln_det_choleski_error(const dvar_matrix &, int &ierr)
Description not yet available.
dmatrix restore_dvar_matrix_value(const dvar_matrix_position &mpos)
prnstream & endl(prnstream &)
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void save_prevariable_position(const prevariable &v)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void df_ln_det_choleski(void)
Description not yet available.
void save_dmatrix_derivatives(const dvar_matrix_position &pos) const
Description not yet available.
Description not yet available.
void initialize(void)
Initialze all elements of dvector to zero.
int save_identifier_string(const char *)
Writes a gradient stack verification string.
dvar_matrix_position restore_dvar_matrix_position()
static dvariable error_condition(int &onerror)
Description not yet available.
static _THREAD DF_FILE * fp
void save_dvar_matrix_position(const dvar_matrix &m)
void rowshift(int min)
Changes the range of valid indices for the rows.
Class definition of matrix with derivitive information .
Stores the adjoint gradient data that will be processed by gradcalc.
double ln_det_choleski(const banded_symmetric_dmatrix &MM, int &ierr)
void colshift(int min)
Description not yet available.
void save_dvar_matrix_value(const dvar_matrix &m)
unsigned int rowsize() const
dvector value(const df1_one_vector &v)
static _THREAD grad_stack * GRAD_STACK1
void initialize(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Fundamental data type for reverse mode automatic differentiation.
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Description not yet available.