Skip to content

Commit bae12ac

Browse files
committed
log1m
1 parent c8f2afd commit bae12ac

7 files changed

Lines changed: 14 additions & 8 deletions

File tree

stan/math/opencl/prim/pareto_lcdf.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ return_type_t<T_y_cl, T_scale_cl, T_shape_cl> pareto_lcdf(
6868

6969
auto log_quot = log(elt_divide(y_min_val, y_val));
7070
auto exp_prod = exp(elt_multiply(alpha_val, log_quot));
71-
auto lcdf_expr = colwise_sum(log(1.0 - exp_prod));
71+
// TODO(Andrew) Further simplify derivatives and log1m_exp below
72+
auto lcdf_expr = colwise_sum(log1m(exp_prod));
7273

7374
auto common_deriv = elt_divide(exp_prod, 1.0 - exp_prod);
7475

stan/math/opencl/prim/weibull_lcdf.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ return_type_t<T_y_cl, T_shape_cl, T_scale_cl> weibull_lcdf(
6565

6666
auto pow_n = pow(elt_divide(y_val, sigma_val), alpha_val);
6767
auto exp_n = exp(-pow_n);
68-
auto lcdf_expr = colwise_sum(log(1.0 - exp_n));
68+
// TODO(Andrew) Further simplify derivatives and log1m_exp below
69+
auto lcdf_expr = colwise_sum(log1m(exp_n));
6970

7071
auto rep_deriv = elt_divide(pow_n, elt_divide(1.0, exp_n) - 1.0);
7172
auto deriv_y_sigma = elt_multiply(rep_deriv, alpha_val);

stan/math/prim/fun/inc_beta_ddb.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <stan/math/prim/fun/inc_beta.hpp>
88
#include <stan/math/prim/fun/inc_beta_dda.hpp>
99
#include <stan/math/prim/fun/inv.hpp>
10-
#include <stan/math/prim/fun/log.hpp>
10+
#include <stan/math/prim/fun/log1m.hpp>
1111
#include <cmath>
1212

1313
namespace stan {
@@ -87,7 +87,7 @@ T inc_beta_ddb(T a, T b, T z, T digamma_b, T digamma_ab) {
8787
}
8888
}
8989

90-
return inc_beta(a, b, z) * (log(1 - z) - digamma_b + sum_numer / sum_denom);
90+
return inc_beta(a, b, z) * (log1m(z) - digamma_b + sum_numer / sum_denom);
9191
}
9292

9393
} // namespace math

stan/math/prim/fun/inc_beta_ddz.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stan/math/prim/fun/exp.hpp>
66
#include <stan/math/prim/fun/lgamma.hpp>
77
#include <stan/math/prim/fun/log.hpp>
8+
#include <stan/math/prim/fun/log1m.hpp>
89
#include <boost/math/special_functions/beta.hpp>
910
#include <cmath>
1011

@@ -29,7 +30,7 @@ template <typename T>
2930
T inc_beta_ddz(T a, T b, T z) {
3031
using std::exp;
3132
using std::log;
32-
return exp((b - 1) * log(1 - z) + (a - 1) * log(z) + lgamma(a + b) - lgamma(a)
33+
return exp((b - 1) * log1m(z) + (a - 1) * log(z) + lgamma(a + b) - lgamma(a)
3334
- lgamma(b));
3435
}
3536

stan/math/prim/prob/pareto_lcdf.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ return_type_t<T_y, T_scale, T_shape> pareto_lcdf(const T_y& y,
6969
const auto& exp_prod
7070
= to_ref_if<!is_constant_all<T_y, T_scale, T_shape>::value>(
7171
exp(alpha_val * log_quot));
72-
T_partials_return P = sum(log(1 - exp_prod));
72+
// TODO(Andrew) Further simplify derivatives and log1m_exp below
73+
T_partials_return P = sum(log1m(exp_prod));
7374

7475
if (!is_constant_all<T_y, T_scale, T_shape>::value) {
7576
const auto& common_deriv = to_ref_if<(!is_constant_all<T_y, T_scale>::value

stan/math/prim/prob/skew_double_exponential_lccdf.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ return_type_t<T_y, T_loc, T_scale, T_skewness> skew_double_exponential_lccdf(
109109
if (y_dbl <= mu_dbl) {
110110
cdf_log += log1m(tau_dbl * exp(-2.0 * expo));
111111
} else {
112-
cdf_log += log(1 - tau_dbl) - 2.0 * expo;
112+
cdf_log += log1m(tau_dbl) - 2.0 * expo;
113113
}
114114

115115
if (!is_constant_all<T_y>::value) {

stan/math/prim/prob/weibull_lcdf.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <stan/math/prim/fun/as_value_column_array_or_scalar.hpp>
99
#include <stan/math/prim/fun/exp.hpp>
1010
#include <stan/math/prim/fun/log.hpp>
11+
#include <stan/math/prim/fun/log1m.hpp>
1112
#include <stan/math/prim/fun/size_zero.hpp>
1213
#include <stan/math/prim/fun/max_size.hpp>
1314
#include <stan/math/prim/fun/to_ref.hpp>
@@ -67,7 +68,8 @@ return_type_t<T_y, T_shape, T_scale> weibull_lcdf(const T_y& y,
6768
const auto& pow_n = to_ref_if<any_derivs>(pow(y_val / sigma_val, alpha_val));
6869
const auto& exp_n = to_ref_if<any_derivs>(exp(-pow_n));
6970

70-
T_partials_return cdf_log = sum(log(1 - exp_n));
71+
// TODO(Andrew) Further simplify derivatives and log1m_exp below
72+
T_partials_return cdf_log = sum(log1m(exp_n));
7173

7274
if (!is_constant_all<T_y, T_scale, T_shape>::value) {
7375
const auto& rep_deriv = to_ref_if<(!is_constant_all<T_y, T_scale>::value

0 commit comments

Comments
 (0)