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

Rejection Sampler Interface #18

Open
tjungni opened this issue Feb 28, 2024 · 0 comments
Open

Rejection Sampler Interface #18

tjungni opened this issue Feb 28, 2024 · 0 comments
Labels
06 - Feature-request Missing feature or functionality

Comments

@tjungni
Copy link
Member

tjungni commented Feb 28, 2024

A sampler can be either exact or inexact with a bias.
Inexact samplers generate proposal distributions that need to be unweighted to become exact, e.g., by using the rejection method.
Therefore, an interface for proposal samplers and rejection samplers needs to be implemented.

Suggested implementation

The following functions need to be implemented:

ProposalSampler <: AbstractSampler
(::ProposalSampler)(setup, global_params)
train!(proposal_sampler, train_params; loss=Nothing)
Base.eltype(::ProposalSampler)
QEDevents._weight(::ProposalSampler, x)
QEDevents._rand!(rng::AbstractRNG, ::ProposalSampler, x::AbstractVector{T}) where {T}
is_exact(::Proposalsampler) = false

where such a proposal sampler could be VEGAS or NIS.
The function train!() will train the model in NIS or optimize the adaptive grid in VEGAS.
Since the loss during training is often of interest for NIS, an array can be passed as input and will be mutated during training.
The global_params parameter in the constructor could include the number of coupling layers in NIS, the architecture of the subnets and the sampling batch size. train_params can include the max number of iterations and function calls for VEGAS or the number of epochs and the optimizer for NIS, just to name a few.

For the rejection sampler, the following needs to be implemented:

RejectionSampler <: AbstractSampler
(::RejectionSampler)(setup, ProposalSampler, global_params)
Base.eltype(::RejectionSampler)
QEDevents._weight(::PRejection_sampler, x) = 1
QEDevents._rand!(rng::AbstractRNG, ::RejectionSampler, x::AbstractVector{T}) where {T}
is_exact(::Proposalsampler) = true

A rejection sampler needs to know the max weight of the proposal to perform unweighting. There are multiple ways this max weight could be obtained. It could be taken from the weights of the samples generated during training of the proposal sampler, N events could be generated to obtain a max weight during the construction of the rejection sampler, or the Adam optimizer could be used to find the max weight. global_params should include a parameter that decides the method of finding the max weight.

@tjungni tjungni added the 06 - Feature-request Missing feature or functionality label Feb 28, 2024
@tjungni tjungni changed the title Proposal sampler interface Proposal Sampler Interface Feb 28, 2024
@szabo137 szabo137 changed the title Proposal Sampler Interface Rejection Sampler Interface Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
06 - Feature-request Missing feature or functionality
Projects
None yet
Development

No branches or pull requests

1 participant