Automatic Differentiation
 
Loading...
Searching...
No Matches
corr_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_CORR_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_FUN_CORR_CONSTRAIN_HPP
3
9#include <cmath>
10
11namespace stan {
12namespace math {
13
26template <typename T>
27inline plain_type_t<T> corr_constrain(const T& x) {
28 return tanh(x);
29}
30
45template <typename T_x, typename T_lp>
46inline auto corr_constrain(const T_x& x, T_lp& lp) {
47 plain_type_t<T_x> tanh_x = tanh(x);
48 lp += sum(log1m(square(tanh_x)));
49 return tanh_x;
50}
51
67template <bool Jacobian, typename T_x, typename T_lp>
68inline auto corr_constrain(const T_x& x, T_lp& lp) {
69 if (Jacobian) {
70 return corr_constrain(x, lp);
71 } else {
72 return corr_constrain(x);
73 }
74}
75
76} // namespace math
77} // namespace stan
78#endif
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:22
fvar< T > tanh(const fvar< T > &x)
Definition tanh.hpp:15
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...
fvar< T > log1m(const fvar< T > &x)
Definition log1m.hpp:12
fvar< T > square(const fvar< T > &x)
Definition square.hpp:12
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9