| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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
16 namespace stan {
17
18 namespace math {
19 using Eigen::Dynamic;
36 template <typename T_y>
37 inline bool
38 check_pos_definite(const char* function,
39 const char* name,
40 const Eigen::Matrix<T_y, Dynamic, Dynamic>& y) {
41 check_symmetric(function, name, y);
42 check_positive_size(function, name, "rows", y.rows());
43
44 if (y.rows() == 1 && !(y(0, 0) > CONSTRAINT_TOLERANCE))
45 domain_error(function, name, y, "is not positive definite: ");
46
47 using Eigen::LDLT;
48 using Eigen::Matrix;
49 using Eigen::Dynamic;
50 LDLT< Matrix<double, Dynamic, Dynamic> > cholesky
51 = value_of_rec(y).ldlt();
52 if (cholesky.info() != Eigen::Success
53 || !cholesky.isPositive()
54 || (cholesky.vectorD().array() <= CONSTRAINT_TOLERANCE).any())
55 domain_error(function, name, y, "is not positive definite:\n");
56 check_not_nan(function, name, y);
57 return true;
58 }
59
60 }
61 }
62 #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:63
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::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
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
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::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::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
check_positive_size.hpp

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