Loading [MathJax]/extensions/TeX/AMSsymbols.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
corr_matrix_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_CONSTRAINT_CORR_MATRIX_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_CORR_MATRIX_CONSTRAIN_HPP
3
9#include <stdexcept>
10
11namespace stan {
12namespace math {
13
39template <typename T, require_eigen_col_vector_t<T>* = nullptr>
40inline Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
41corr_matrix_constrain(const T& x, Eigen::Index k) {
42 Eigen::Index k_choose_2 = (k * (k - 1)) / 2;
43 check_size_match("cov_matrix_constrain", "x.size()", x.size(), "k_choose_2",
44 k_choose_2);
45 return read_corr_matrix(corr_constrain(x), k);
46}
47
70template <typename T, typename Lp, require_eigen_col_vector_t<T>* = nullptr,
71 require_convertible_t<return_type_t<T>, Lp>* = nullptr>
72inline Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
73corr_matrix_constrain(const T& x, Eigen::Index k, Lp& lp) {
74 Eigen::Index k_choose_2 = (k * (k - 1)) / 2;
75 check_size_match("cov_matrix_constrain", "x.size()", x.size(), "k_choose_2",
76 k_choose_2);
77 return read_corr_matrix(corr_constrain(x, lp), k, lp);
78}
79
93template <typename T, require_std_vector_t<T>* = nullptr>
94inline auto corr_matrix_constrain(const T& y, int K) {
96 y, [K](auto&& v) { return corr_matrix_constrain(v, K); });
97}
98
115template <typename T, typename Lp, require_std_vector_t<T>* = nullptr,
116 require_convertible_t<return_type_t<T>, Lp>* = nullptr>
117inline auto corr_matrix_constrain(const T& y, int K, Lp& lp) {
119 y, [&lp, K](auto&& v) { return corr_matrix_constrain(v, K, lp); });
120}
121
143template <bool Jacobian, typename T, typename Lp,
145inline auto corr_matrix_constrain(const T& x, Eigen::Index k, Lp& lp) {
146 if constexpr (Jacobian) {
147 return corr_matrix_constrain(x, k, lp);
148 } else {
149 return corr_matrix_constrain(x, k);
150 }
151}
152
153} // namespace math
154} // namespace stan
155
156#endif
require_t< std::is_convertible< std::decay_t< T >, std::decay_t< S > > > require_convertible_t
Require types T and S satisfies std::is_convertible.
Eigen::Matrix< value_type_t< T >, Eigen::Dynamic, Eigen::Dynamic > corr_matrix_constrain(const T &x, Eigen::Index k)
Return the correlation matrix of the specified dimensionality derived from the specified vector of un...
Eigen::Matrix< value_type_t< T_CPCs >, Eigen::Dynamic, Eigen::Dynamic > read_corr_matrix(const T_CPCs &CPCs, size_t K)
Return the correlation matrix of the specified dimensionality corresponding to the specified canonica...
plain_type_t< T > corr_constrain(const T &x)
Return the result of transforming the specified scalar or container of values to have a valid correla...
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...