| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

multi_gp_log.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_GP_LOG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_MULTI_GP_LOG_HPP
3
4 #include <stan/math/prim/mat/err/check_ldlt_factor.hpp>
5 #include <stan/math/prim/scal/err/check_size_match.hpp>
6 #include <stan/math/prim/mat/err/check_symmetric.hpp>
7 #include <stan/math/prim/scal/err/check_finite.hpp>
8 #include <stan/math/prim/scal/err/check_not_nan.hpp>
9 #include <stan/math/prim/scal/err/check_positive.hpp>
10 #include <stan/math/prim/scal/err/check_positive_finite.hpp>
11 #include <stan/math/prim/mat/fun/log.hpp>
12 #include <stan/math/prim/mat/fun/log_determinant_ldlt.hpp>
13 #include <stan/math/prim/mat/fun/multiply.hpp>
14 #include <stan/math/prim/mat/fun/sum.hpp>
15 #include <stan/math/prim/mat/fun/trace_gen_inv_quad_form_ldlt.hpp>
16 #include <stan/math/prim/scal/fun/constants.hpp>
17 #include <stan/math/prim/scal/meta/include_summand.hpp>
18
19 namespace stan {
20 namespace math {
39 template <bool propto,
40 typename T_y, typename T_covar, typename T_w>
41 typename boost::math::tools::promote_args<T_y, T_covar, T_w>::type
42 multi_gp_log(const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
43 const Eigen::Matrix
44 <T_covar, Eigen::Dynamic, Eigen::Dynamic>& Sigma,
45 const Eigen::Matrix<T_w, Eigen::Dynamic, 1>& w) {
46 static const char* function("multi_gp_log");
47 typedef typename boost::math::tools::promote_args<T_y, T_covar, T_w>::type
48 T_lp;
49 T_lp lp(0.0);
50
51
52 check_positive(function, "Kernel rows", Sigma.rows());
53 check_finite(function, "Kernel", Sigma);
54 check_symmetric(function, "Kernel", Sigma);
55
56 LDLT_factor<T_covar, Eigen::Dynamic, Eigen::Dynamic> ldlt_Sigma(Sigma);
57 check_ldlt_factor(function, "LDLT_Factor of Sigma", ldlt_Sigma);
58
59 check_size_match(function,
60 "Size of random variable (rows y)", y.rows(),
61 "Size of kernel scales (w)", w.size());
62 check_size_match(function,
63 "Size of random variable", y.cols(),
64 "rows of covariance parameter", Sigma.rows());
65 check_positive_finite(function, "Kernel scales", w);
66 check_finite(function, "Random variable", y);
67
68 if (y.rows() == 0)
69 return lp;
70
71 if (include_summand<propto>::value) {
72 lp += NEG_LOG_SQRT_TWO_PI * y.rows() * y.cols();
73 }
74
75 if (include_summand<propto, T_covar>::value) {
76 lp -= 0.5 * log_determinant_ldlt(ldlt_Sigma) * y.rows();
77 }
78
79 if (include_summand<propto, T_w>::value) {
80 lp += (0.5 * y.cols()) * sum(log(w));
81 }
82
83 if (include_summand<propto, T_y, T_w, T_covar>::value) {
84 Eigen::Matrix<T_w, Eigen::Dynamic, Eigen::Dynamic>
85 w_mat(w.asDiagonal());
86 Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic> yT(y.transpose());
87 lp -= 0.5 * trace_gen_inv_quad_form_ldlt(w_mat, ldlt_Sigma, yT);
88 }
89
90 return lp;
91 }
92
93 template <typename T_y, typename T_covar, typename T_w>
94 inline
95 typename boost::math::tools::promote_args<T_y, T_covar, T_w>::type
96 multi_gp_log(const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
97 const Eigen::Matrix<T_covar, Eigen::Dynamic, Eigen::Dynamic>&
98 Sigma,
99 const Eigen::Matrix<T_w, Eigen::Dynamic, 1>& w) {
100 return multi_gp_log<false>(y, Sigma, w);
101 }
102
103 }
104 }
105 #endif
check_not_nan.hpp
stan::math::sum
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Definition: sum.hpp:20
multiply.hpp
check_size_match.hpp
check_positive_finite.hpp
check_positive.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
check_symmetric.hpp
stan::math::include_summand
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
Definition: include_summand.hpp:35
stan::math::check_ldlt_factor
bool check_ldlt_factor(const char *function, const char *name, LDLT_factor< T, R, C > &A)
Return true if the argument is a valid LDLT_factor.
Definition: check_ldlt_factor.hpp:34
log.hpp
include_summand.hpp
check_ldlt_factor.hpp
stan::math::LDLT_factor
Definition: LDLT_factor.hpp:13
trace_gen_inv_quad_form_ldlt.hpp
stan::math::check_positive
bool check_positive(const char *function, const char *name, const T_y &y)
Return true if y is positive.
Definition: check_positive.hpp:66
stan::math::check_size_match
bool check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Return true if the provided sizes match.
Definition: check_size_match.hpp:30
stan::math::multi_gp_log
boost::math::tools::promote_args< T_y, T_covar, T_w >::type multi_gp_log(const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const Eigen::Matrix< T_covar, Eigen::Dynamic, Eigen::Dynamic > &Sigma, const Eigen::Matrix< T_w, Eigen::Dynamic, 1 > &w)
The log of a multivariate Gaussian Process for the given y, Sigma, and w.
Definition: multi_gp_log.hpp:42
stan::math::NEG_LOG_SQRT_TWO_PI
const double NEG_LOG_SQRT_TWO_PI
Definition: constants.hpp:181
stan::math::check_finite
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
Definition: check_finite.hpp:60
constants.hpp
check_finite.hpp
sum.hpp
stan::math::check_symmetric
bool check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is symmetric.
Definition: check_symmetric.hpp:36
stan::math::log_determinant_ldlt
T log_determinant_ldlt(LDLT_factor< T, R, C > &A)
Definition: log_determinant_ldlt.hpp:12
stan::math::trace_gen_inv_quad_form_ldlt
boost::enable_if_c<!stan::is_var< T1 >::value &&!stan::is_var< T2 >::value &&!stan::is_var< T3 >::value, typename boost::math::tools::promote_args< T1, T2, T3 >::type >::type trace_gen_inv_quad_form_ldlt(const Eigen::Matrix< T1, R1, C1 > &D, const LDLT_factor< T2, R2, C2 > &A, const Eigen::Matrix< T3, R3, C3 > &B)
Definition: trace_gen_inv_quad_form_ldlt.hpp:30
stan::math::check_positive_finite
bool check_positive_finite(const char *function, const char *name, const T_y &y)
Return true if y is positive and finite.
Definition: check_positive_finite.hpp:28
log_determinant_ldlt.hpp

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