| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

check_pos_definite.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_ERR_CHECK_POS_DEFINITE_HPP
2 #define STAN_MATH_PRIM_MAT_ERR_CHECK_POS_DEFINITE_HPP
3
4 #include <stan/math/prim/mat/meta/get.hpp>
5 #include <stan/math/prim/mat/meta/length.hpp>
6 #include <stan/math/prim/mat/meta/is_vector.hpp>
7 #include <stan/math/prim/mat/meta/is_vector_like.hpp>
8 #include <stan/math/prim/scal/err/check_not_nan.hpp>
9 #include <stan/math/prim/scal/err/domain_error.hpp>
10 #include <stan/math/prim/mat/err/check_symmetric.hpp>
11 #include <stan/math/prim/mat/err/constraint_tolerance.hpp>
12 #include <stan/math/prim/scal/err/check_positive_size.hpp>
13 #include <stan/math/prim/mat/fun/Eigen.hpp>
14 #include <stan/math/prim/mat/fun/value_of_rec.hpp>
15 namespace stan {
16 namespace math {
17
32 template <typename T_y>
33 inline bool check_pos_definite(const char* function, const char* name,
34 const Eigen::Matrix<T_y, -1, -1>& y) {
35 check_symmetric(function, name, y);
36 check_positive_size(function, name, "rows", y.rows());
37 if (y.rows() == 1 && !(y(0, 0) > CONSTRAINT_TOLERANCE))
38 domain_error(function, name, "is not positive definite.", "");
39
40 Eigen::LDLT<Eigen::MatrixXd> cholesky = value_of_rec(y).ldlt();
41 if (cholesky.info() != Eigen::Success
42 || !cholesky.isPositive()
43 || (cholesky.vectorD().array() <= 0.0).any())
44 domain_error(function, name, "is not positive definite.", "");
45 check_not_nan(function, name, y);
46 return true;
47 }
48
62 template <typename Derived>
63 inline bool check_pos_definite(const char* function, const char* name,
64 const Eigen::LDLT<Derived>& cholesky) {
65 if (cholesky.info() != Eigen::Success
66 || !cholesky.isPositive()
67 || !(cholesky.vectorD().array() > 0.0).all())
68 domain_error(function, "LDLT decomposition of", " failed", name);
69 return true;
70 }
71
87 template <typename Derived>
88 inline bool check_pos_definite(const char* function, const char* name,
89 const Eigen::LLT<Derived>& cholesky) {
90 if (cholesky.info() != Eigen::Success
91 || !(cholesky.matrixLLT().diagonal().array() > 0.0).all())
92 domain_error(function, "Matrix", " is not positive definite", name);
93 return true;
94 }
95
96 }
97 }
98 #endif
check_not_nan.hpp
value_of_rec.hpp
stan::math::check_not_nan
bool check_not_nan(const char *function, const char *name, const T_y &y)
Return true if y is not NaN.
Definition: check_not_nan.hpp:60
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
stan::math::value_of_rec
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of_rec.hpp:21
is_vector_like.hpp
get.hpp
length.hpp
is_vector.hpp
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::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_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
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

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