1
- export ValueHistogram, VisitationFrequency, AbstractBinning
2
-
3
- """
4
- AbstractBinning
5
-
6
- The supertype of all binning schemes.
7
- """
8
- abstract type AbstractBinning end
9
-
1
+ export ValueHistogram, VisitationFrequency
10
2
# We need binning to be defined first to add it as a field to a struct
11
3
include (" rectangular_binning.jl" )
12
4
include (" fasthist.jl" )
@@ -42,10 +34,19 @@ are returned as `SVector`s.
42
34
43
35
See also: [`RectangularBinning`](@ref).
44
36
"""
45
- struct ValueHistogram{B <: AbstractBinning } <: ProbabilitiesEstimator
46
- binning :: B
37
+ struct ValueHistogram{H <: HistogramEncoding } <: ProbabilitiesEstimator
38
+ encoding :: H
47
39
end
48
40
ValueHistogram (ϵ:: Union{Real,Vector} ) = ValueHistogram (RectangularBinning (ϵ))
41
+ function ValueHistogram (x, b:: AbstractBinning )
42
+ encoding = RectangularBinEncoding (x, b)
43
+ return ValueHistogram (encoding)
44
+ end
45
+ function ValueHistogram (b:: FixedRectangularBinning )
46
+ encoding = RectangularBinEncoding (b)
47
+ return ValueHistogram (encoding)
48
+ end
49
+
49
50
50
51
"""
51
52
VisitationFrequency
@@ -54,24 +55,20 @@ An alias for [`ValueHistogram`](@ref).
54
55
"""
55
56
const VisitationFrequency = ValueHistogram
56
57
57
- # For organizational outcomes we extend methods here. However, their
58
- # source code in truth is in the binnings file using the bin encoding
59
-
60
- # This method is only valid for rectangular binnings, as `fasthist`
61
- # is only valid for rectangular binnings. For more binnings, it needs to be extended.
58
+ # The source code of `ValueHistogram` operates as rather simple calls to
59
+ # the underlying encoding and the `fasthist` function and extensions.
60
+ # See the `rectangular_binning.jl` file for more.
62
61
function probabilities (x:: Array_or_Dataset , est:: ValueHistogram )
63
- # and the `fasthist` actually just makes an encoding,
64
- # this function is in `rectangular_binning.jl`
65
- Probabilities (fasthist (x, est. binning)[1 ])
62
+ Probabilities (fasthist (x, est. encoding)[1 ])
66
63
end
67
64
68
65
function probabilities_and_outcomes (x:: Array_or_Dataset , est:: ValueHistogram )
69
- probs, bins, encoder = fasthist (x, est. binning)
66
+ probs, bins = fasthist (x, est. encoding) # bins are integers here
70
67
unique! (bins) # `bins` is already sorted from `fasthist!`
71
68
# Here we transfor the cartesian coordinate based bins into data unit bins:
72
- outcomes = map (b -> decode_from_bin (b, encoder), bins)
69
+ outcomes = map (b -> decode (b, encoder), bins)
73
70
return Probabilities (probs), vec (outcomes)
74
71
end
75
72
76
- outcome_space (x, est:: ValueHistogram ) = outcome_space (x, est. binning )
77
- total_outcomes (x, est:: ValueHistogram ) = total_outcomes (x, est. binning )
73
+ outcome_space (x, est:: ValueHistogram ) = outcome_space (x, est. encoding )
74
+ total_outcomes (x, est:: ValueHistogram ) = total_outcomes (x, est. encoding )
0 commit comments