Skip to content

Commit d6dc9a4

Browse files
committed
Merge branch 'dev' into arithmetic
2 parents 17e7168 + 076cbd2 commit d6dc9a4

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ julia> pdf(v, L)
122122
## Measures over finite labeled sets
123123

124124
There is, in fact, no enforcement that probabilities in a
125-
`UnivariateFinite` distribution sum to one, only that they be
126-
non-negative. Thus `UnivariateFinite` objects can be more properly
127-
understood as an implementation of arbitrary non-negative measures
128-
over finite labeled sets.
125+
`UnivariateFinite` distribution sum to one, only that they be belong
126+
to a type `T` for which `zero(T)` is defined. In particular
127+
`UnivariateFinite` objects implement arbitrary non-negative, signed,
128+
or complex measures over a finite labeled set.
129129

130130

131131
## What does this package provide?

src/methods.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,9 @@ function Dist.fit(d::Type{<:UnivariateFinite},
330330
end
331331

332332

333+
# # BROADCASTING OVER SINGLE UNIVARIATE FINITE
334+
335+
# This mirrors behaviour assigned Distributions.Distribution objects,
336+
# which allows `pdf.(d::UnivariateFinite, support(d))` to work.
337+
338+
Broadcast.broadcastable(d::UnivariateFinite) = Ref(d)

src/types.jl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,14 @@ same size as the array.
161161

162162
# # TYPES - PLAIN AND ARRAY
163163

164-
# extend Ditributions type hiearchy to account for non-euclidean
165-
# supports:
166-
abstract type Categorical{S<:Finite} <: Dist.ValueSupport end
167-
168-
# not exported:
169-
const _UnivariateFinite_{S} =
170-
Dist.Distribution{Dist.Univariate,Categorical{S}}
171-
172164
# R - reference type <: Unsigned
173165
# V - type of class labels (eg, Char in `categorical(['a', 'b'])`)
174166
# P - raw probability type
175167
# S - scitype of samples
176168

177169
# Note that the keys of `prob_given_ref` need not exhaust all the
178170
# refs of all classes but will be ordered (LittleDicts preserve order)
179-
DOC_CONSTRUCTOR
180-
struct UnivariateFinite{S,V,R,P} <: _UnivariateFinite_{S}
171+
struct UnivariateFinite{S,V,R,P}
181172
scitype::Type{S}
182173
decoder::CategoricalDecoder{V,R}
183174
prob_given_ref::LittleDict{R,P,Vector{R}, Vector{P}}

test/methods.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ A, S, Q, F = V[1], V[2], V[3], V[4]
121121
@test pdf(d, "class_1") == 0.7
122122
end
123123

124+
@testset "broadcasting pdf over single UnivariateFinite object" begin
125+
d = UnivariateFinite(["a", "b"], [0.1, 0.9], pool=missing);
126+
@test pdf.(d, ["a", "b"]) == [0.1, 0.9]
127+
end
128+
124129
@testset "constructor arguments not categorical values" begin
125130
@test_throws ArgumentError UnivariateFinite(Dict('f'=>0.7, 'q'=>0.2))
126131
@test_throws ArgumentError UnivariateFinite(Dict('f'=>0.7, 'q'=>0.2),

0 commit comments

Comments
 (0)