Skip to content

Commit 1c8bd5b

Browse files
committed
fix misspecified iG algorithm
1 parent 1faf29e commit 1c8bd5b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

include/boost/random/inverse_gaussian_distribution.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ class inverse_gaussian_distribution
132132
using std::sqrt;
133133
#endif
134134
RealType y = _alpha * chi_squared_distribution<RealType>(RealType(1.0))(urng);
135-
RealType cand_fac = result_type(1) + y - sqrt(result_type(2) * y + y * y);
135+
RealType cand = _alpha + _alpha * (y - sqrt(y * (result_type(4) * _beta + y))) / (result_type(2) * _beta);
136136
RealType u = uniform_01<RealType>()(urng);
137-
if (u <= 1 / (1 + cand_fac)) {
138-
return _alpha * cand_fac;
137+
if (u < _alpha / (_alpha + cand)) {
138+
return cand;
139139
}
140-
return _alpha * cand_fac;
140+
return _alpha * _alpha / cand;
141141
}
142142

143143
/**

0 commit comments

Comments
 (0)