| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/rev/core.hpp>
6 #include <stan/math/rev/mat/fun/LDLT_alloc.hpp>
7 #include <stan/math/rev/mat/fun/LDLT_factor.hpp>
8
9 namespace stan {
10 namespace math {
11 namespace {
12
22 template<int R, int C>
23 class log_det_ldlt_vari : public vari {
24 public:
25 explicit log_det_ldlt_vari(const LDLT_factor<var, R, C> &A)
26 : vari(A.alloc_->log_abs_det()), alloc_ldlt_(A.alloc_)
27 { }
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
43 const LDLT_alloc<R, C> *alloc_ldlt_;
44 };
45 }
46
47 template<int R, int C>
48 var log_determinant_ldlt(LDLT_factor<var, R, C> &A) {
49 return var(new log_det_ldlt_vari<R, C>(A));
50 }
51
52 }
53 }
54 #endif
stan::math::LDLT_factor< var, R, C >
A template specialization of src/stan/math/matrix/LDLT_factor.hpp for var which can be used with all ...
Definition: LDLT_factor.hpp:46
core.hpp
LDLT_alloc.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:30
alloc_
mdivide_left_ldlt_alloc< R1, C1, R2, C2 > * alloc_
Definition: mdivide_left_ldlt.hpp:44
alloc_ldlt_
const LDLT_alloc< R, C > * alloc_ldlt_
Definition: log_determinant_ldlt.hpp:43
LDLT_factor.hpp
Eigen.hpp
stan::math::log_determinant_ldlt
T log_determinant_ldlt(LDLT_factor< T, R, C > &A)
Definition: log_determinant_ldlt.hpp:12

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