Stan Math Library  2.20.0
reverse mode automatic differentiation
log_determinant_ldlt.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_MAT_FUN_LOG_DETERMINANT_LDLT_HPP
2 #define STAN_MATH_REV_MAT_FUN_LOG_DETERMINANT_LDLT_HPP
3 
4 #include <stan/math/rev/meta.hpp>
6 #include <stan/math/rev/core.hpp>
9 
10 namespace stan {
11 namespace math {
12 namespace internal {
13 
23 template <int R, int C>
24 class log_det_ldlt_vari : public vari {
25  public:
27  : vari(A.alloc_->log_abs_det()), alloc_ldlt_(A.alloc_) {}
28 
29  virtual void chain() {
30  Eigen::Matrix<double, R, C> invA;
31 
32  // If we start computing Jacobians, this may be a bit inefficient
33  invA.setIdentity(alloc_ldlt_->N_, alloc_ldlt_->N_);
34  alloc_ldlt_->ldlt_.solveInPlace(invA);
35 
36  for (size_t j = 0; j < alloc_ldlt_->N_; j++) {
37  for (size_t i = 0; i < alloc_ldlt_->N_; i++) {
38  alloc_ldlt_->variA_(i, j)->adj_ += adj_ * invA(i, j);
39  }
40  }
41  }
42 
44 };
45 } // namespace internal
46 
47 template <int R, int C>
50 }
51 
52 } // namespace math
53 } // namespace stan
54 #endif
A template specialization of src/stan/math/matrix/LDLT_factor.hpp for var which can be used with all ...
Definition: LDLT_factor.hpp:47
The variable implementation base class.
Definition: vari.hpp:30
This object stores the actual (double typed) LDLT factorization of an Eigen::Matrix<var> along with p...
Definition: LDLT_alloc.hpp:21
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
Returns the log det of the matrix whose LDLT factorization is given See The Matrix Cookbook&#39;s chapter...
friend class var
Definition: vari.hpp:32
virtual void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
log_det_ldlt_vari(const LDLT_factor< var, R, C > &A)
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Definition: vari.hpp:44
T log_determinant_ldlt(LDLT_factor< T, R, C > &A)

     [ Stan Home Page ] © 2011–2018, Stan Development Team.