/
findmode_simple.jl
49 lines (32 loc) · 1.26 KB
/
findmode_simple.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
# This file is a part of BAT.jl, licensed under the MIT License (MIT).
"""
struct ModeAsDefined <: AbstractModeEstimator
Get the mode as defined by the density, resp. the underlying distribution
(if available), via `StatsBase.mode`.
Constructors:
* ```$(FUNCTIONNAME)()```
"""
struct ModeAsDefined <: AbstractModeEstimator end
export ModeAsDefined
function bat_findmode_impl(target::AnySampleable, algorithm::ModeAsDefined, context::BATContext)
(result = StatsBase.mode(target),)
end
function bat_findmode_impl(target::Distribution, algorithm::ModeAsDefined, context::BATContext)
(result = varshape(target)(StatsBase.mode(unshaped(target))),)
end
function bat_findmode_impl(target::BATDistMeasure, algorithm::ModeAsDefined, context::BATContext)
bat_findmode_impl(Distribution(target), algorithm, context)
end
"""
MaxDensitySearch <: AbstractModeEstimator
Constructors:
MaxDensitySearch()
Estimate the mode as the variate with the highest posterior density value
within a given set of samples.
"""
struct MaxDensitySearch <: AbstractModeEstimator end
export MaxDensitySearch
function bat_findmode_impl(target::DensitySampleVector, algorithm::MaxDensitySearch, context::BATContext)
v, i = _get_mode(target)
(result = v, mode_idx = i)
end