1#ifndef STAN_MATH_REV_FUN_LOG_MIX_HPP
2#define STAN_MATH_REV_FUN_LOG_MIX_HPP
24 double theta_val,
double lambda1_val,
double lambda2_val,
25 double& one_m_exp_lam2_m_lam1,
double& one_m_t_prod_exp_lam2_m_lam1,
26 double& one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1) {
28 double lam2_m_lam1 = lambda2_val - lambda1_val;
29 double exp_lam2_m_lam1 =
exp(lam2_m_lam1);
30 one_m_exp_lam2_m_lam1 = 1 - exp_lam2_m_lam1;
31 double one_m_t = 1 - theta_val;
32 one_m_t_prod_exp_lam2_m_lam1 = one_m_t * exp_lam2_m_lam1;
33 one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1
34 = 1 / (theta_val + one_m_t_prod_exp_lam2_m_lam1);
76template <
typename T_theta,
typename T_lambda1,
typename T_lambda2,
79 const T_theta& theta,
const T_lambda1& lambda1,
const T_lambda2& lambda2) {
84 double theta_double =
value_of(theta);
85 const double lambda1_double =
value_of(lambda1);
86 const double lambda2_double =
value_of(lambda2);
88 double log_mix_function_value
89 =
log_mix(theta_double, lambda1_double, lambda2_double);
91 double one_m_exp_lam2_m_lam1(0.0);
92 double one_m_t_prod_exp_lam2_m_lam1(0.0);
93 double one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1(0.0);
95 if (lambda1 > lambda2) {
97 one_m_exp_lam2_m_lam1, one_m_t_prod_exp_lam2_m_lam1,
98 one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1);
101 one_m_exp_lam2_m_lam1, one_m_t_prod_exp_lam2_m_lam1,
102 one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1);
103 one_m_exp_lam2_m_lam1 = -one_m_exp_lam2_m_lam1;
104 theta_double = one_m_t_prod_exp_lam2_m_lam1;
105 one_m_t_prod_exp_lam2_m_lam1 = 1.0 -
value_of(theta);
109 partials<0>(ops_partials)[0]
110 = one_m_exp_lam2_m_lam1 * one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1;
113 partials<1>(ops_partials)[0]
114 = theta_double * one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1;
117 partials<2>(ops_partials)[0] = one_m_t_prod_exp_lam2_m_lam1
118 * one_d_t_plus_one_m_t_prod_exp_lam2_m_lam1;
121 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...