Skip to content

Commit 4a3cd07

Browse files
authored
Merge pull request #1894 from andrjohns/feature/Feature-1
Bugfix: lognormal - wrong lpdf with integer sigma
2 parents 19f5f25 + 8d6c43b commit 4a3cd07

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

stan/math/prim/prob/lognormal_lpdf.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stan/math/prim/meta.hpp>
55
#include <stan/math/prim/err.hpp>
66
#include <stan/math/prim/fun/constants.hpp>
7+
#include <stan/math/prim/fun/inv.hpp>
78
#include <stan/math/prim/fun/log.hpp>
89
#include <stan/math/prim/fun/max_size.hpp>
910
#include <stan/math/prim/fun/size.hpp>
@@ -63,7 +64,7 @@ return_type_t<T_y, T_loc, T_scale> lognormal_lpdf(const T_y& y, const T_loc& mu,
6364
inv_sigma_sq(size(sigma));
6465
if (include_summand<propto, T_y, T_loc, T_scale>::value) {
6566
for (size_t n = 0; n < stan::math::size(sigma); n++) {
66-
inv_sigma[n] = 1 / value_of(sigma_vec[n]);
67+
inv_sigma[n] = inv(value_of(sigma_vec[n]));
6768
}
6869
}
6970
if (include_summand<propto, T_y, T_loc, T_scale>::value) {
@@ -85,7 +86,7 @@ return_type_t<T_y, T_loc, T_scale> lognormal_lpdf(const T_y& y, const T_loc& mu,
8586
stan::math::size(y));
8687
if (!is_constant_all<T_y>::value) {
8788
for (size_t n = 0; n < stan::math::size(y); n++) {
88-
inv_y[n] = 1 / value_of(y_vec[n]);
89+
inv_y[n] = inv(value_of(y_vec[n]));
8990
}
9091
}
9192

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ TEST(ProbLognormal, log_matches_lpdf) {
2121
EXPECT_FLOAT_EQ(
2222
(stan::math::lognormal_lpdf<double, double, double>(y, mu, sigma)),
2323
(stan::math::lognormal_log<double, double, double>(y, mu, sigma)));
24+
25+
EXPECT_FLOAT_EQ((stan::math::lognormal_lpdf(0.8, 2.0, 2.0)),
26+
(stan::math::lognormal_log(0.8, 2, 2)));
2427
}

0 commit comments

Comments
 (0)