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

RNG never used when sampling initial state #41

Open
lkruse opened this issue Jan 13, 2023 · 2 comments
Open

RNG never used when sampling initial state #41

lkruse opened this issue Jan 13, 2023 · 2 comments

Comments

@lkruse
Copy link

lkruse commented Jan 13, 2023

In simulate.jl, a random state is sampled from the Gaussian Belief:

    # make initial state
    s0 = rand(rng, b0)

However, the rng passed into the rand() function isn't actually used to seed experiments; in kf_classes.jl, the rand() function is defined as

function Base.rand(rng::AbstractRNG, b::GaussianBelief)
    return b.μ + cholesky(b.Σ).L * randn(size(b.Σ,1))
end

Should there be two extensions of rand() - one that dispatches on the rng for simulation reproducibility and one that does not? For example,

function Base.rand(rng::AbstractRNG, b::GaussianBelief)
    return b.μ + cholesky(b.Σ).L * randn(rng, size(b.Σ,1))
end

function Base.rand(b::GaussianBelief)
    return b.μ + cholesky(b.Σ).L * randn(size(b.Σ,1))
end
@zsunberg
Copy link
Member

You should only have to implement 1 new method. Read this: https://docs.julialang.org/en/v1/stdlib/Random/#Hooking-into-the-Random-API

I think you should only have to implement 1 method with SamplerTrivial to get everything to work

@zsunberg
Copy link
Member

zsunberg commented Jan 13, 2023

Specifically https://docs.julialang.org/en/v1/stdlib/Random/#A-simple-sampler-without-pre-computed-data

I think you should just define

rand (rng::AbstractRNG, s::Random.SamplerTrivial{<:GaussianBelief})

And everything should work

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