Skip to content

Bridge sampling with non-integer weights #337

@philippeller

Description

@philippeller

When using the bridge sampler on samples generated with non-integer weights, it crashes (stack trace below).

It is in particular the nsamples=Int(sum(second_batch.weight)) here:

proposal_samples = bat_sample(proposal_density,IIDSampling(nsamples=Int(sum(second_batch.weight)))).result

I suggest for instance to use floor(Int,sum(second_batch.weight)) instead

ArithmeticError: <PyCall.jlwrap (in a Julia function called from Python)
JULIA: InexactError: Int64(207.62753894835834)
Stacktrace:
 [1] Int64
   @ ./float.jl:723 [inlined]
 [2] bridge_sampling_integral(target_density::BAT.PosteriorDensity{Float64, Float64, BAT.ReshapedDensity{BAT.TransformedDensity{BAT.DensityWithShape{BAT.LFDensity{PyObject}, ScalarShape{Real}}, BAT.DistributionTransform{BAT.StandardUvNormal{Float64}, Distributions.Uniform{Float64}, ScalarShape{Real}, ScalarShape{Real}}, BAT.TDNoCorr, ScalarShape{Real}}, ArrayShape{Real, 1}}, BAT.DistributionDensity{Distributions.Product{Distributions.Continuous, BAT.StandardUvNormal{Float64}, FillArrays.Fill{BAT.StandardUvNormal{Float64}, 1, Tuple{Base.OneTo{Int64}}}}, BAT.HyperRectBounds{Float64}}, ArrayShape{Real, 1}, BAT.HyperRectBounds{Float32}}, target_samples::StructArrays.StructVector{BAT.DensitySample{Vector{Float64}, Float64, Float64, Nothing, Nothing}, NamedTuple{(:v, :logd, :weight, :info, :aux), Tuple{ArrayOfSimilarArrays{Float64, 1, 1, 2, SubArray{Float64, 2, Matrix{Float64}, Tuple{UnitRange{Int64}, Base.Slice{Base.OneTo{Int64}}}, false}}, Vector{Float64}, Vector{Float64}, Vector{Nothing}, Vector{Nothing}}}, Int64}, strict::Bool, ess_alg::BAT.EffSampleSizeFromAC{BAT.GeyerAutocorLen})
   @ BAT ~/.julia/packages/BAT/Ws127/src/integration/bridge_sampling_integration.jl:134
 [3] bat_integrate_impl(target::BAT.SampledDensity{BAT.PosteriorDensity{Float64, Float64, BAT.DensityWithShape{BAT.LFDensity{PyObject}, ScalarShape{Real}}, BAT.DistributionDensity{Distributions.Uniform{Float64}, BAT.HyperRectBounds{Float64}}, ScalarShape{Real}, BAT.HyperRectBounds{Float64}}, StructArrays.StructVector{BAT.DensitySample{Float64, Float64, Float64, Nothing, Nothing}, NamedTuple{(:v, :logd, :weight, :info, :aux), Tuple{SubArray{Float64, 1, Matrix{Float64}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}, Vector{Float64}, Vector{Float64}, Vector{Nothing}, Vector{Nothing}}}, Int64}, BAT.UnknownSampleGenerator}, algorithm::BAT.BridgeSampling{BAT.PriorToGaussian, BAT.EffSampleSizeFromAC{BAT.GeyerAutocorLen}})
   @ BAT ~/.julia/packages/BAT/Ws127/src/integration/bridge_sampling_integration.jl:33
 [4] bat_integrate(target::BAT.SampledDensity{BAT.PosteriorDensity{Float64, Float64, BAT.DensityWithShape{BAT.LFDensity{PyObject}, ScalarShape{Real}}, BAT.DistributionDensity{Distributions.Uniform{Float64}, BAT.HyperRectBounds{Float64}}, ScalarShape{Real}, BAT.HyperRectBounds{Float64}}, StructArrays.StructVector{BAT.DensitySample{Float64, Float64, Float64, Nothing, Nothing}, NamedTuple{(:v, :logd, :weight, :info, :aux), Tuple{SubArray{Float64, 1, Matrix{Float64}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}, Vector{Float64}, Vector{Float64}, Vector{Nothing}, Vector{Nothing}}}, Int64}, BAT.UnknownSampleGenerator}, algorithm::BAT.BridgeSampling{BAT.PriorToGaussian, BAT.EffSampleSizeFromAC{BAT.GeyerAutocorLen}})
   @ BAT ~/.julia/packages/BAT/Ws127/src/algotypes/integration_algorithm.jl:45
 [5] invokelatest(::Any, ::Any, ::Vararg{Any, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ Base ./essentials.jl:708
 [6] invokelatest(::Any, ::Any, ::Vararg{Any, N} where N)
   @ Base ./essentials.jl:706
 [7] _pyjlwrap_call(f::Function, args_::Ptr{PyCall.PyObject_struct}, kw_::Ptr{PyCall.PyObject_struct})
   @ PyCall ~/.julia/packages/PyCall/7a7w0/src/callback.jl:28
 [8] pyjlwrap_call(self_::Ptr{PyCall.PyObject_struct}, args_::Ptr{PyCall.PyObject_struct}, kw_::Ptr{PyCall.PyObject_struct})
   @ PyCall ~/.julia/packages/PyCall/7a7w0/src/callback.jl:44>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions