File tree Expand file tree Collapse file tree 3 files changed +12
-13
lines changed Expand file tree Collapse file tree 3 files changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,8 @@ struct MCMCSerial <: AbstractMCMCEnsemble end
82
82
83
83
function condition end
84
84
85
+ function logdensity_and_state end
86
+
85
87
include (" samplingstats.jl" )
86
88
include (" logging.jl" )
87
89
include (" interface.jl" )
Original file line number Diff line number Diff line change @@ -203,16 +203,7 @@ function AbstractMCMC.step(
203
203
logdensity_model. logdensity, conditioning_variables_values
204
204
)
205
205
206
- # recompute the logdensity stored in the mcmc state, because the values might have been updated in other sub-problems
207
- updated_log_prob = LogDensityProblems. logdensity (cond_logdensity, sub_state)
208
-
209
- if ! hasproperty (sub_state, :logp )
210
- error (
211
- " $(typeof (sub_state)) does not have a `:logp` field, which is required by Gibbs sampling" ,
212
- )
213
- end
214
- sub_state = BangBang. setproperty!! (sub_state, :logp , updated_log_prob)
215
-
206
+ _, sub_state = AbstractMCMC. logdensity_and_state (cond_logdensity, sub_state)
216
207
sub_state = last (
217
208
AbstractMCMC. step (
218
209
rng,
Original file line number Diff line number Diff line change @@ -9,9 +9,15 @@ struct MHTransition{T}
9
9
params:: Vector{T}
10
10
end
11
11
12
- function AbstractMCMC. LogDensityProblems. logdensity (logdensity_function, state:: MHState )
13
- # recompute the logdensity, instead of using the one stored in the state
14
- return AbstractMCMC. LogDensityProblems. logdensity (logdensity_function, state. params)
12
+ function AbstractMCMC. logdensity_and_state (
13
+ logdensity_function, state:: MHState ; recompute_logp:: Bool = true
14
+ )
15
+ if recompute_logp
16
+ logp, substate = AbstractMCMC. LogDensityProblems. logdensity (logdensity_function, state. params)
17
+ return logp, MHState (substate. params, logp)
18
+ else
19
+ return state. logp, state
20
+ end
15
21
end
16
22
17
23
function Base. vec (state:: MHState )
You can’t perform that action at this time.
0 commit comments