Automatic Differentiation
 
Loading...
Searching...
No Matches
hmm_check.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_ERR_HMM_CHECK_HPP
2#define STAN_MATH_PRIM_ERR_HMM_CHECK_HPP
3
6
7namespace stan {
8namespace math {
9
27template <typename T_omega, typename T_Gamma, typename T_rho,
28 require_all_eigen_t<T_omega, T_Gamma>* = nullptr,
29 require_eigen_col_vector_t<T_rho>* = nullptr>
30inline void hmm_check(const T_omega& log_omegas, const T_Gamma& Gamma,
31 const T_rho& rho, const char* function) {
32 int n_states = log_omegas.rows();
33
34 check_consistent_size(function, "rho", rho, n_states);
35 check_square(function, "Gamma", Gamma);
36 check_nonzero_size(function, "Gamma", Gamma);
37 check_multiplicable(function, "Gamma", Gamma, "log_omegas", log_omegas);
38
39 check_simplex(function, "rho", rho);
40 const auto& Gamma_ref = to_ref(Gamma);
41 for (int i = 0; i < Gamma.rows(); ++i) {
42 check_simplex(function, "Gamma[i, ]", Gamma_ref.row(i));
43 }
44}
45
46} // namespace math
47} // namespace stan
48#endif
void check_square(const char *function, const char *name, const T_y &y)
Check if the specified matrix is square.
void check_multiplicable(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the matrices can be multiplied.
void check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
Check if x is consistent with size expected_size.
void hmm_check(const T_omega &log_omegas, const T_Gamma &Gamma, const T_rho &rho, const char *function)
Check arguments for hidden Markov model functions with a discrete latent state (lpdf,...
Definition hmm_check.hpp:30
void check_simplex(const char *function, const char *name, const T &theta)
Throw an exception if the specified vector is not a simplex.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...