Skip to content

Commit

Permalink
Merge pull request #51 from aisopous/ai/ncomponents-probs
Browse files Browse the repository at this point in the history
Add missing Distributions methods for KeyedMixtureModel
  • Loading branch information
rofinn authored Feb 7, 2023
2 parents dc5d9e0 + 5a0bbbe commit 063fd33
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KeyedDistributions"
uuid = "2576fb08-064d-4cab-b15d-8dda7fcb9a6d"
authors = ["Invenia Technical Computing Corporation"]
version = "0.1.16"
version = "0.1.17"

[deps]
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
Expand Down
8 changes: 6 additions & 2 deletions src/KeyedDistributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ Distributions.sampler(d::KeyedDistribution) = sampler(distribution(d))

Distributions.params(d::KeyedDistOrSampleable) = params(distribution(d))

Distributions.probs(d::KeyedMixtureModel) = probs(distribution(d))

Distributions.components(d::KeyedMixtureModel) = components(distribution(d))

Distributions.ncomponents(d::KeyedMixtureModel) = ncomponents(distribution(d))

Base.eltype(d::KeyedDistribution) = eltype(distribution(d))

function Distributions._logpdf(d::KeyedDistribution, x::AbstractArray)
Expand Down Expand Up @@ -341,8 +347,6 @@ function KeyedDistribution(
return KeyedDistribution(kd.d, keys)
end

Distributions.components(kd::KeyedMixtureModel) = Distributions.components(kd.d)

function (mm::KeyedMixtureModel)(keys...)
margcomps = map(Distributions.components(mm)) do c
inds = first(map(AxisKeys.findindex, keys, axiskeys(mm)))
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ using Test
@test mean(d[[2]]) == mean(mm[[2]])
@test cov(d[[2]]) == cov(mm[[2]])
@test mm isa MixtureModelLike
@test probs(mm) == pri
@test ncomponents(mm) == 2
@test components(mm) == [d, d]
end

@testset "Mixture of KeyedMvTDist{AbstractArray, PDMats}" begin
Expand Down

2 comments on commit 063fd33

@rofinn
Copy link
Member Author

@rofinn rofinn commented on 063fd33 Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/77229

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.17 -m "<description of version>" 063fd330ff8c466af0013b77bbec68b1ac74d9cc
git push origin v0.1.17

Please sign in to comment.