@@ -3,43 +3,44 @@ struct Ensemble{D} <: MHSampler
3
3
proposal:: D
4
4
end
5
5
6
- # Define the first step! function, which is called at the
7
- # beginning of sampling. Return the initial parameter used
8
- # to define the sampler .
9
- function AbstractMCMC. step! (
6
+ # Define the first sampling step.
7
+ # Return a 2-tuple consisting of the initial sample and the initial state.
8
+ # In this case they are identical .
9
+ function AbstractMCMC. step (
10
10
rng:: Random.AbstractRNG ,
11
11
model:: DensityModel ,
12
- spl:: Ensemble ,
13
- N:: Integer ,
14
- :: Nothing ;
12
+ spl:: Ensemble ;
15
13
init_params = nothing ,
16
14
kwargs... ,
17
15
)
18
16
if init_params === nothing
19
- return propose (rng, spl, model)
17
+ transitions = propose (rng, spl, model)
20
18
else
21
- return Transition (model, init_params)
19
+ transitions = [ Transition (model, x) for x in init_params]
22
20
end
21
+
22
+ return transitions, transitions
23
23
end
24
24
25
- # Define the other step functions. Returns a Transition containing
26
- # either a new proposal (if accepted) or the previous proposal
27
- # (if not accepted).
28
- function AbstractMCMC. step! (
25
+ # Define the other sampling steps.
26
+ # Return a 2-tuple consisting of the next sample and the the next state.
27
+ # In this case they are identical, and for each walker they are either a new proposal
28
+ # (if accepted) or the previous proposal (if not accepted).
29
+ function AbstractMCMC. step (
29
30
rng:: Random.AbstractRNG ,
30
31
model:: DensityModel ,
31
32
spl:: Ensemble ,
32
- :: Integer ,
33
- params_prev;
33
+ params_prev:: Vector{<:Transition} ;
34
34
kwargs... ,
35
35
)
36
36
# Generate a new proposal. Accept/reject happens at proposal level.
37
- return propose (rng, spl, model, params_prev)
37
+ transitions = propose (rng, spl, model, params_prev)
38
+ return transitions, transitions
38
39
end
39
40
40
41
#
41
42
# Initial proposal
42
- #
43
+ #
43
44
function propose (rng:: Random.AbstractRNG , spl:: Ensemble , model:: DensityModel )
44
45
# Make the first proposal with a static draw from the prior.
45
46
static_prop = StaticProposal (spl. proposal. proposal)
49
50
50
51
#
51
52
# Every other proposal
52
- #
53
- function propose (rng:: Random.AbstractRNG , spl:: Ensemble , model:: DensityModel , walkers:: Vector{W} ) where {W<: Transition }
53
+ #
54
+ function propose (
55
+ rng:: Random.AbstractRNG ,
56
+ spl:: Ensemble ,
57
+ model:: DensityModel ,
58
+ walkers:: Vector{<:Transition} ,
59
+ )
54
60
new_walkers = similar (walkers)
55
61
56
62
others = 1 : (spl. n_walkers - 1 )
@@ -64,7 +70,6 @@ function propose(rng::Random.AbstractRNG, spl::Ensemble, model::DensityModel, wa
64
70
return new_walkers
65
71
end
66
72
67
-
68
73
# ####################################
69
74
# Basic stretch move implementation #
70
75
# ####################################
0 commit comments