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
offset_multiplier_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_CONSTRAINT_OFFSET_MULTIPLIER_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_OFFSET_MULTIPLIER_CONSTRAIN_HPP
3
14#include <cmath>
15
16namespace stan {
17namespace math {
18
42template <typename T, typename M, typename S,
44 T, M, S>* = nullptr>
45inline auto offset_multiplier_constrain(const T& x, const M& mu,
46 const S& sigma) {
47 const auto& mu_ref = to_ref(mu);
48 const auto& sigma_ref = to_ref(sigma);
50 check_matching_dims("offset_multiplier_constrain", "x", x, "mu", mu);
51 }
53 check_matching_dims("offset_multiplier_constrain", "x", x, "sigma", sigma);
55 check_matching_dims("offset_multiplier_constrain", "mu", mu, "sigma",
56 sigma);
57 }
58
59 check_finite("offset_multiplier_constrain", "offset", value_of_rec(mu_ref));
60 check_positive_finite("offset_multiplier_constrain", "multiplier",
61 value_of_rec(sigma_ref));
62 return stan::math::eval(fma(sigma_ref, x, mu_ref));
63}
64
92template <typename T, typename M, typename S, typename Lp,
95 T, M, S>* = nullptr>
96inline auto offset_multiplier_constrain(const T& x, const M& mu, const S& sigma,
97 Lp& lp) {
98 const auto& mu_ref = to_ref(mu);
99 const auto& sigma_ref = to_ref(sigma);
101 check_matching_dims("offset_multiplier_constrain", "x", x, "mu", mu);
102 }
104 check_matching_dims("offset_multiplier_constrain", "x", x, "sigma", sigma);
106 check_matching_dims("offset_multiplier_constrain", "mu", mu, "sigma",
107 sigma);
108 }
109
110 check_finite("offset_multiplier_constrain", "offset", value_of_rec(mu_ref));
111 check_positive_finite("offset_multiplier_constrain", "multiplier",
112 value_of_rec(sigma_ref));
113 if (math::size(sigma_ref) == 1) {
114 lp += sum(multiply_log(math::size(x), sigma_ref));
115 } else {
116 lp += sum(log(sigma_ref));
117 }
118 return stan::math::eval(fma(sigma_ref, x, mu_ref));
119}
120
124template <typename T, typename M, typename S,
126inline auto offset_multiplier_constrain(const std::vector<T>& x, const M& mu,
127 const S& sigma) {
128 std::vector<
129 plain_type_t<decltype(offset_multiplier_constrain(x[0], mu, sigma))>>
130 ret;
131 ret.reserve(x.size());
132 const auto& mu_ref = to_ref(mu);
133 const auto& sigma_ref = to_ref(sigma);
134 for (size_t i = 0; i < x.size(); ++i) {
135 ret.emplace_back(offset_multiplier_constrain(x[i], mu_ref, sigma_ref));
136 }
137 return ret;
138}
139
143template <typename T, typename M, typename S, typename Lp,
146inline auto offset_multiplier_constrain(const std::vector<T>& x, const M& mu,
147 const S& sigma, Lp& lp) {
148 std::vector<
149 plain_type_t<decltype(offset_multiplier_constrain(x[0], mu, sigma, lp))>>
150 ret;
151 ret.reserve(x.size());
152 const auto& mu_ref = to_ref(mu);
153 const auto& sigma_ref = to_ref(sigma);
154 for (size_t i = 0; i < x.size(); ++i) {
155 ret.emplace_back(offset_multiplier_constrain(x[i], mu_ref, sigma_ref, lp));
156 }
157 return ret;
158}
159
163template <typename T, typename M, typename S,
165inline auto offset_multiplier_constrain(const std::vector<T>& x, const M& mu,
166 const std::vector<S>& sigma) {
167 check_matching_dims("offset_multiplier_constrain", "x", x, "sigma", sigma);
168 std::vector<
169 plain_type_t<decltype(offset_multiplier_constrain(x[0], mu, sigma[0]))>>
170 ret;
171 ret.reserve(x.size());
172 const auto& mu_ref = to_ref(mu);
173 for (size_t i = 0; i < x.size(); ++i) {
174 ret.emplace_back(offset_multiplier_constrain(x[i], mu_ref, sigma[i]));
175 }
176 return ret;
177}
178
182template <typename T, typename M, typename S, typename Lp,
185inline auto offset_multiplier_constrain(const std::vector<T>& x, const M& mu,
186 const std::vector<S>& sigma, Lp& lp) {
187 check_matching_dims("offset_multiplier_constrain", "x", x, "sigma", sigma);
188 std::vector<plain_type_t<decltype(
189 offset_multiplier_constrain(x[0], mu, sigma[0], lp))>>
190 ret;
191 ret.reserve(x.size());
192 const auto& mu_ref = to_ref(mu);
193 for (size_t i = 0; i < x.size(); ++i) {
194 ret.emplace_back(offset_multiplier_constrain(x[i], mu_ref, sigma[i], lp));
195 }
196 return ret;
197}
198
202template <typename T, typename M, typename S,
204inline auto offset_multiplier_constrain(const std::vector<T>& x,
205 const std::vector<M>& mu,
206 const S& sigma) {
207 check_matching_dims("offset_multiplier_constrain", "x", x, "mu", mu);
208 std::vector<
209 plain_type_t<decltype(offset_multiplier_constrain(x[0], mu[0], sigma))>>
210 ret;
211 ret.reserve(x.size());
212 const auto& sigma_ref = to_ref(sigma);
213 for (size_t i = 0; i < x.size(); ++i) {
214 ret.emplace_back(offset_multiplier_constrain(x[i], mu[i], sigma_ref));
215 }
216 return ret;
217}
218
222template <typename T, typename M, typename S, typename Lp,
225inline auto offset_multiplier_constrain(const std::vector<T>& x,
226 const std::vector<M>& mu,
227 const S& sigma, Lp& lp) {
228 check_matching_dims("offset_multiplier_constrain", "x", x, "mu", mu);
229 std::vector<plain_type_t<decltype(
230 offset_multiplier_constrain(x[0], mu[0], sigma, lp))>>
231 ret;
232 ret.reserve(x.size());
233 const auto& sigma_ref = to_ref(sigma);
234 for (size_t i = 0; i < x.size(); ++i) {
235 ret.emplace_back(offset_multiplier_constrain(x[i], mu[i], sigma_ref, lp));
236 }
237 return ret;
238}
239
243template <typename T, typename M, typename S>
244inline auto offset_multiplier_constrain(const std::vector<T>& x,
245 const std::vector<M>& mu,
246 const std::vector<S>& sigma) {
247 check_matching_dims("offset_multiplier_constrain", "x", x, "mu", mu);
248 check_matching_dims("offset_multiplier_constrain", "x", x, "sigma", sigma);
249 std::vector<plain_type_t<decltype(
250 offset_multiplier_constrain(x[0], mu[0], sigma[0]))>>
251 ret;
252 ret.reserve(x.size());
253 for (size_t i = 0; i < x.size(); ++i) {
254 ret.emplace_back(offset_multiplier_constrain(x[i], mu[i], sigma[i]));
255 }
256 return ret;
257}
258
262template <typename T, typename M, typename S, typename Lp,
264inline auto offset_multiplier_constrain(const std::vector<T>& x,
265 const std::vector<M>& mu,
266 const std::vector<S>& sigma, Lp& lp) {
267 check_matching_dims("offset_multiplier_constrain", "x", x, "mu", mu);
268 check_matching_dims("offset_multiplier_constrain", "x", x, "sigma", sigma);
269 std::vector<plain_type_t<decltype(
270 offset_multiplier_constrain(x[0], mu[0], sigma[0], lp))>>
271 ret;
272 ret.reserve(x.size());
273 for (size_t i = 0; i < x.size(); ++i) {
274 ret.emplace_back(offset_multiplier_constrain(x[i], mu[i], sigma[i], lp));
275 }
276 return ret;
277}
278
304template <bool Jacobian, typename T, typename M, typename S, typename Lp,
306inline auto offset_multiplier_constrain(const T& x, const M& mu, const S& sigma,
307 Lp& lp) {
308 if constexpr (Jacobian) {
309 return offset_multiplier_constrain(x, mu, sigma, lp);
310 } else {
311 return offset_multiplier_constrain(x, mu, sigma);
312 }
313}
314
315} // namespace math
316} // namespace stan
317
318#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.
require_all_not_t< is_nonscalar_prim_or_rev_kernel_expression< std::decay_t< Types > >... > require_all_not_nonscalar_prim_or_rev_kernel_expression_t
Require none of the types satisfy is_nonscalar_prim_or_rev_kernel_expression.
require_not_t< is_std_vector< std::decay_t< T > > > require_not_std_vector_t
Require type does not satisfy is_std_vector.
require_all_not_t< is_std_vector< std::decay_t< Types > >... > require_all_not_std_vector_t
Require none of the types satisfy is_std_vector.
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
Definition size.hpp:19
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > multiply_log(const fvar< T > &x1, const fvar< T > &x2)
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
Definition eval.hpp:20
fvar< T > log(const fvar< T > &x)
Definition log.hpp:18
void check_matching_dims(const char *function, const char *name1, const T1 &y1, const char *name2, const T2 &y2)
Check if the two containers have the same dimensions.
auto offset_multiplier_constrain(const T &x, const M &mu, const S &sigma)
Return the linearly transformed value for the specified unconstrained input and specified offset and ...
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
fvar< return_type_t< T1, T2, T3 > > fma(const fvar< T1 > &x1, const fvar< T2 > &x2, const fvar< T3 > &x3)
The fused multiply-add operation (C99).
Definition fma.hpp:60
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Check if a type is derived from Eigen::EigenBase or is a var_value whose value_type is derived from E...
Definition is_matrix.hpp:18