Skip to content

Commit d4a144e

Browse files
Tor FjeldeTor Fjelde
authored andcommitted
added an explanation of the min
1 parent 5193119 commit d4a144e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/RobustAdaptiveMetropolis.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,13 @@ function ram_step_inner(
143143
# Compute the acceptance probability.
144144
lp = state.logprob
145145
lp_new = LogDensityProblems.logdensity(f, x_new)
146-
logα = min(lp_new - lp, zero(lp)) # `min` because we'll use this for updating
146+
# Technically, the `min` here is unnecessary for sampling according to `min(..., 1)`.
147+
# However, `ram_adapt` assumes that `logα` actually represents the log acceptance probability
148+
# and is thus bounded at 0. Moreover, users might be interested in inspecting the average
149+
# acceptance rate to check that the algorithm achieves something similar to the target rate.
150+
# Hence, it's a bit more convenient for the user if we just perform the `min` here
151+
# so they can just take an average of (`exp` of) the `logα` values.
152+
logα = min(lp_new - lp, zero(lp))
147153
isaccept = Random.randexp(rng) > -logα
148154

149155
return x_new, lp_new, U, logα, isaccept

0 commit comments

Comments
 (0)