![]() |
Stan
2.10.0
probability, sampling & optimization
|
A stream-based writer for integer, scalar, vector, matrix and array data types, which transforms from constrained to a sequence of constrained variables. More...
#include <writer.hpp>
Public Types | |
typedef Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > | matrix_t |
typedef Eigen::Matrix< T, Eigen::Dynamic, 1 > | vector_t |
typedef Eigen::Matrix< T, 1, Eigen::Dynamic > | row_vector_t |
typedef Eigen::Array< T, Eigen::Dynamic, 1 > | array_vec_t |
Public Member Functions | |
writer (std::vector< T > &data_r, std::vector< int > &data_i) | |
Construct a writer that writes to the specified scalar and integer vectors. More... | |
~writer () | |
Destroy this writer. More... | |
std::vector< T > & | data_r () |
Return a reference to the underlying vector of real values that have been written. More... | |
std::vector< int > & | data_i () |
Return a reference to the underlying vector of integer values that have been written. More... | |
void | integer (int n) |
Write the specified integer to the sequence of integer values. More... | |
void | scalar_unconstrain (T &y) |
Write the unconstrained value corresponding to the specified scalar. More... | |
void | scalar_pos_unconstrain (T &y) |
Write the unconstrained value corresponding to the specified positive-constrained scalar. More... | |
void | scalar_lb_unconstrain (double lb, T &y) |
Return the unconstrained version of the specified input, which is constrained to be above the specified lower bound. More... | |
void | scalar_ub_unconstrain (double ub, T &y) |
Write the unconstrained value corresponding to the specified lower-bounded value. More... | |
void | scalar_lub_unconstrain (double lb, double ub, T &y) |
Write the unconstrained value corresponding to the specified value with the specified bounds. More... | |
void | corr_unconstrain (T &y) |
Write the unconstrained value corresponding to the specified correlation-constrained variable. More... | |
void | prob_unconstrain (T &y) |
Write the unconstrained value corresponding to the specified probability value. More... | |
void | ordered_unconstrain (vector_t &y) |
Write the unconstrained vector that corresponds to the specified ascendingly ordered vector. More... | |
void | positive_ordered_unconstrain (vector_t &y) |
Write the unconstrained vector that corresponds to the specified postiive ascendingly ordered vector. More... | |
void | vector_unconstrain (const vector_t &y) |
Write the specified unconstrained vector. More... | |
void | row_vector_unconstrain (const vector_t &y) |
Write the specified unconstrained vector. More... | |
void | matrix_unconstrain (const matrix_t &y) |
Write the specified unconstrained matrix. More... | |
void | vector_lb_unconstrain (double lb, vector_t &y) |
void | row_vector_lb_unconstrain (double lb, row_vector_t &y) |
void | matrix_lb_unconstrain (double lb, matrix_t &y) |
void | vector_ub_unconstrain (double ub, vector_t &y) |
void | row_vector_ub_unconstrain (double ub, row_vector_t &y) |
void | matrix_ub_unconstrain (double ub, matrix_t &y) |
void | vector_lub_unconstrain (double lb, double ub, vector_t &y) |
void | row_vector_lub_unconstrain (double lb, double ub, row_vector_t &y) |
void | matrix_lub_unconstrain (double lb, double ub, matrix_t &y) |
void | unit_vector_unconstrain (vector_t &y) |
Write the unconstrained vector corresponding to the specified unit_vector value. More... | |
void | simplex_unconstrain (vector_t &y) |
Write the unconstrained vector corresponding to the specified simplex value. More... | |
void | cholesky_factor_unconstrain (matrix_t &y) |
Writes the unconstrained Cholesky factor corresponding to the specified constrained matrix. More... | |
void | cholesky_corr_unconstrain (matrix_t &y) |
Writes the unconstrained Cholesky factor for a correlation matrix corresponding to the specified constrained matrix. More... | |
void | cov_matrix_unconstrain (matrix_t &y) |
Writes the unconstrained covariance matrix corresponding to the specified constrained correlation matrix. More... | |
void | corr_matrix_unconstrain (matrix_t &y) |
Writes the unconstrained correlation matrix corresponding to the specified constrained correlation matrix. More... | |
Public Attributes | |
const double | CONSTRAINT_TOLERANCE |
This is the tolerance for checking arithmetic bounds in rank and in simplexes. More... | |
A stream-based writer for integer, scalar, vector, matrix and array data types, which transforms from constrained to a sequence of constrained variables.
This class converts constrained values to unconstrained values with mappings that invert those defined in stan::io::reader
to convert unconstrained values to constrained values.
T | Basic scalar type. |
Definition at line 40 of file writer.hpp.
typedef Eigen::Array<T, Eigen::Dynamic, 1> stan::io::writer< T >::array_vec_t |
Definition at line 50 of file writer.hpp.
typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> stan::io::writer< T >::matrix_t |
Definition at line 46 of file writer.hpp.
typedef Eigen::Matrix<T, 1, Eigen::Dynamic> stan::io::writer< T >::row_vector_t |
Definition at line 48 of file writer.hpp.
typedef Eigen::Matrix<T, Eigen::Dynamic, 1> stan::io::writer< T >::vector_t |
Definition at line 47 of file writer.hpp.
|
inline |
Construct a writer that writes to the specified scalar and integer vectors.
data_r | Scalar values. |
data_i | Integer values. |
Definition at line 65 of file writer.hpp.
|
inline |
Destroy this writer.
Definition at line 77 of file writer.hpp.
|
inline |
Writes the unconstrained Cholesky factor for a correlation matrix corresponding to the specified constrained matrix.
The unconstraining operation is the inverse of the constraining operation in cov_matrix_constrain(Matrix<T,Dynamic,Dynamic)
.
y | Constrained covariance matrix. |
std::runtime_error | if y has no elements or if it is not square |
Definition at line 435 of file writer.hpp.
|
inline |
Writes the unconstrained Cholesky factor corresponding to the specified constrained matrix.
The unconstraining operation is the inverse of the constraining operation in cov_matrix_constrain(Matrix<T,Dynamic,Dynamic)
.
y | Constrained covariance matrix. |
std::runtime_error | if y has no elements or if it is not square |
Definition at line 413 of file writer.hpp.
|
inline |
Writes the unconstrained correlation matrix corresponding to the specified constrained correlation matrix.
The unconstraining operation is the inverse of the constraining operation in corr_matrix_constrain(Matrix<T,Dynamic,Dynamic)
.
y | Constrained correlation matrix. |
std::runtime_error | if the correlation matrix has no elements or is not a square matrix. |
std::runtime_error | if the correlation matrix cannot be factorized by factor_cov_matrix() or if the sds returned by factor_cov_matrix() on log scale are unconstrained. |
Definition at line 492 of file writer.hpp.
|
inline |
Write the unconstrained value corresponding to the specified correlation-constrained variable.
The unconstraining transform is atanh(y)
, which reverses the transfrom in corr_constrain()
.
y | Correlation value. |
std::runtime_error | if y is not between -1.0 and 1.0 |
Definition at line 192 of file writer.hpp.
|
inline |
Writes the unconstrained covariance matrix corresponding to the specified constrained correlation matrix.
The unconstraining operation is the inverse of the constraining operation in cov_matrix_constrain(Matrix<T,Dynamic,Dynamic)
.
y | Constrained covariance matrix. |
std::runtime_error | if y has no elements or if it is not square |
Definition at line 457 of file writer.hpp.
|
inline |
Return a reference to the underlying vector of integer values that have been written.
Definition at line 96 of file writer.hpp.
|
inline |
Return a reference to the underlying vector of real values that have been written.
Definition at line 85 of file writer.hpp.
|
inline |
Write the specified integer to the sequence of integer values.
n | Integer to write. |
Definition at line 105 of file writer.hpp.
|
inline |
Definition at line 310 of file writer.hpp.
|
inline |
Definition at line 345 of file writer.hpp.
|
inline |
Definition at line 327 of file writer.hpp.
|
inline |
Write the specified unconstrained matrix.
y | Matrix to write. |
Definition at line 293 of file writer.hpp.
|
inline |
Write the unconstrained vector that corresponds to the specified ascendingly ordered vector.
The unconstraining transform is defined for input vector y
to produce an output vector x
of the same size, defined by x[0] = log(y[0])
and by x[k] = log(y[k] - y[k-1])
for k > 0
. This unconstraining transform inverts the constraining transform specified in ordered_constrain(size_t)
.
y | Ascendingly ordered vector. |
std::runtime_error | if vector is not in ascending order. |
Definition at line 226 of file writer.hpp.
|
inline |
Write the unconstrained vector that corresponds to the specified postiive ascendingly ordered vector.
The unconstraining transform is defined for input vector y
to produce an output vector x
of the same size, defined by x[0] = log(y[0])
and by x[k] = log(y[k] - y[k-1])
for k > 0
. This unconstraining transform inverts the constraining transform specified in positive_ordered_constrain(size_t)
.
y | Positive ascendingly ordered vector. |
std::runtime_error | if vector is not in ascending order. |
Definition at line 252 of file writer.hpp.
|
inline |
Write the unconstrained value corresponding to the specified probability value.
The unconstraining transform is logit(y)
, which inverts the constraining transform defined in prob_constrain()
.
y | Probability value. |
std::runtime_error | if y is not between 0.0 and 1.0 |
Definition at line 207 of file writer.hpp.
|
inline |
Definition at line 305 of file writer.hpp.
|
inline |
Definition at line 340 of file writer.hpp.
|
inline |
Definition at line 322 of file writer.hpp.
|
inline |
Write the specified unconstrained vector.
y | Vector to write. |
Definition at line 282 of file writer.hpp.
|
inline |
Return the unconstrained version of the specified input, which is constrained to be above the specified lower bound.
The unconstraining transform is log(y - lb)
, which inverts the constraining transform defined in reader::scalar_lb_constrain(double)
,
lb | Lower bound. |
y | Lower-bounded value. |
std::runtime_error | if y is lower than the lower bound provided. |
Definition at line 148 of file writer.hpp.
|
inline |
Write the unconstrained value corresponding to the specified value with the specified bounds.
The unconstraining transform is given by reader::logit((y-L)/(U-L))
, which inverts the constraining transform defined in scalar_lub_constrain(double,double)
.
lb | Lower bound. |
ub | Upper bound. |
y | Bounded value. |
std::runtime_error | if y is not between the lower and upper bounds |
Definition at line 178 of file writer.hpp.
|
inline |
Write the unconstrained value corresponding to the specified positive-constrained scalar.
The transformation applied is log(y)
, which is the inverse of constraining transform specified in reader::scalar_pos_constrain()
.
This method will fail if the argument is not non-negative.
y | The positive value. |
std::runtime_error | if y is negative. |
Definition at line 131 of file writer.hpp.
|
inline |
Write the unconstrained value corresponding to the specified lower-bounded value.
The unconstraining transform is log(ub - y)
, which reverses the constraining transform defined in reader::scalar_ub_constrain(double)
.
ub | Upper bound. |
y | Constrained value. |
std::runtime_error | if y is higher than the upper bound provided. |
Definition at line 162 of file writer.hpp.
|
inline |
Write the unconstrained value corresponding to the specified scalar.
Here, the unconstrain operation is a no-op, which matches reader::scalar_constrain()
.
y | The value. |
Definition at line 116 of file writer.hpp.
|
inline |
Write the unconstrained vector corresponding to the specified simplex value.
If the specified constrained simplex is of size K
, the returned unconstrained vector is of size K-1
.
The transform takes y = y[1],...,y[K]
and produces the unconstrained vector. This inverts the constraining transform of simplex_constrain(size_t)
.
y | Simplex constrained value. |
std::runtime_error | if the vector is not a simplex. |
Definition at line 393 of file writer.hpp.
|
inline |
Write the unconstrained vector corresponding to the specified unit_vector value.
If the specified constrained unit_vector is of size K
, the returned unconstrained vector is of size K-1
.
The transform takes y = y[1],...,y[K]
and produces the unconstrained vector. This inverts the constraining transform of unit_vector_constrain(size_t)
.
y | Simplex constrained value. |
std::runtime_error | if the vector is not a unit_vector. |
Definition at line 369 of file writer.hpp.
|
inline |
Definition at line 300 of file writer.hpp.
|
inline |
Definition at line 335 of file writer.hpp.
|
inline |
Definition at line 317 of file writer.hpp.
|
inline |
Write the specified unconstrained vector.
y | Vector to write. |
Definition at line 271 of file writer.hpp.
const double stan::io::writer< T >::CONSTRAINT_TOLERANCE |
This is the tolerance for checking arithmetic bounds in rank and in simplexes.
The current value is 1E-8
.
Definition at line 56 of file writer.hpp.