Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ check_simplex()

template<typename T , require_matrix_t< T > * = nullptr>
void stan::math::check_simplex ( const char *  function,
const char *  name,
const T &  theta 
)

Throw an exception if the specified vector is not a simplex.

Throw an exception if each vector in a standard vector is not a simplex.

To be a simplex, all values must be greater than or equal to 0 and the values must sum to 1. A valid simplex is one where the sum of the elements is equal to 1. This function tests that the sum is within the tolerance specified by CONSTRAINT_TOLERANCE. This function only accepts Eigen vectors, statically typed vectors, not general matrices with 1 column.

Template Parameters
TA type inheriting from Eigen::EigenBase
Parameters
functionFunction name (for error messages)
nameVariable name (for error messages)
thetaVector to test
Exceptions
`std::invalid_argument`if theta is a 0-vector
`std::domain_error`if the vector is not a simplex or if any element is NaN

To be a simplex, all values must be greater than or equal to 0 and the values must sum to 1. A valid simplex is one where the sum of the elements is equal to 1. This function tests that the sum is within the tolerance specified by CONSTRAINT_TOLERANCE. This function only accepts Eigen vectors, statically typed vectors, not general matrices with 1 column.

Template Parameters
TA standard vector with inner type inheriting from Eigen::EigenBase
Parameters
functionFunction name (for error messages)
nameVariable name (for error messages)
thetaVector to test.
Exceptions
`std::invalid_argument`if theta is a 0-vector
`std::domain_error`if the vector is not a simplex or if any element is NaN

Definition at line 34 of file check_simplex.hpp.