All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
check_corr_matrix.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_CORR_MATRIX_HPP
#define STAN_MATH_PRIM_MAT_ERR_CHECK_CORR_MATRIX_HPP
#include <stan/math/prim/scal/err/domain_error.hpp>
#include <stan/math/prim/scal/err/check_positive_size.hpp>
#include <stan/math/prim/mat/err/check_pos_definite.hpp>
#include <stan/math/prim/mat/err/check_symmetric.hpp>
#include <stan/math/prim/scal/err/check_size_match.hpp>
#include <stan/math/prim/mat/err/constraint_tolerance.hpp>
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/meta/index_type.hpp>
#include <stan/math/prim/scal/meta/error_index.hpp>
#include <sstream>
#include <string>
namespace stan {
namespace math {
using Eigen::Dynamic;
template <typename T_y>
inline bool
check_corr_matrix(const char* function,
const char* name,
const Eigen::Matrix<T_y, Dynamic, Dynamic>& y) {
using Eigen::Matrix;
using stan::math::index_type;
typedef typename index_type<Matrix<T_y, Dynamic, Dynamic> >::type size_t;
check_size_match(function,
"Rows of correlation matrix", y.rows(),
"columns of correlation matrix", y.cols());
check_positive_size(function, name, "rows", y.rows());
check_symmetric(function, "y", y);
for (size_t k = 0; k < y.rows(); ++k) {
if (!(fabs(y(k, k) - 1.0) <= CONSTRAINT_TOLERANCE)) {
std::ostringstream msg;
msg << "is not a valid correlation matrix. "
<< name << "(" << stan::error_index::value + k
<< "," << stan::error_index::value + k
<< ") is ";
std::string msg_str(msg.str());
domain_error(function, name, y(k, k),
msg_str.c_str(),
", but should be near 1.0");
return false;
}
}
stan::math::check_pos_definite(function, "y", y);
return true;
}
}
}
#endif
stan::math::fabs
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:14
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::math::check_symmetric
bool check_symmetric(const char *function, const char *name, const Eigen::Matrix< T_y, Dynamic, Dynamic > &y)
Return true if the specified matrix is symmetric.
Definition: check_symmetric.hpp:38
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::check_pos_definite
bool check_pos_definite(const char *function, const char *name, const Eigen::Matrix< T_y, Dynamic, Dynamic > &y)
Return true if the specified square, symmetric matrix is positive definite.
Definition: check_pos_definite.hpp:38
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:19
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:32
Eigen.hpp
domain_error.hpp
error_index.hpp
check_positive_size.hpp
check_pos_definite.hpp
stan::math::check_corr_matrix
bool check_corr_matrix(const char *function, const char *name, const Eigen::Matrix< T_y, Dynamic, Dynamic > &y)
Return true if the specified matrix is a valid correlation matrix.
Definition: check_corr_matrix.hpp:46

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