| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

check_corr_matrix.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_CORR_MATRIX_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_CORR_MATRIX_HPP
3
4 #include <stan/math/prim/scal/err/domain_error.hpp>
5 #include <stan/math/prim/scal/err/check_positive_size.hpp>
6 #include <stan/math/prim/mat/err/check_pos_definite.hpp>
7 #include <stan/math/prim/mat/err/check_symmetric.hpp>
8 #include <stan/math/prim/scal/err/check_size_match.hpp>
9 #include <stan/math/prim/mat/err/constraint_tolerance.hpp>
10 #include <stan/math/prim/mat/fun/Eigen.hpp>
11 #include <stan/math/prim/mat/meta/index_type.hpp>
12 #include <stan/math/prim/scal/meta/error_index.hpp>
13 #include <sstream>
14 #include <string>
15
16 namespace stan {
17 namespace math {
18
44 template <typename T_y>
45 inline bool
46 check_corr_matrix(const char* function,
47 const char* name,
48 const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y) {
49 using Eigen::Matrix;
50
51 typedef typename index_type<Matrix<
52 T_y, Eigen::Dynamic, Eigen::Dynamic> >::type size_t;
53
54 check_size_match(function,
55 "Rows of correlation matrix", y.rows(),
56 "columns of correlation matrix", y.cols());
57 check_positive_size(function, name, "rows", y.rows());
58 check_symmetric(function, "y", y);
59
60 for (size_t k = 0; k < y.rows(); ++k) {
61 if (!(fabs(y(k, k) - 1.0) <= CONSTRAINT_TOLERANCE)) {
62 std::ostringstream msg;
63 msg << "is not a valid correlation matrix. "
64 << name << "(" << stan::error_index::value + k
65 << "," << stan::error_index::value + k
66 << ") is ";
67 std::string msg_str(msg.str());
68 domain_error(function, name, y(k, k),
69 msg_str.c_str(),
70 ", but should be near 1.0");
71 return false;
72 }
73 }
74 check_pos_definite(function, "y", y);
75 return true;
76 }
77
78 }
79 }
80 #endif
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
check_size_match.hpp
stan::math::check_positive_size
bool check_positive_size(const char *function, const char *name, const char *expr, const int size)
Return true if size is positive.
Definition: check_positive_size.hpp:23
stan
Definition: log_sum_exp.hpp:8
constraint_tolerance.hpp
check_symmetric.hpp
stan::math::CONSTRAINT_TOLERANCE
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
Definition: constraint_tolerance.hpp:11
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
index_type.hpp
stan::error_index::value
Definition: error_index.hpp:7
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::domain_error
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
Definition: domain_error.hpp:30
Eigen.hpp
stan::math::check_corr_matrix
bool check_corr_matrix(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is a valid correlation matrix.
Definition: check_corr_matrix.hpp:46
stan::math::check_pos_definite
bool check_pos_definite(const char *function, const char *name, const Eigen::Matrix< T_y,-1,-1 > &y)
Return true if the specified square, symmetric matrix is positive definite.
Definition: check_pos_definite.hpp:33
domain_error.hpp
error_index.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
check_positive_size.hpp
check_pos_definite.hpp

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