Skip to content

Commit fe5c86c

Browse files
committed
rm average method and tests
1 parent 233a048 commit fe5c86c

File tree

2 files changed

+0
-70
lines changed

2 files changed

+0
-70
lines changed

src/methods.jl

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -136,58 +136,6 @@ end
136136

137137
# TODO: It would be useful to define == as well.
138138

139-
# TODO: Now that `UnivariateFinite` is any finite measure, we can
140-
# replace the following nonsense with an overloading of `+`. I think
141-
# it is only used in MLJEnsembles.jl - but need to check. I believe
142-
# this is a private method we can easily remove
143-
144-
function average(dvec::AbstractVector{UnivariateFinite{S,V,R,P}};
145-
weights=nothing) where {S,V,R,P}
146-
147-
n = length(dvec)
148-
149-
Dist.@check_args(UnivariateFinite, weights == nothing || n==length(weights))
150-
151-
# check all distributions have consistent pool:
152-
first_index = first(dvec).decoder.classes
153-
for d in dvec
154-
d.decoder.classes == first_index ||
155-
error("Averaging UnivariateFinite distributions with incompatible"*
156-
" pools. ")
157-
end
158-
159-
# get all refs:
160-
refs = reduce(union, [keys(d.prob_given_ref) for d in dvec]) |> collect
161-
162-
# initialize the prob dictionary for the distribution sum:
163-
prob_given_ref = LittleDict{R,P}([refs...], zeros(P, length(refs)))
164-
165-
# make vector of all the distributions dicts padded to have same common keys:
166-
prob_given_ref_vec = map(dvec) do d
167-
merge(prob_given_ref, d.prob_given_ref)
168-
end
169-
170-
# sum up:
171-
if weights == nothing
172-
scale = 1/n
173-
for x in refs
174-
for k in 1:n
175-
prob_given_ref[x] += scale*prob_given_ref_vec[k][x]
176-
end
177-
end
178-
else
179-
scale = 1/sum(weights)
180-
for x in refs
181-
for k in 1:n
182-
prob_given_ref[x] +=
183-
weights[k]*prob_given_ref_vec[k][x]*scale
184-
end
185-
end
186-
end
187-
d1 = first(dvec)
188-
return UnivariateFinite(sample_scitype(d1), d1.decoder, prob_given_ref)
189-
end
190-
191139
"""
192140
Dist.pdf(d::UnivariateFinite, x)
193141

test/methods.jl

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -239,24 +239,6 @@ end
239239
UnivariateFinite([maybe, yes, no], [0.7, 0.2, 0.1])))
240240
end
241241

242-
@testset "UnivariateFinite arithmetic" begin
243-
v = categorical(collect("abc"))
244-
a , b, c = v[1], v[2], v[3]
245-
246-
d1 = UnivariateFinite([a, b], [0.2, 0.8])
247-
d2 = UnivariateFinite([b, c], [0.3, 0.7])
248-
dvec = [d1, d2]
249-
d = CategoricalDistributions.average(dvec)
250-
@test pdf(d, 'a') 0.1
251-
@test pdf(d, 'b') 0.55
252-
@test pdf(d, 'c') 0.35
253-
w = [4, 6]
254-
d = CategoricalDistributions.average(dvec, weights=w)
255-
@test pdf(d, 'a') 0.4*0.2
256-
@test pdf(d, 'b') 0.4*0.8 + 0.6*0.3
257-
@test pdf(d, 'c') 0.6*0.7
258-
end
259-
260242
@testset "params" begin
261243
d = UnivariateFinite(["x", "y"], [0.3, 0.7], pool=missing)
262244
ps = Distributions.params(d)

0 commit comments

Comments
 (0)