Automatic Differentiation
 
Loading...
Searching...
No Matches
read_cov_matrix.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_READ_COV_MATRIX_HPP
2#define STAN_MATH_REV_FUN_READ_COV_MATRIX_HPP
3
10
11namespace stan {
12namespace math {
13
27template <typename T_CPCs, typename T_sds,
28 require_all_var_vector_t<T_CPCs, T_sds>* = nullptr>
29var_value<Eigen::MatrixXd> read_cov_matrix(const T_CPCs& CPCs, const T_sds& sds,
30 scalar_type_t<T_CPCs>& log_prob) {
31 return multiply_lower_tri_self_transpose(read_cov_L(CPCs, sds, log_prob));
32}
33
44template <typename T_CPCs, typename T_sds,
47 const T_sds& sds) {
48 size_t K = sds.rows();
49
52 = sds.val().matrix().asDiagonal() * corr_L.val();
53
54 reverse_pass_callback([sds, corr_L, prod]() mutable {
55 corr_L.adj() += sds.val().matrix().asDiagonal() * prod.adj();
56 sds.adj() += (prod.adj().cwiseProduct(corr_L.val())).rowwise().sum();
57 });
58
60}
61
62} // namespace math
63} // namespace stan
64
65#endif
require_all_t< is_var_vector< std::decay_t< Types > >... > require_all_var_vector_t
Require all of the types satisfy is_var_vector.
Eigen::Matrix< value_type_t< EigMat >, EigMat::RowsAtCompileTime, EigMat::RowsAtCompileTime > multiply_lower_tri_self_transpose(const EigMat &m)
Eigen::Matrix< value_type_t< T_CPCs >, Eigen::Dynamic, Eigen::Dynamic > read_cov_matrix(const T_CPCs &CPCs, const T_sds &sds, value_type_t< T_CPCs > &log_prob)
A generally worse alternative to call prior to evaluating the density of an elliptical distribution.
value_type_t< T > prod(const T &m)
Calculates product of given kernel generator expression elements.
Definition prod.hpp:21
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
Eigen::Matrix< value_type_t< T_CPCs >, Eigen::Dynamic, Eigen::Dynamic > read_cov_L(const T_CPCs &CPCs, const T_sds &sds, value_type_t< T_CPCs > &log_prob)
This is the function that should be called prior to evaluating the density of any elliptical distribu...
Eigen::Matrix< value_type_t< T >, Eigen::Dynamic, Eigen::Dynamic > read_corr_L(const T &CPCs, size_t K)
Return the Cholesky factor of the correlation matrix of the specified dimensionality corresponding to...
typename scalar_type< T >::type scalar_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...