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

Add init_params keyword argument #26

Merged
merged 10 commits into from
Jan 19, 2022
Merged

Add init_params keyword argument #26

merged 10 commits into from
Jan 19, 2022

Conversation

theogf
Copy link
Member

@theogf theogf commented Jan 18, 2022

The idea behing this PR is to allow different behavior for initial_sample by passing the kwargs as well. Typically passing a defined starting point for the MCMC chain.

@theogf theogf marked this pull request as ready for review January 18, 2022 14:49
src/interface.jl Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jan 18, 2022

Codecov Report

Merging #26 (ff5f188) into main (ca39ed3) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #26   +/-   ##
=======================================
  Coverage   94.91%   94.91%           
=======================================
  Files           3        3           
  Lines          59       59           
=======================================
  Hits           56       56           
  Misses          3        3           
Impacted Files Coverage Δ
src/abstractmcmc.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ca39ed3...ff5f188. Read the comment docs.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@devmotion
Copy link
Member

Is it reasonable to forward all keyword arguments? And do you have any application or downstream code that exploits it? Then it would be easier to see if we should use a different design or if it works sufficiently well. Would be good to add such examples to the tests as well.

@theogf
Copy link
Member Author

theogf commented Jan 18, 2022

I literally want to do:

function inital_sample(rng, m::MyModel; init_params, kwargs...)
    return init_params
end

But I wanted to take an approach that would not affect the current package, hence the general kwargs approach.
And sure I can add some tests.

@devmotion
Copy link
Member

BTW regarding initial parameters the plan is to move the initial_params support in DynamicPPL/Turing to AbstractMCMC. The plan exists for quite some time now but it was not prioritized...

@devmotion
Copy link
Member

So ideally we would just support the AbstractMCMC interface for initial parameters but of course this would require the upstream changes first.

@theogf
Copy link
Member Author

theogf commented Jan 18, 2022

Is there any open PR yet?
[EDIT:] Checking AbstractMCMC, it does not look like it.

@devmotion
Copy link
Member

Yeah, unfortunately not. I'll add it to my (growing) list of things that should be prioritized... Until then, I suggest following the convention in other Turing packages such as AdvancedMH (https://github.com/TuringLang/AdvancedMH.jl/blob/361a66905947799d7945818862673d07d5568b16/src/mh-core.jl#L78-L81) or DynamicPPL and supporting an explicit init_params keyword argument with default value nothing.

@theogf
Copy link
Member Author

theogf commented Jan 18, 2022

I can see the point. But is there a general performance impact on passing all kwargs?

@theogf
Copy link
Member Author

theogf commented Jan 18, 2022

Additionally, do you want me to modify the current initial_sample with

function initial_sample(rng, model::ESSModel; init_params=nothing)
     return init_params == nothing ? rand(rng, prior(model)) ? init_params
end

@devmotion
Copy link
Member

I don't think so. But it seems easier to not have to overload any methods but just handle it in the implementation of step here. I.e., write explicitly something like

f = init_params === nothing ? ... : init_params
...

@devmotion
Copy link
Member

Additionally, do you want me to modify the current initial_sample with

No, I think it is simpler to just handle init_params in step, similar to e.g. AdvancedMH.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

This would be my suggestion.

src/abstractmcmc.jl Outdated Show resolved Hide resolved
src/abstractmcmc.jl Outdated Show resolved Hide resolved
src/interface.jl Outdated Show resolved Hide resolved
src/abstractmcmc.jl Outdated Show resolved Hide resolved
theogf and others added 2 commits January 19, 2022 13:35
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Looks good so far!

Can you also mention it in the documentation (since it's not one of the standard AbstractMCMC keyword arguments (yet) that we refer to in the docs) and update the version number?

test/simple.jl Show resolved Hide resolved
test/simple.jl Outdated Show resolved Hide resolved
theogf and others added 2 commits January 19, 2022 16:02
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
test/simple.jl Outdated Show resolved Hide resolved
test/simple.jl Outdated Show resolved Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@devmotion devmotion changed the title Pass kwargs to initial_sample Add init_params keyword argument Jan 19, 2022
@devmotion
Copy link
Member

Great, thanks @theogf!

@devmotion devmotion merged commit 65feb50 into main Jan 19, 2022
@delete-merged-branch delete-merged-branch bot deleted the tgf/patch-1 branch January 19, 2022 16:04
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

Successfully merging this pull request may close these issues.

2 participants