/
median_estimator.jl
54 lines (37 loc) · 1.44 KB
/
median_estimator.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This file is a part of BAT.jl, licensed under the MIT License (MIT).
"""
abstract type BAT.AbstractMedianEstimator
Abstract type for BAT optimization algorithms.
A typical application for optimization in BAT is mode estimation
(see [`bat_findmode`](@ref)),
"""
abstract type AbstractMedianEstimator end
"""
bat_findmedian(
samples::DensitySampleVector
)
The function computes the median of marginalized `samples`.
Returns a NamedTuple of the shape
```julia
(result = v, ...)
```
Result properties not listed here are algorithm-specific and are not part
of the stable public API.
!!! note
Do not add add methods to `bat_findmedian`, add methods to
`bat_findmedian_impl` instead.
"""
function bat_findmedian end
export bat_findmedian
function bat_findmedian_impl end
function bat_findmedian(samples::DensitySampleVector, algorithm, context::BATContext)
orig_context = deepcopy(context)
r = bat_findmedian_impl(samples, algorithm, context)
result_with_args(r, (algorithm = algorithm, context = orig_context))
end
bat_findmedian(samples::DensitySampleVector) = bat_findmedian(samples, get_batcontext())
bat_findmedian(samples::DensitySampleVector, algorithm) = bat_findmedian(samples, algorithm, get_batcontext())
function bat_findmedian(samples::DensitySampleVector, context::BATContext)
algorithm = bat_default_withdebug(bat_findmedian, Val(:algorithm), samples)
bat_findmedian(samples, algorithm, context)
end