Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampler initialization (init_params) #1563

Closed
mateuszbaran opened this issue Mar 29, 2021 · 3 comments
Closed

Sampler initialization (init_params) #1563

mateuszbaran opened this issue Mar 29, 2021 · 3 comments

Comments

@mateuszbaran
Copy link

Hi!
Could you add some documentation to sampler initialization (init_params)? Right now it's quite non-intuitive to use.

I'm currently using the NUTS sampler for my model and unfortunately it tends to pick initial values of random variables that are far from the expected ones, and my model has numerical issues at such extreme values. Thus I'd like to start with some more likely initial values.

@mateuszbaran
Copy link
Author

I'm not even sure how to use init_params, I tried that:

@model function test(x)
    a ~ Normal(1.0, 2.0)
    println(a)
    x ~ filldist(Normal(a, 0.1), length(x))
    return a
end

sample(test([1.0, 2.0, 1.3]), NUTS(), 10; init_params = [3.1])

and it never goes through a equal to 3.1 (that value is never printed).

@mateuszbaran
Copy link
Author

After some investigation it looks like this line:
https://github.com/TuringLang/DynamicPPL.jl/blob/3602c56dba16bc2b60efbef6bf6ff31226354c7d/src/sampler.jl#L80
resets initialization for HMC samplers (but not for MH).

bors bot pushed a commit to TuringLang/DynamicPPL.jl that referenced this issue Apr 18, 2021
…niform` (#232)

This PR is a quick fix for TuringLang/Turing.jl#1563 and TuringLang/Turing.jl#1588.

As explained in TuringLang/Turing.jl#1588 (comment), the problem is that currently `SampleFromUniform` always resamples variables in every run, and hence also initial parameters provided by users are resampled in https://github.com/TuringLang/DynamicPPL.jl/blob/9d4137eb33e83f34c484bf78f9a57f828b3c92a0/src/sampler.jl#L80.

As mentioned in TuringLang/Turing.jl#1588 (comment), a better long term solution would be to fix this inconsistency and use dedicated evaluation and sampling contexts, as suggested in #80.
@yebai
Copy link
Member

yebai commented Nov 14, 2022

Likely fixed by TuringLang/DynamicPPL.jl#232

@yebai yebai closed this as completed Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants