Skip to content

Commit c082e39

Browse files
docs: tighten inv_gaussian comments
1 parent 70c24ed commit c082e39

6 files changed

Lines changed: 10 additions & 24 deletions

File tree

stan/math/prim/prob/inv_gaussian_cdf.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ namespace math {
3434
* \f$\Phi(z_1) + e^{2\lambda/\mu}\Phi(-z_2)\f$ overflows a double above
3535
* \f$2\lambda/\mu = 710\f$. See <code>inv_gaussian_lcdf</code>.
3636
*
37-
* <p>Both boundaries are handled elementwise: \f$y = 0\f$ contributes a
38-
* factor of zero and \f$y = \infty\f$ a factor of one, so a container mixing
39-
* a boundary with ordinary observations multiplies to the same value as its
40-
* elements taken one at a time. The partials are zero at both.
37+
* <p>Both boundaries of the support are handled elementwise; the partials
38+
* are zero at both.
4139
*
4240
* @tparam T_y type of scalar
4341
* @tparam T_loc type of mean parameter

stan/math/prim/prob/inv_gaussian_lccdf.hpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ inline auto log_diff_exp_guarded(T1&& a, T2&& b) {
7575
* that first happens at \f$\log S = -5 \times 10^5\f$, so the survivor is
7676
* zero to any representable precision there.
7777
*
78-
* <p>Both boundaries are handled elementwise: \f$y = 0\f$ contributes
79-
* \f$\log 1 = 0\f$ and \f$y = \infty\f$ contributes \f$-\infty\f$, so a
80-
* container mixing a boundary with ordinary observations sums to the same
81-
* value as its elements taken one at a time. The partials are zero at both,
82-
* and wherever the survivor has underflowed.
78+
* <p>Both boundaries of the support are handled elementwise; the partials
79+
* are zero at both, and wherever the survivor has underflowed.
8380
*
8481
* @tparam T_y type of scalar
8582
* @tparam T_loc type of mean parameter

stan/math/prim/prob/inv_gaussian_lcdf.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,10 @@ inline auto log_scaled_upper_term(T1&& z1, T2&& z2) {
141141
* \f$z_{1,2} = \sqrt{\lambda/y}\,(y/\mu \mp 1)\f$. The factor
142142
* \f$e^{2\lambda/\mu}\f$ overflows a double above \f$2\lambda/\mu = 710\f$,
143143
* so the two terms are combined in log space. That grouping of \f$z\f$ is
144-
* exact at \f$y = \mu\f$ and returns \f$z_1 = 0\f$ there for any
145-
* \f$\lambda\f$.
144+
* exact in floating point at \f$y = \mu\f$.
146145
*
147-
* <p>Both boundaries are handled elementwise: \f$y = 0\f$ contributes
148-
* \f$-\infty\f$ and \f$y = \infty\f$ contributes \f$\log 1 = 0\f$, so a
149-
* container mixing a boundary with ordinary observations sums to the same
150-
* value as its elements taken one at a time. The partials are zero at both.
146+
* <p>Both boundaries of the support are handled elementwise; the partials
147+
* are zero at both.
151148
*
152149
* @tparam T_y type of scalar
153150
* @tparam T_loc type of mean parameter

stan/math/prim/prob/inv_gaussian_lpdf.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ inline return_type_t<T_y, T_loc, T_shape> inv_gaussian_lpdf(
9898
const auto& inv_mu = to_ref_if<any_ad>(inv(mu_val));
9999
const auto& inv_y = to_ref_if<any_ad>(inv(y_val));
100100
const auto& y_m_mu = to_ref_if<any_ad>(y_val - mu_val);
101-
// (y - mu)^2 / (2 mu^2 y)
102101
const auto& half_sq_scaled = to_ref(0.5 * square(y_m_mu * inv_mu) * inv_y);
103102

104103
size_t N = max_size(y, mu, lambda);

stan/math/prim/prob/inv_gaussian_rng.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ namespace math {
3030
* candidate roots and a Bernoulli draw selects between them. The method is
3131
* exact, with no rejection step.
3232
*
33-
* <p>The smaller root is formed as
34-
* \f$x = \mu / (1 + u/2 + \sqrt{u + u^2/4})\f$ with
35-
* \f$u = \mu w / \lambda\f$. Since \f$(1 + u/2)^2 - (u + u^2/4) = 1\f$
36-
* exactly, this form subtracts nothing and stays accurate for \f$u\f$ up to
37-
* \f$10^{20}\f$.
33+
* <p>The smaller root is computed in reciprocal form; since
34+
* \f$(1 + u/2)^2 - (u + u^2/4) = 1\f$ exactly, it subtracts nothing and
35+
* stays accurate for \f$u = \mu w / \lambda\f$ up to \f$10^{20}\f$.
3836
*
3937
* @tparam T_loc type of mean parameter
4038
* @tparam T_shape type of shape parameter

test/unit/math/prim/prob/inv_gaussian_test.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ TEST(ProbDistributionsInvGaussian, boundaries) {
121121
EXPECT_FLOAT_EQ(-inf, inv_gaussian_lcdf(0.0, 1.0, 2.0));
122122
EXPECT_FLOAT_EQ(0.0, inv_gaussian_lccdf(0.0, 1.0, 2.0));
123123
EXPECT_FLOAT_EQ(0.0, inv_gaussian_cdf(0.0, 1.0, 2.0));
124-
// y == inf is in the closure of the support: zero density, saturated CDF
125124
EXPECT_FLOAT_EQ(-inf, inv_gaussian_lpdf(inf, 1.0, 2.0));
126125
EXPECT_FLOAT_EQ(0.0, inv_gaussian_lcdf(inf, 1.0, 2.0));
127126
EXPECT_FLOAT_EQ(-inf, inv_gaussian_lccdf(inf, 1.0, 2.0));
@@ -206,8 +205,6 @@ TEST(ProbDistributionsInvGaussian, probabilityNeverExceedsOne) {
206205
EXPECT_FLOAT_EQ(-4.99000499999999997e17, inv_gaussian_lcdf(1e-4, 1e-1, 1e14));
207206
}
208207

209-
// At y == mu the CDF is a fixed quantity independent of the scale of mu, so
210-
// all of these must agree.
211208
TEST(ProbDistributionsInvGaussian, medianIsScaleInvariant) {
212209
using stan::math::inv_gaussian_lccdf;
213210
using stan::math::inv_gaussian_lcdf;

0 commit comments

Comments
 (0)