Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/plotting/MarginalDist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ function MarginalDist(
filter::Bool = false
)

if filter && !isempty(samples) && !all(iszero, samples.weight)
samples = BAT.drop_low_weight_samples(samples)
end

marg_samples = bat_marginalize(samples, vsel).result
vs = varshape(marg_samples)
vs isa NamedTupleShape ? shapes = [getproperty(acc, :shape) for acc in vs._accessors] : shapes = [0,0]
UV = (vs isa ArrayShape && vsel isa Integer) || (length(shapes) == 1 && (shapes[1] isa Union{ScalarShape, ConstValueShape} || getproperty(shapes[1], :dims) == (1,)))

if filter
marg_samples = BAT.drop_low_weight_samples(marg_samples)
end

marg_samples = flatview(unshaped.(marg_samples).v)
cols = Tuple(Vector.(eachrow(marg_samples)))

Expand Down
3 changes: 1 addition & 2 deletions src/plotting/recipes_samples_2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
reshaped_samples,
vsel,
bins = bins,
closed = closed,
filter = filter
closed = closed
)

if seriestype == :scatter
Expand Down
7 changes: 7 additions & 0 deletions test/plotting/test_MarginalDist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ using BAT: MarginalDist, get_bin_centers, find_marginalmodes, asindex
binned_2d = marg_2d.dist isa BAT.ReshapedDist ? marg_2d.dist.dist : marg_2d.dist
@test binned_2d isa MvBinnedDist
@test isapprox(mean(binned_2d), [0, 0], atol = 0.1)

low_weight_samples = DensitySampleVector(
[[0.0], [1.0e15], [1.0], [2.0]], zeros(4);
weight = [1.0, 1.0e-6, 5.0e-6, 1.0],
)
filtered = MarginalDist(low_weight_samples, 1; bins = 4, filter = true)
@test maximum(abs, only(get_bin_centers(filtered))) < 10
end

@testset "from distribution" begin
Expand Down
Loading