Stan Math Library: stan/math/prim/mat/err/check_pos_definite.hpp Source File

| Stan Math Library 2.10.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
17 namespace math {
18
35 template <typename T_y>
36 inline bool
37 check_pos_definite(
38 const char* function,
39 const char* name,
40 const Eigen::Matrix<T_y, Eigen::Dynamic, Eigen::Dynamic>& y
41 ) {
42 check_symmetric(function, name, y);
43 check_positive_size(function, name, "rows", y.rows());
44
45 if (y.rows() == 1 && !(y(0, 0) > CONSTRAINT_TOLERANCE))
46 domain_error(function, name, y, "is not positive definite: ");
47
48 using Eigen::LDLT;
49 using Eigen::Matrix;
50 using Eigen::Dynamic;
51 LDLT< Matrix<double, Dynamic, Dynamic> > cholesky
52 = value_of_rec(y).ldlt();
53 if (cholesky.info() != Eigen::Success
54 || !cholesky.isPositive()
55 || (cholesky.vectorD().array() <= 0.0).any())
56 domain_error(function, name, y, "is not positive definite:\n");
57 check_not_nan(function, name, y);
58 return true;
59 }
60
75 template <typename Derived>
76 inline bool
77 check_pos_definite(const char* function,
78 const char* name,
79 const Eigen::LDLT<Derived>& cholesky) {
80 if (cholesky.info() != Eigen::Success
81 || !cholesky.isPositive()
82 || !(cholesky.vectorD().array() > 0.0).all())
83 domain_error(function, "LDLT decomposition of", " failed", name);
84 return true;
85 }
86
101 template <typename Derived>
102 inline bool
103 check_pos_definite(const char* function,
104 const char* name,
105 const Eigen::LLT<Derived>& cholesky) {
106 if (cholesky.info() != Eigen::Success
107 || !(cholesky.matrixLLT().diagonal().array() > 0.0).all())
108 domain_error(function, "Cholesky decomposition of", " failed", name);
109 return true;
110 }
111
112 }
113 }
114 #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
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:32
Eigen.hpp
stan::math::check_pos_definite
bool check_pos_definite(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified square, symmetric matrix is positive definite.
Definition: check_pos_definite.hpp:37
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:37
check_positive_size.hpp

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