File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 1
1
name = " AdvancedMH"
2
2
uuid = " 5b7e9947-ddc0-4b3f-9b55-0d8042f74170"
3
- version = " 0.3.0 "
3
+ version = " 0.3.1 "
4
4
5
5
[deps ]
6
6
AbstractMCMC = " 80f14c24-f653-4e6a-9b94-39d6b0f70001"
Original file line number Diff line number Diff line change @@ -29,6 +29,17 @@ The sampler is constructed using
29
29
```julia
30
30
spl = MetropolisHastings(proposal)
31
31
```
32
+
33
+ When using `MetropolisHastings` with the function `sample`, the following keyword
34
+ arguments are allowed:
35
+
36
+ - `init_params` defines the initial parameterization for your model. If
37
+ none is given, the initial parameters will be drawn from the sampler's proposals.
38
+ - `param_names` is a vector of strings to be assigned to parameters. This is only
39
+ used if `chain_type=Chains`.
40
+ - `chain_type` is the type of chain you would like returned to you. Supported
41
+ types are `chain_type=Chains` if `MCMCChains` is imported, or
42
+ `chain_type=StructArray` if `StructArrays` is imported.
32
43
"""
33
44
mutable struct MetropolisHastings{D} <: Metropolis
34
45
proposal :: D
@@ -155,9 +166,14 @@ function step!(
155
166
model:: DensityModel ,
156
167
spl:: MetropolisHastings ,
157
168
N:: Integer ;
169
+ init_params= nothing ,
158
170
kwargs...
159
171
)
160
- return propose (spl, model)
172
+ if init_params === nothing
173
+ return propose (spl, model)
174
+ else
175
+ return Transition (model, init_params)
176
+ end
161
177
end
162
178
163
179
# Define the other step functions. Returns a Transition containing
Original file line number Diff line number Diff line change @@ -78,5 +78,17 @@ using MCMCChains
78
78
c3 = sample (m3, MetropolisHastings (p3), 100 ; chain_type= Vector{NamedTuple})
79
79
c4 = sample (m4, MetropolisHastings (p4), 100 ; chain_type= Vector{NamedTuple})
80
80
end
81
+
82
+ @testset " Initial parameters" begin
83
+ # Set up our sampler with initial parameters.
84
+ spl1 = StaticMH ([Normal (0 ,1 ), Normal (0 , 1 )])
85
+
86
+ val = [0.4 , 1.2 ]
87
+
88
+ # Sample from the posterior.
89
+ chain1 = sample (model, spl1, 10 , init_params = val)
90
+
91
+ @test chain1[1 ]. params == val
92
+ end
81
93
end
82
94
You can’t perform that action at this time.
0 commit comments