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

Parameterize SobolPayload.params with <: Distribution #6

Open
lrennels opened this issue Jan 25, 2019 · 2 comments
Open

Parameterize SobolPayload.params with <: Distribution #6

lrennels opened this issue Jan 25, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@lrennels
Copy link
Owner

lrennels commented Jan 25, 2019

mutable struct SobolPayload
    params::Union{OrderedDict{Symbol, <:Any}, Nothing}
    calc_second_order::Bool
    N::Int 

    function SobolPayload(;params= nothing, calc_second_order = false, N = 1000)
        return new(params, calc_second_order, N)
    end
end

The params attribute of SobolPayload above should be parameterized as `Union{OrderedDict{Symbol, <:Distribution}, Nothing}, however this causes an error because params dictionaries such as

        :x2 => Uniform(0.75, 1.25),
        :x3 => LogNormal(20, 4))

seem to have type OrderedDict{Symbol, Any}, causing an error.

@lrennels lrennels added the bug Something isn't working label Jan 25, 2019
@lrennels lrennels changed the title Parameterize SobolPayload.params as ::Union{OrderedDict{Symbol, <:Distribution}, Nothing Parameterize SobolPayload.params with <: DIstiribution Jan 25, 2019
@lrennels
Copy link
Owner Author

lrennels commented Jan 25, 2019

RIch:

It's because the most specific type that all the elements are a subtype of is the parameterized Distribution{Univariate,Continuous}.

If we define, say, EmpiricalDist as a univariate, discrete Distribution, e.g.,

struct EmpiricalDist <: Distribution{Univariate, Discrete}
     foo::Int
end

we get:

Dict(:a => EmpiricalDistribution1(1), :b => Normal(1, 0.2))
Dict{Symbol,Distribution{Univariate,S} where S<:ValueSupport} with 2 entries:
  :a => EmpiricalDistribution1(foo=1)
  :b => Normal{Float64}(μ=1.0, σ=0.2)

This is a general issue in Julia: since it types a container based on the tightest type that contains all the contents, if your initial values aren't as general as the full set the container will hold, you have to type it explicitly, or the later additions (that fall outside the narrow type) will fail.

So, yes,

params = OrderedDict{Symbol, Distribution}(:x1 => Normal(1, 0.2),
        :x2 => Uniform(0.75, 1.25),
        :x3 => LogNormal(20, 4))

is the way to go.

@lrennels
Copy link
Owner Author

Need to decide if this is worth it, because don't want user to have to parameterize their input so specifically.

@lrennels lrennels changed the title Parameterize SobolPayload.params with <: DIstiribution Parameterize SobolPayload.params with <: Distribution Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant