Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs 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>
12 
13 namespace stan {
14  namespace math {
15 
31  // FIXME: update warnings
32  template <typename T_y, typename T_result, class Policy>
33  inline bool check_corr_matrix(const char* function,
34  const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
35  const char* name,
36  T_result* result,
37  const Policy&) {
38  if (!check_size_match(function,
39  y.rows(), "Rows of correlation matrix",
40  y.cols(), "columns of correlation matrix",
41  result, Policy()))
42  return false;
43  if (!check_positive(function, y.rows(), "rows", result, Policy()))
44  return false;
45  if (!check_symmetric(function, y, "y", result, Policy()))
46  return false;
48  k = 0; k < y.rows(); ++k) {
49  if (fabs(y(k,k) - 1.0) > CONSTRAINT_TOLERANCE) {
50  std::ostringstream message;
51  message << name << " is not a valid correlation matrix. "
52  << name << "(" << k << "," << k
53  << ") is %1%, but should be near 1.0";
54  T_result tmp
55  = policies::raise_domain_error<T_y>(function,
56  message.str().c_str(),
57  y(k,k), Policy());
58  if (result != 0)
59  *result = tmp;
60  return false;
61  }
62  }
63  if (!check_pos_definite(function, y, "y", result, Policy()))
64  return false;
65  return true;
66  }
67 
68  template <typename T_y, typename T_result>
69  inline bool check_corr_matrix(const char* function,
70  const Eigen::Matrix<T_y,Eigen::Dynamic,Eigen::Dynamic>& y,
71  const char* name,
72  T_result* result) {
73  return check_corr_matrix(function,y,name,result,default_policy());
74  }
75 
76  template <typename T>
77  inline bool check_corr_matrix(const char* function,
78  const Eigen::Matrix<T,Eigen::Dynamic,Eigen::Dynamic>& y,
79  const char* name,
80  T* result = 0) {
81  return check_corr_matrix(function,y,name,result,default_policy());
82  }
83 
84  }
85 }
86 #endif

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