GaussianFilters.jl icon indicating copy to clipboard operation
GaussianFilters.jl copied to clipboard

RNG never used when sampling initial state

Open lkruse opened this issue 2 years ago • 2 comments

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

lkruse avatar Jan 13 '23 01:01 lkruse

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 avatar Jan 13 '23 02:01 zsunberg

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

zsunberg avatar Jan 13 '23 03:01 zsunberg