| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

multi_gp_cholesky_log.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_PROB_MULTI_GP_CHOLESKY_LOG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_MULTI_GP_CHOLESKY_LOG_HPP
3
4 #include <stan/math/prim/scal/err/check_size_match.hpp>
5 #include <stan/math/prim/scal/err/check_finite.hpp>
6 #include <stan/math/prim/scal/err/check_positive.hpp>
7 #include <stan/math/prim/scal/fun/constants.hpp>
8 #include <stan/math/prim/scal/meta/include_summand.hpp>
9
10 #include <stan/math/prim/mat/fun/dot_self.hpp>
11 #include <stan/math/prim/mat/fun/log.hpp>
12 #include <stan/math/prim/mat/fun/mdivide_left_tri_low.hpp>
13 #include <stan/math/prim/mat/fun/multiply.hpp>
14 #include <stan/math/prim/mat/fun/row.hpp>
15 #include <stan/math/prim/mat/fun/sum.hpp>
16
17 namespace stan {
18 namespace math {
19 // MultiGPCholesky(y|L, w) [y.rows() = w.size(), y.cols() = Sigma.rows();
20 // Sigma symmetric, non-negative, definite]
40 template <bool propto,
41 typename T_y, typename T_covar, typename T_w>
42 typename boost::math::tools::promote_args<T_y, T_covar, T_w>::type
43 multi_gp_cholesky_log(const Eigen::Matrix
44 <T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
45 const Eigen::Matrix
46 <T_covar, Eigen::Dynamic, Eigen::Dynamic>& L,
47 const Eigen::Matrix<T_w, Eigen::Dynamic, 1>& w) {
48 static const char* function("stan::math::multi_gp_cholesky_log");
49 typedef
50 typename boost::math::tools::promote_args<T_y, T_covar, T_w>::type T_lp;
51 T_lp lp(0.0);
52
53 using stan::math::mdivide_left_tri_low;
54 using stan::math::dot_self;
55 using stan::math::sum;
56 using stan::math::log;
57
58 using stan::math::check_size_match;
59 using stan::math::check_finite;
60 using stan::math::check_positive;
61
62 check_size_match(function,
63 "Size of random variable (rows y)", y.rows(),
64 "Size of kernel scales (w)", w.size());
65 check_size_match(function,
66 "Size of random variable", y.cols(),
67 "rows of covariance parameter", L.rows());
68 check_finite(function, "Kernel scales", w);
69 check_positive(function, "Kernel scales", w);
70 check_finite(function, "Random variable", y);
71
72 if (y.rows() == 0)
73 return lp;
74
75 if (include_summand<propto>::value) {
76 lp += NEG_LOG_SQRT_TWO_PI * y.rows() * y.cols();
77 }
78
79 if (include_summand<propto, T_covar>::value) {
80 lp -= L.diagonal().array().log().sum() * y.rows();
81 }
82
83 if (include_summand<propto, T_w>::value) {
84 lp += 0.5 * y.cols() * sum(log(w));
85 }
86
87 if (include_summand<propto, T_y, T_w, T_covar>::value) {
88 T_lp sum_lp_vec(0.0);
89 for (int i = 0; i < y.rows(); i++) {
90 Eigen::Matrix<T_y, Eigen::Dynamic, 1> y_row(y.row(i));
91 Eigen::Matrix<typename boost::math::tools::promote_args
92 <T_y, T_covar>::type,
93 Eigen::Dynamic, 1>
94 half(mdivide_left_tri_low(L, y_row));
95 sum_lp_vec += w(i) * dot_self(half);
96 }
97 lp -= 0.5*sum_lp_vec;
98 }
99
100 return lp;
101 }
102
103 template <typename T_y, typename T_covar, typename T_w>
104 inline
105 typename boost::math::tools::promote_args<T_y, T_covar, T_w>::type
106 multi_gp_cholesky_log(const Eigen::Matrix
107 <T_y, Eigen::Dynamic, Eigen::Dynamic>& y,
108 const Eigen::Matrix
109 <T_covar, Eigen::Dynamic, Eigen::Dynamic>& L,
110 const Eigen::Matrix<T_w, Eigen::Dynamic, 1>& w) {
111 return multi_gp_cholesky_log<false>(y, L, w);
112 }
113 }
114 }
115
116 #endif
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.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
stan::math::dot_self
fvar< T > dot_self(const Eigen::Matrix< fvar< T >, R, C > &v)
Definition: dot_self.hpp:16
stan::math::include_summand
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
Definition: include_summand.hpp:36
log.hpp
include_summand.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:68
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
row.hpp
stan::math::NEG_LOG_SQRT_TWO_PI
const double NEG_LOG_SQRT_TWO_PI
Definition: constants.hpp:184
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:62
constants.hpp
check_finite.hpp
stan::math::mdivide_left_tri_low
Eigen::Matrix< fvar< T >, R1, C1 > mdivide_left_tri_low(const Eigen::Matrix< fvar< T >, R1, C1 > &A, const Eigen::Matrix< fvar< T >, R2, C2 > &b)
Definition: mdivide_left_tri_low.hpp:22
sum.hpp
dot_self.hpp
mdivide_left_tri_low.hpp
stan::math::multi_gp_cholesky_log
boost::math::tools::promote_args< T_y, T_covar, T_w >::type multi_gp_cholesky_log(const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const Eigen::Matrix< T_covar, Eigen::Dynamic, Eigen::Dynamic > &L, const Eigen::Matrix< T_w, Eigen::Dynamic, 1 > &w)
The log of a multivariate Gaussian Process for the given y, w, and a Cholesky factor L of the kernel ...
Definition: multi_gp_cholesky_log.hpp:43

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