diff --git a/src/AliasScalarSampling.jl b/src/AliasScalarSampling.jl index 5ae89d127..362629b79 100644 --- a/src/AliasScalarSampling.jl +++ b/src/AliasScalarSampling.jl @@ -18,9 +18,12 @@ struct AliasingScalarSampler pxf = Float64.(p_x) pxf[pxf.<0.0] .= 0.0 # no negative values! pxf ./=sum(pxf) # must sum to 1 - pxf .-= quantile(pxf,SNRfloor) # remove lowest quantile + pxf2 = pxf .- quantile(pxf,SNRfloor) # remove lowest quantile + pxf2s = sum(pxf2) + pxf[:] = 1e-10 < pxf2s ? pxf2 : pxf pxf[pxf.<0.0] .= 0.0 - pxf ./=sum(pxf) + pxf ./= sum(pxf) + sum(isnan.(pxf)) == 0 ? nothing : error("AliasingScalarSampler got NaN because of particular values in p_x") wim = StatsBase.ProbabilityWeights(pxf) new(x, wim) end