Skip to content

Improving interaction between different implementations of the interface #85

@torfjelde

Description

@torfjelde

How do you feel about adding something like:

"""
    state_from_transiton(state, transition_prev[, state_prev])

Return new instance of `state` using information from `transition_prev` and, optionally, `state_prev`.

Defaults to `setparameters!!(state, parameters(transition_prev))`.
"""
function state_from_transition(state, transition_prev, state_prev)
    return state_from_transition(state, transition_prev)
end

function state_from_transition(state, transition)
    return setparameters!!(state, parameters(transition))
end

"""
    setparameters!!(state, parameters)

Return new instance of `state` with parameters set to `parameters`.
"""
setparameters!!

"""
    parameters(transition)

Return parameters in `transition`.
"""
parameters

to make it easier for samplers to interact across packages? Then you just need to implement state_from_transition for the different types to get cross-package compat.

Another issue is also the model argument which often is specific to a particular sampler implementation. We've previous spoken about generalizing this so that we don't have a bunch of these lying around, e.g. AdvancedMH.DensityModel and AdvancedHMC.DifferentiableDensityModel, but we should also maybe add a function getmodel(model, sampler, state) or something too, which is identity by default but allows one to provide a model-type which encodes a bunch of different models for specific samplers, e.g. in the case of a MixtureSampler you might have a MixtureState which, among other things, holds the current sampler-index, and a ManyModels which simply wraps a collection of models corresponding to each of the components/samplers in the MixtureSampler:

getmodel(model::ManyModels, sampler::MixtureSampler, state::MixtureState) = model[state.current_index]

I've been running into quite a few scenarios recently where I'd love to have something like this, e.g. wanting to implement MixtureSampler and CompositionSampler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions