Skip to content

Commit

Permalink
Merge pull request #434 from alan-turing-institute/dev
Browse files Browse the repository at this point in the history
For a 0.15.3 release
  • Loading branch information
ablaom authored Oct 13, 2020
2 parents 2b01dae + 0eb5c2e commit c58bcfc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MLJBase"
uuid = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
authors = ["Anthony D. Blaom <[email protected]>"]
version = "0.15.2"
version = "0.15.3"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down Expand Up @@ -32,7 +32,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
[compat]
CategoricalArrays = "^0.8.1"
ComputationalResources = "^0.3"
Distributions = "^0.22,^0.23"
Distributions = "0.22, 0.23, 0.24"
HTTP = "^0.8"
InvertedIndices = "^1"
JLSO = "^2.1,^2.2"
Expand Down
5 changes: 5 additions & 0 deletions src/composition/models/pipelines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ in which the specified models are composed in order. This means
`model1` receives inputs, whose output is passed to `model2`, and so
forth. Model types or instances may be specified.
**Important.** By default a new model *type* name is automatically
generated. To specify a different name add a keyword argument such as
`name=MyPipeType`. This is necessary if serializing the pipeline; see
[`MLJ.save`](@ref).
At most one of the models may be a supervised model, but this model
can appear in any position.
Expand Down
22 changes: 13 additions & 9 deletions src/univariate_finite/methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ function average(dvec::AbstractVector{UnivariateFinite{S,V,R,P}};
return UnivariateFinite(sample_scitype(d1), d1.decoder, prob_given_ref)
end


function _pdf(d::UnivariateFinite{S,V,R,P}, ref) where {S,V,R,P}
return get(d.prob_given_ref, ref, zero(P))
end

"""
Distributions.pdf(d::UnivariateFinite, x)
Expand Down Expand Up @@ -226,11 +221,18 @@ One can also do weighted fits:
See also `classes`, `support`.
"""
Distributions.pdf(d::UnivariateFinite, cv::CategoricalValue) = _pdf(d, int(cv))

function Distributions.pdf(
d::UnivariateFinite{S,V,R,P}, c::V) where {S,V,R,P}
d::UnivariateFinite{S,V,R,P},
cv::CategoricalValue,
) where {S,V,R,P}
return get(d.prob_given_ref, int(cv), zero(P))
end
Distributions.pdf(d::UnivariateFinite{S,V}, c::V) where {S,V} = _pdf(d, c)

# Avoid method ambiguity errors with Distributions >= 0.24
Distributions.pdf(d::UnivariateFinite{S,V}, c::V) where {S,V<:Real} = _pdf(d, c)

function _pdf(d::UnivariateFinite, c)
_classes = classes(d)
c in _classes || throw(DomainError("Value $c not in pool. "))
pool = CategoricalArrays.pool(_classes)
Expand All @@ -239,8 +241,10 @@ function Distributions.pdf(
end

Distributions.logpdf(d::UnivariateFinite, cv::CategoricalValue) = log(pdf(d,cv))
Distributions.logpdf(d::UnivariateFinite{S,V}, c::V) where {S,V} = log(pdf(d, c))

Distributions.logpdf(d::UnivariateFinite{S,V,R,P}, c::V) where {S,V,R,P} = log(pdf(d,c))
# Avoid method ambiguity errors with Distributions >= 0.24
Distributions.logpdf(d::UnivariateFinite{S,V}, c::V) where {S,V<:Real} = log(pdf(d, c))

function Distributions.mode(d::UnivariateFinite)
dic = d.prob_given_ref
Expand Down
5 changes: 5 additions & 0 deletions test/univariate_finite/methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ end
@test pdf(d, 'f') == 0
@test pdf(d, f) == 0
@test_throws DomainError pdf(d, 'j')

# regression test
# https://github.com/alan-turing-institute/MLJBase.jl/pull/432/files#r502299301
d = UnivariateFinite(classes(categorical(UInt32[0, 1])), [0.4, 0.6])
@test pdf(d, UInt32(1)) == 0.6
end

@testset "approx for UnivariateFinite" begin
Expand Down

0 comments on commit c58bcfc

Please sign in to comment.