1#ifndef STAN_MATH_PRIM_PROB_GAUSSIAN_DLM_OBS_LPDF_HPP
2#define STAN_MATH_PRIM_PROB_GAUSSIAN_DLM_OBS_LPDF_HPP
65template <
bool propto,
typename T_y,
typename T_F,
typename T_G,
typename T_V,
66 typename T_W,
typename T_m0,
typename T_C0,
69 require_eigen_col_vector_t<T_m0>* =
nullptr>
71 const T_y& y,
const T_F& F,
const T_G& G,
const T_V& V,
const T_W& W,
72 const T_m0& m0,
const T_C0& C0) {
75 static constexpr const char* function =
"gaussian_dlm_obs_lpdf";
84 const auto& y_ref =
to_ref(y);
85 const auto& F_ref =
to_ref(F);
86 const auto& G_ref =
to_ref(G);
87 const auto& V_ref =
to_ref(V);
88 const auto& W_ref =
to_ref(W);
89 const auto& m0_ref =
to_ref(m0);
90 const auto& C0_ref =
to_ref(C0);
119 Eigen::Matrix<T_lp, Eigen::Dynamic, 1> m{m0_ref};
120 Eigen::Matrix<T_lp, Eigen::Dynamic, Eigen::Dynamic> C{C0_ref};
121 Eigen::Matrix<T_lp, Eigen::Dynamic, 1> a(n);
122 Eigen::Matrix<T_lp, Eigen::Dynamic, Eigen::Dynamic> R(n, n);
123 Eigen::Matrix<T_lp, Eigen::Dynamic, 1> f(r);
124 Eigen::Matrix<T_lp, Eigen::Dynamic, Eigen::Dynamic> Q(r, r);
125 Eigen::Matrix<T_lp, Eigen::Dynamic, Eigen::Dynamic> Q_inv(r, r);
126 Eigen::Matrix<T_lp, Eigen::Dynamic, 1>
e(r);
127 Eigen::Matrix<T_lp, Eigen::Dynamic, Eigen::Dynamic> A(n, r);
129 for (
int i = 0; i < y.cols(); i++) {
143 e = y_ref.col(i) - f;
192 bool propto,
typename T_y,
typename T_F,
typename T_G,
typename T_V,
193 typename T_W,
typename T_m0,
typename T_C0,
197 const T_y& y,
const T_F& F,
const T_G& G,
const T_V& V,
const T_W& W,
198 const T_m0& m0,
const T_C0& C0) {
201 static constexpr const char* function =
"gaussian_dlm_obs_lpdf";
202 check_size_match(function,
"columns of F", F.cols(),
"rows of y", y.rows());
204 check_size_match(function,
"rows of G", G.rows(),
"columns of G", G.cols());
210 const auto& y_ref =
to_ref(y);
211 const auto& F_ref =
to_ref(F);
212 const auto& G_ref =
to_ref(G);
213 const auto& V_ref =
to_ref(V);
214 const auto& W_ref =
to_ref(W);
215 const auto& m0_ref =
to_ref(m0);
216 const auto& C0_ref =
to_ref(C0);
231 if (y.cols() == 0 || y.rows() == 0) {
239 if constexpr (include_summand<propto>::value) {
243 if constexpr (include_summand<propto, T_y, T_F, T_G, T_V, T_W, T_m0,
249 Eigen::Matrix<T_lp, Eigen::Dynamic, 1> A(n);
250 Eigen::Matrix<T_lp, Eigen::Dynamic, 1> Fj(n);
251 Eigen::Matrix<T_lp, Eigen::Dynamic, 1> m{m0_ref};
252 Eigen::Matrix<T_lp, Eigen::Dynamic, Eigen::Dynamic> C{C0_ref};
254 for (
int i = 0; i < y.cols(); i++) {
259 for (
int j = 0; j < y.rows(); ++j) {
262 const auto& Fj = F_ref.col(j);
271 e = y_ref.coeff(j, i) - f;
288template <
typename T_y,
typename T_F,
typename T_G,
typename T_V,
typename T_W,
289 typename T_m0,
typename T_C0>
291 const T_y& y,
const T_F& F,
const T_G& G,
const T_V& V,
const T_W& W,
292 const T_m0& m0,
const T_C0& C0) {
293 return gaussian_dlm_obs_lpdf<false>(y, F, G, V, W, m0, C0);
require_all_t< is_eigen_col_vector< std::decay_t< Types > >... > require_all_eigen_col_vector_t
Require all of the types satisfy is_eigen_col_vector.
require_all_t< is_eigen_matrix_dynamic< std::decay_t< Types > >... > require_all_eigen_matrix_dynamic_t
Require all of the types satisfy is_eigen_matrix_dynamic.
return_type_t< T_y, T_F, T_G, T_V, T_W, T_m0, T_C0 > gaussian_dlm_obs_lpdf(const T_y &y, const T_F &F, const T_G &G, const T_V &V, const T_W &W, const T_m0 &m0, const T_C0 &C0)
The log of a Gaussian dynamic linear model (GDLM).
auto transpose(Arg &&a)
Transposes a kernel generator expression.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
bool size_zero(const T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
void check_pos_semidefinite(const char *function, const char *name, const EigMat &y)
Check if the specified matrix is positive definite.
static constexpr double e()
Return the base of the natural logarithm.
value_type_t< EigMat > log_determinant_spd(const EigMat &m)
Returns the log absolute determinant of the specified square matrix.
fvar< T > log(const fvar< T > &x)
auto multiply(const Mat1 &m1, const Mat2 &m2)
Return the product of the specified matrices.
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
promote_scalar_t< return_type_t< EigMat1, EigMat2 >, EigMat2 > quad_form_sym(const EigMat1 &A, const EigMat2 &B)
Return the quadratic form of a symmetric matrix.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
Eigen::Matrix< value_type_t< EigMat >, Eigen::Dynamic, Eigen::Dynamic > inverse_spd(const EigMat &m)
Returns the inverse of the specified symmetric, pos/neg-definite matrix.
return_type_t< EigMat1, EigMat2 > trace_quad_form(const EigMat1 &A, const EigMat2 &B)
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
static constexpr double HALF_LOG_TWO_PI
The value of half the natural logarithm , .
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
auto dot_product(const T_a &a, const T_b &b)
Returns the dot product of the specified vectors.
fvar< T > square(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...