7474DEFAULT_ADAPT_CONF_TYPE = Nothing
7575STAN_DEFAULT_ADAPT_CONF = nothing
7676
77- Sampler (alg:: Hamiltonian ) = Sampler (alg, nothing )
78- function Sampler (alg:: Hamiltonian , adapt_conf:: Nothing )
79- return _sampler (alg:: Hamiltonian , adapt_conf)
77+ Sampler (alg:: Hamiltonian , s:: Selector ) = Sampler (alg, nothing , s)
78+ Sampler (alg:: Hamiltonian , adapt_conf:: Nothing ) = Sampler (alg, adapt_conf, Selector ())
79+ function Sampler (alg:: Hamiltonian , adapt_conf:: Nothing , s:: Selector )
80+ return _sampler (alg:: Hamiltonian , adapt_conf, s)
8081end
81- function _sampler (alg:: Hamiltonian , adapt_conf)
82+ function _sampler (alg:: Hamiltonian , adapt_conf, s :: Selector )
8283 info= Dict {Symbol, Any} ()
8384
8485 # For state infomation
@@ -88,7 +89,7 @@ function _sampler(alg::Hamiltonian, adapt_conf)
8889 # Adapt configuration
8990 info[:adapt_conf ] = adapt_conf
9091
91- Sampler (alg, info)
92+ Sampler (alg, info, s )
9293end
9394
9495function sample (model:: Model , alg:: Hamiltonian ;
@@ -133,7 +134,7 @@ function sample(model::Model, alg::Hamiltonian;
133134 deepcopy (resume_from. info[:vi ])
134135 end
135136
136- if spl. selector. tag[] == :default
137+ if spl. selector. tag == :default
137138 link! (vi, spl)
138139 runmodel! (model, vi, spl)
139140 end
@@ -185,7 +186,7 @@ function sample(model::Model, alg::Hamiltonian;
185186 c = Chain (0.0 , samples) # wrap the result by Chain
186187 if save_state # save state
187188 # Convert vi back to X if vi is required to be saved
188- spl. selector. tag[] == :default && invlink! (vi, spl)
189+ spl. selector. tag == :default && invlink! (vi, spl)
189190 c = save (c, spl, model, vi, samples)
190191 end
191192 return c
@@ -197,11 +198,11 @@ function step(model, spl::Sampler{<:StaticHamiltonian}, vi::VarInfo, is_first::V
197198end
198199
199200function step (model, spl:: Sampler{<:AdaptiveHamiltonian} , vi:: VarInfo , is_first:: Val{true} )
200- spl. selector. tag[] != :default && link! (vi, spl)
201+ spl. selector. tag != :default && link! (vi, spl)
201202 epsilon = find_good_eps (model, spl, vi) # heuristically find good initial epsilon
202203 dim = length (vi[spl])
203204 spl. info[:wum ] = ThreePhaseAdapter (spl, epsilon, dim)
204- spl. selector. tag[] != :default && invlink! (vi, spl)
205+ spl. selector. tag != :default && invlink! (vi, spl)
205206 return vi, true
206207end
207208
@@ -215,7 +216,7 @@ function step(model, spl::Sampler{<:Hamiltonian}, vi::VarInfo, is_first::Val{fal
215216 spl. info[:eval_num ] = 0
216217
217218 Turing. DEBUG && @debug " X-> R..."
218- if spl. selector. tag[] != :default
219+ if spl. selector. tag != :default
219220 link! (vi, spl)
220221 runmodel! (model, vi, spl)
221222 end
@@ -241,7 +242,7 @@ function step(model, spl::Sampler{<:Hamiltonian}, vi::VarInfo, is_first::Val{fal
241242 setlogp! (vi, lj)
242243 end
243244
244- if PROGRESS[] && spl. selector. tag[] == :default
245+ if PROGRESS[] && spl. selector. tag == :default
245246 std_str = string (spl. info[:wum ]. pc)
246247 std_str = length (std_str) >= 32 ? std_str[1 : 30 ]* " ..." : std_str
247248 haskey (spl. info, :progress ) && ProgressMeter. update! (
@@ -256,7 +257,7 @@ function step(model, spl::Sampler{<:Hamiltonian}, vi::VarInfo, is_first::Val{fal
256257 end
257258
258259 Turing. DEBUG && @debug " R -> X..."
259- spl. selector. tag[] != :default && invlink! (vi, spl)
260+ spl. selector. tag != :default && invlink! (vi, spl)
260261
261262 return vi, is_accept
262263end
0 commit comments