Stan Math Library: stan/math/prim/mat/fun/trace_inv_quad_form_ldlt.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

trace_inv_quad_form_ldlt.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_TRACE_INV_QUAD_FORM_LDLT_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/fun/LDLT_factor.hpp>
6 #include <stan/math/prim/mat/err/check_multiplicable.hpp>
7 #include <stan/math/prim/mat/fun/mdivide_left_ldlt.hpp>
8 #include <stan/math/prim/mat/fun/trace.hpp>
9 #include <stan/math/prim/mat/fun/transpose.hpp>
10 #include <stan/math/prim/mat/fun/multiply.hpp>
11 #include <stan/math/prim/scal/meta/is_var.hpp>
12
13 namespace stan {
14 namespace math {
15
16 /*
17 * Compute the trace of an inverse quadratic form. I.E., this computes
18 * trace(B^T A^-1 B)
19 * where the LDLT_factor of A is provided.
20 */
21 template <typename T1, typename T2, int R2, int C2, int R3, int C3>
22 inline typename
23 boost::enable_if_c<!stan::is_var<T1>::value &&
24 !stan::is_var<T2>::value,
25 typename
26 boost::math::tools::promote_args<T1, T2>::type>::type
27 trace_inv_quad_form_ldlt(const stan::math::LDLT_factor<T1, R2, C2> &A,
28 const Eigen::Matrix<T2, R3, C3> &B) {
29 stan::math::check_multiplicable("trace_inv_quad_form_ldlt",
30 "A", A,
31 "B", B);
32
33 return trace(multiply(transpose(B), mdivide_left_ldlt(A, B)));
34 }
35 }
36 }
37
38 #endif
multiply.hpp
check_multiplicable.hpp
stan
Definition: log_sum_exp.hpp:8
stan::is_var
Definition: is_var.hpp:7
stan::math::multiply
Eigen::Matrix< fvar< T >, R1, C1 > multiply(const Eigen::Matrix< fvar< T >, R1, C1 > &m, const fvar< T > &c)
Definition: multiply.hpp:21
stan::math::trace_inv_quad_form_ldlt
boost::enable_if_c<!stan::is_var< T1 >::value &&!stan::is_var< T2 >::value, typename boost::math::tools::promote_args< T1, T2 >::type >::type trace_inv_quad_form_ldlt(const stan::math::LDLT_factor< T1, R2, C2 > &A, const Eigen::Matrix< T2, R3, C3 > &B)
Definition: trace_inv_quad_form_ldlt.hpp:27
transpose.hpp
trace.hpp
is_var.hpp
stan::math::LDLT_factor
Definition: LDLT_factor.hpp:18
LDLT_factor.hpp
stan::math::mdivide_left_ldlt
Eigen::Matrix< fvar< T2 >, R1, C2 > mdivide_left_ldlt(const stan::math::LDLT_factor< double, R1, C1 > &A, const Eigen::Matrix< fvar< T2 >, R2, C2 > &b)
Returns the solution of the system Ax=b given an LDLT_factor of A.
Definition: mdivide_left_ldlt.hpp:25
stan::math::check_multiplicable
bool check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Return true if the matrices can be multiplied.
Definition: check_multiplicable.hpp:33
Eigen.hpp
stan::math::trace
T trace(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &m)
Returns the trace of the specified matrix.
Definition: trace.hpp:20
mdivide_left_ldlt.hpp
stan::math::transpose
Eigen::Matrix< T, C, R > transpose(const Eigen::Matrix< T, R, C > &m)
Definition: transpose.hpp:12

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