Stan  2.10.0
probability, sampling & optimization
Public Types | Public Member Functions | Public Attributes | List of all members
stan::io::writer< T > Class Template Reference

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...
 

Detailed Description

template<typename T>
class stan::io::writer< T >

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.

Template Parameters
TBasic scalar type.

Definition at line 40 of file writer.hpp.

Member Typedef Documentation

template<typename T >
typedef Eigen::Array<T, Eigen::Dynamic, 1> stan::io::writer< T >::array_vec_t

Definition at line 50 of file writer.hpp.

template<typename T >
typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> stan::io::writer< T >::matrix_t

Definition at line 46 of file writer.hpp.

template<typename T >
typedef Eigen::Matrix<T, 1, Eigen::Dynamic> stan::io::writer< T >::row_vector_t

Definition at line 48 of file writer.hpp.

template<typename T >
typedef Eigen::Matrix<T, Eigen::Dynamic, 1> stan::io::writer< T >::vector_t

Definition at line 47 of file writer.hpp.

Constructor & Destructor Documentation

template<typename T >
stan::io::writer< T >::writer ( std::vector< T > &  data_r,
std::vector< int > &  data_i 
)
inline

Construct a writer that writes to the specified scalar and integer vectors.

Parameters
data_rScalar values.
data_iInteger values.

Definition at line 65 of file writer.hpp.

template<typename T >
stan::io::writer< T >::~writer ( )
inline

Destroy this writer.

Definition at line 77 of file writer.hpp.

Member Function Documentation

template<typename T >
void stan::io::writer< T >::cholesky_corr_unconstrain ( matrix_t y)
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).

Parameters
yConstrained covariance matrix.
Exceptions
std::runtime_errorif y has no elements or if it is not square

Definition at line 435 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::cholesky_factor_unconstrain ( matrix_t y)
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).

Parameters
yConstrained covariance matrix.
Exceptions
std::runtime_errorif y has no elements or if it is not square

Definition at line 413 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::corr_matrix_unconstrain ( matrix_t y)
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).

Parameters
yConstrained correlation matrix.
Exceptions
std::runtime_errorif the correlation matrix has no elements or is not a square matrix.
std::runtime_errorif 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.

template<typename T >
void stan::io::writer< T >::corr_unconstrain ( T &  y)
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().

Parameters
yCorrelation value.
Exceptions
std::runtime_errorif y is not between -1.0 and 1.0

Definition at line 192 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::cov_matrix_unconstrain ( matrix_t y)
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).

Parameters
yConstrained covariance matrix.
Exceptions
std::runtime_errorif y has no elements or if it is not square

Definition at line 457 of file writer.hpp.

template<typename T >
std::vector<int>& stan::io::writer< T >::data_i ( )
inline

Return a reference to the underlying vector of integer values that have been written.

Returns
Values that have been written.

Definition at line 96 of file writer.hpp.

template<typename T >
std::vector<T>& stan::io::writer< T >::data_r ( )
inline

Return a reference to the underlying vector of real values that have been written.

Returns
Values that have been written.

Definition at line 85 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::integer ( int  n)
inline

Write the specified integer to the sequence of integer values.

Parameters
nInteger to write.

Definition at line 105 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::matrix_lb_unconstrain ( double  lb,
matrix_t y 
)
inline

Definition at line 310 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::matrix_lub_unconstrain ( double  lb,
double  ub,
matrix_t y 
)
inline

Definition at line 345 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::matrix_ub_unconstrain ( double  ub,
matrix_t y 
)
inline

Definition at line 327 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::matrix_unconstrain ( const matrix_t y)
inline

Write the specified unconstrained matrix.

Parameters
yMatrix to write.

Definition at line 293 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::ordered_unconstrain ( vector_t y)
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).

Parameters
yAscendingly ordered vector.
Returns
Unconstrained vector corresponding to the specified vector.
Exceptions
std::runtime_errorif vector is not in ascending order.

Definition at line 226 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::positive_ordered_unconstrain ( vector_t y)
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).

Parameters
yPositive ascendingly ordered vector.
Returns
Unconstrained vector corresponding to the specified vector.
Exceptions
std::runtime_errorif vector is not in ascending order.

Definition at line 252 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::prob_unconstrain ( T &  y)
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().

Parameters
yProbability value.
Exceptions
std::runtime_errorif y is not between 0.0 and 1.0

Definition at line 207 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::row_vector_lb_unconstrain ( double  lb,
row_vector_t y 
)
inline

Definition at line 305 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::row_vector_lub_unconstrain ( double  lb,
double  ub,
row_vector_t y 
)
inline

Definition at line 340 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::row_vector_ub_unconstrain ( double  ub,
row_vector_t y 
)
inline

Definition at line 322 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::row_vector_unconstrain ( const vector_t y)
inline

Write the specified unconstrained vector.

Parameters
yVector to write.

Definition at line 282 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::scalar_lb_unconstrain ( double  lb,
T &  y 
)
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),

Parameters
lbLower bound.
yLower-bounded value.
Exceptions
std::runtime_errorif y is lower than the lower bound provided.

Definition at line 148 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::scalar_lub_unconstrain ( double  lb,
double  ub,
T &  y 
)
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).

Parameters
lbLower bound.
ubUpper bound.
yBounded value.
Exceptions
std::runtime_errorif y is not between the lower and upper bounds

Definition at line 178 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::scalar_pos_unconstrain ( T &  y)
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.

Parameters
yThe positive value.
Exceptions
std::runtime_errorif y is negative.

Definition at line 131 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::scalar_ub_unconstrain ( double  ub,
T &  y 
)
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).

Parameters
ubUpper bound.
yConstrained value.
Exceptions
std::runtime_errorif y is higher than the upper bound provided.

Definition at line 162 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::scalar_unconstrain ( T &  y)
inline

Write the unconstrained value corresponding to the specified scalar.

Here, the unconstrain operation is a no-op, which matches reader::scalar_constrain().

Parameters
yThe value.

Definition at line 116 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::simplex_unconstrain ( vector_t y)
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).

Parameters
ySimplex constrained value.
Returns
Unconstrained value.
Exceptions
std::runtime_errorif the vector is not a simplex.

Definition at line 393 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::unit_vector_unconstrain ( vector_t y)
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).

Parameters
ySimplex constrained value.
Returns
Unconstrained value.
Exceptions
std::runtime_errorif the vector is not a unit_vector.

Definition at line 369 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::vector_lb_unconstrain ( double  lb,
vector_t y 
)
inline

Definition at line 300 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::vector_lub_unconstrain ( double  lb,
double  ub,
vector_t y 
)
inline

Definition at line 335 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::vector_ub_unconstrain ( double  ub,
vector_t y 
)
inline

Definition at line 317 of file writer.hpp.

template<typename T >
void stan::io::writer< T >::vector_unconstrain ( const vector_t y)
inline

Write the specified unconstrained vector.

Parameters
yVector to write.

Definition at line 271 of file writer.hpp.

Member Data Documentation

template<typename T >
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.


The documentation for this class was generated from the following file:

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