Stan Math Library: stan/math/rev/mat/fun/log_determinant_ldlt.hpp Source File

| Stan Math Library 2.10.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 stan::math::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(stan::math::LDLT_factor<var, R, C> &A) {
49 return var(new log_det_ldlt_vari<R, C>(A));
50 }
51 }
52 }
53 #endif
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:31
_alloc
mdivide_left_ldlt_alloc< R1, C1, R2, C2 > * _alloc
Definition: mdivide_left_ldlt.hpp:44
stan::math::LDLT_factor
Definition: LDLT_factor.hpp:18
LDLT_factor.hpp
Eigen.hpp
_alloc_ldlt
const LDLT_alloc< R, C > * _alloc_ldlt
Definition: log_determinant_ldlt.hpp:43
stan::math::log_determinant_ldlt
T log_determinant_ldlt(stan::math::LDLT_factor< T, R, C > &A)
Definition: log_determinant_ldlt.hpp:12

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