Stan Math Library  2.15.0
reverse mode automatic differentiation
corr_matrix_free.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_CORR_MATRIX_FREE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_CORR_MATRIX_FREE_HPP
3 
11 #include <cmath>
12 
13 namespace stan {
14  namespace math {
15 
36  template <typename T>
37  Eigen::Matrix<T, Eigen::Dynamic, 1>
38  corr_matrix_free(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>&
39  y) {
40  check_square("corr_matrix_free", "y", y);
41  check_nonzero_size("corr_matrix_free", "y", y);
42 
43  using Eigen::Array;
44  using Eigen::Dynamic;
45  using Eigen::Matrix;
46  typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
47 
48  size_type k = y.rows();
49  size_type k_choose_2 = (k * (k-1)) / 2;
50  Array<T, Dynamic, 1> x(k_choose_2);
51  Array<T, Dynamic, 1> sds(k);
52  bool successful = factor_cov_matrix(y, x, sds);
53  if (!successful)
54  domain_error("corr_matrix_free",
55  "factor_cov_matrix failed on y", y, "");
56  for (size_type i = 0; i < k; ++i) {
57  check_bounded("corr_matrix_free", "log(sd)",
59  }
60  return x.matrix();
61  }
62  }
63 }
64 #endif
void check_nonzero_size(const char *function, const char *name, const T_y &y)
Check if the specified matrix/vector is of non-zero size.
void check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Check if the value is between the low and high values, inclusively.
const double CONSTRAINT_TOLERANCE
The tolerance for checking arithmetic bounds In rank and in simplexes.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:13
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
bool factor_cov_matrix(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &Sigma, Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs, Eigen::Array< T, Eigen::Dynamic, 1 > &sds)
This function is intended to make starting values, given a covariance matrix Sigma.
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.
void check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is square.
Eigen::Matrix< T, Eigen::Dynamic, 1 > corr_matrix_free(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &y)
Return the vector of unconstrained partial correlations that define the specified correlation matrix ...

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