Skip to content

Commit

Permalink
Merge pull request #68 from TuringLang/ml/isdone
Browse files Browse the repository at this point in the history
add `state` to isdone signature
  • Loading branch information
cpfiffer authored Apr 10, 2021
2 parents 232fb36 + ff5d718 commit 2f6d220
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
keywords = ["markov chain monte carlo", "probablistic programming"]
license = "MIT"
desc = "A lightweight interface for common MCMC methods."
version = "3.0.1"
version = "3.0.2"

[deps]
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ StatsBase.sample(
for regular and parallel sampling, respectively. In regular sampling, users may
provide a function
```julia
isdone(rng, model, sampler, samples, iteration; kwargs...)
isdone(rng, model, sampler, samples, state, iteration; kwargs...)
```
that returns `true` when sampling should end, and `false` otherwise, instead of
a fixed number of samples `nsamples`. AbstractMCMC defines the abstract types
Expand Down
2 changes: 1 addition & 1 deletion src/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ function mcmcsample(
# Step through the sampler until stopping.
i = 2

while !isdone(rng, model, sampler, samples, i; progress=progress, kwargs...)
while !isdone(rng, model, sampler, samples, state, i; progress=progress, kwargs...)
# Discard thinned samples.
for _ in 1:(thinning - 1)
# Obtain the next sample and state.
Expand Down
3 changes: 2 additions & 1 deletion test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ function isdone(
model::MyModel,
s::MySampler,
samples,
state,
iteration::Int;
kwargs...
)
# Calculate the mean of x.b.
bmean = mean(x.b for x in samples)
return abs(bmean) <= 0.001 || iteration >= 10_000
return abs(bmean) <= 0.001 || iteration >= 10_000 || state >= 10_000
end

# Set a default convergence function.
Expand Down

2 comments on commit 2f6d220

@cpfiffer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/34006

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.0.2 -m "<description of version>" 2f6d22076f16bda49ad182fd597ca2455fa72e18
git push origin v3.0.2

Please sign in to comment.