Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
check_corr_matrix.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_CORR_MATRIX_HPP
2 #define STAN__MATH__ERROR_HANDLING__MATRIX__CHECK_CORR_MATRIX_HPP
3 
4 #include <sstream>
5 
14 
15 
16 namespace stan {
17 
18  namespace math {
19 
36  // FIXME: update warnings
37  template <typename T_y, typename T_result>
38  inline bool check_corr_matrix(const char* function,
39  const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
40  const char* name,
41  T_result* result) {
42  using Eigen::Dynamic;
43  using Eigen::Matrix;
44  typedef typename index_type<Matrix<T_y,Dynamic,Dynamic> >::type size_t;
45 
47  y.rows(), "Rows of correlation matrix",
48  y.cols(), "columns of correlation matrix",
49  result);
50 
51  stan::math::check_positive(function, y.rows(), "rows", result);
52 
53  stan::math::check_symmetric(function, y, "y", result);
54 
55  for (size_t k = 0; k < y.rows(); ++k) {
56  if (!(fabs(y(k,k) - 1.0) <= CONSTRAINT_TOLERANCE)) {
57  std::ostringstream message;
58  message << " is not a valid correlation matrix. "
59  << name << "(" << stan::error_index::value + k
60  << "," << stan::error_index::value + k
61  << ") is %1%, but should be near 1.0";
62  std::string msg(message.str());
63  return dom_err(function,y(k,k),name,msg.c_str(),"",result);
64  }
65  }
66  stan::math::check_pos_definite(function, y, "y", result);
67  return true;
68  }
69 
70  }
71 }
72 #endif
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:18
bool dom_err(const char *function, const T &y, const char *name, const char *error_msg, const T_msg error_msg2, T_result *result)
Definition: dom_err.hpp:36
bool check_size_match(const char *function, T_size1 i, const char *name_i, T_size2 j, const char *name_j, T_result *result)
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
bool check_symmetric(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result)
Return true if the specified matrix is symmetric.
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:21
bool check_pos_definite(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result)
Return true if the specified matrix is positive definite.
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result)
bool check_corr_matrix(const char *function, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result)
Return true if the specified matrix is a valid correlation matrix.

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