1#ifndef STAN_MATH_REV_FUN_LOG_MIX_HPP
2#define STAN_MATH_REV_FUN_LOG_MIX_HPP
25 double theta_val,
double lambda1_val,
double lambda2_val,
26 double& one_m_exp_lam2_m_lam1,
double& one_m_t_prod_exp_lam2_m_lam1,
27 double& one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1) {
29 double lam2_m_lam1 = lambda2_val - lambda1_val;
30 double exp_lam2_m_lam1 =
exp(lam2_m_lam1);
31 one_m_exp_lam2_m_lam1 = 1 - exp_lam2_m_lam1;
32 double one_m_t = 1 - theta_val;
33 one_m_t_prod_exp_lam2_m_lam1 = one_m_t * exp_lam2_m_lam1;
34 one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1
35 = 1 / (theta_val + one_m_t_prod_exp_lam2_m_lam1);
77template <
typename T_theta,
typename T_lambda1,
typename T_lambda2,
80 const T_theta& theta,
const T_lambda1& lambda1,
const T_lambda2& lambda2) {
85 double theta_double =
value_of(theta);
86 const double lambda1_double =
value_of(lambda1);
87 const double lambda2_double =
value_of(lambda2);
89 double log_mix_function_value
90 =
log_mix(theta_double, lambda1_double, lambda2_double);
92 double one_m_exp_lam2_m_lam1(0.0);
93 double one_m_t_prod_exp_lam2_m_lam1(0.0);
94 double one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1(0.0);
96 if (lambda1 > lambda2) {
98 one_m_exp_lam2_m_lam1, one_m_t_prod_exp_lam2_m_lam1,
99 one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1);
102 one_m_exp_lam2_m_lam1, one_m_t_prod_exp_lam2_m_lam1,
103 one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1);
104 one_m_exp_lam2_m_lam1 = -one_m_exp_lam2_m_lam1;
105 theta_double = one_m_t_prod_exp_lam2_m_lam1;
106 one_m_t_prod_exp_lam2_m_lam1 = 1.0 -
value_of(theta);
110 partials<0>(ops_partials)[0]
111 = one_m_exp_lam2_m_lam1 * one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1;
114 partials<1>(ops_partials)[0]
115 = theta_double * one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1;
118 partials<2>(ops_partials)[0] = one_m_t_prod_exp_lam2_m_lam1
119 * one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1;
122 return ops_partials.build(log_mix_function_value);
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
require_any_t< is_var< std::decay_t< Types > >... > require_any_var_t
Require any of the types satisfy is_var.
T value_of(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > log_mix(const fvar< T > &theta, const fvar< T > &lambda1, const fvar< T > &lambda2)
Return the log mixture density with specified mixing proportion and log densities and its derivative ...
void log_mix_partial_helper(const T_theta &theta, const T_lambda1 &lambda1, const T_lambda2 &lambda2, promote_args_t< T_theta, T_lambda1, T_lambda2 >(&partials_array)[N])
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
fvar< T > exp(const fvar< T > &x)
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...