Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/multivariate/mvnormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,9 @@ fit_mle(D::Type{MvNormal}, ss::MvNormalStats) = fit_mle(FullNormal, ss)
fit_mle(D::Type{MvNormal}, x::AbstractMatrix{Float64}) = fit_mle(FullNormal, x)
fit_mle(D::Type{MvNormal}, x::AbstractMatrix{Float64}, w::AbstractArray{Float64}) = fit_mle(FullNormal, x, w)

fit_mle(D::Type{FullNormal}, ss::MvNormalStats) = MvNormal(ss.m, ss.s2 * inv(ss.tw))
fit_mle(D::Type{<:FullNormal}, ss::MvNormalStats) = MvNormal(ss.m, ss.s2 * inv(ss.tw))

function fit_mle(D::Type{FullNormal}, x::AbstractMatrix{Float64})
function fit_mle(D::Type{<:FullNormal}, x::AbstractMatrix{Float64})
n = size(x, 2)
mu = vec(mean(x, dims=2))
z = x .- mu
Expand All @@ -408,7 +408,7 @@ function fit_mle(D::Type{FullNormal}, x::AbstractMatrix{Float64})
MvNormal(mu, PDMat(C))
end

function fit_mle(D::Type{FullNormal}, x::AbstractMatrix{Float64}, w::AbstractVector)
function fit_mle(D::Type{<:FullNormal}, x::AbstractMatrix{Float64}, w::AbstractVector)
m = size(x, 1)
n = size(x, 2)
length(w) == n || throw(DimensionMismatch("Inconsistent argument dimensions"))
Expand All @@ -428,7 +428,7 @@ function fit_mle(D::Type{FullNormal}, x::AbstractMatrix{Float64}, w::AbstractVec
MvNormal(mu, PDMat(C))
end

function fit_mle(D::Type{DiagNormal}, x::AbstractMatrix{Float64})
function fit_mle(D::Type{<:DiagNormal}, x::AbstractMatrix{Float64})
m = size(x, 1)
n = size(x, 2)

Expand All @@ -443,7 +443,7 @@ function fit_mle(D::Type{DiagNormal}, x::AbstractMatrix{Float64})
MvNormal(mu, PDiagMat(va))
end

function fit_mle(D::Type{DiagNormal}, x::AbstractMatrix{Float64}, w::AbstractVector)
function fit_mle(D::Type{<:DiagNormal}, x::AbstractMatrix{Float64}, w::AbstractVector)
m = size(x, 1)
n = size(x, 2)
length(w) == n || throw(DimensionMismatch("Inconsistent argument dimensions"))
Expand All @@ -462,7 +462,7 @@ function fit_mle(D::Type{DiagNormal}, x::AbstractMatrix{Float64}, w::AbstractVec
MvNormal(mu, PDiagMat(va))
end

function fit_mle(D::Type{IsoNormal}, x::AbstractMatrix{Float64})
function fit_mle(D::Type{<:IsoNormal}, x::AbstractMatrix{Float64})
m = size(x, 1)
n = size(x, 2)

Expand All @@ -478,7 +478,7 @@ function fit_mle(D::Type{IsoNormal}, x::AbstractMatrix{Float64})
MvNormal(mu, ScalMat(m, va / (m * n)))
end

function fit_mle(D::Type{IsoNormal}, x::AbstractMatrix{Float64}, w::AbstractVector)
function fit_mle(D::Type{<:IsoNormal}, x::AbstractMatrix{Float64}, w::AbstractVector)
m = size(x, 1)
n = size(x, 2)
length(w) == n || throw(DimensionMismatch("Inconsistent argument dimensions"))
Expand Down
9 changes: 9 additions & 0 deletions test/multivariate/mvnormal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ end
@test isa(g, DiagNormal)
@test g.μ ≈ uw
@test g.Σ.diag ≈ diag(Cw)

# fit_mle should accept the aliases in instantiated or fully concrete form,
# not just as the bare `UnionAll` name (#2073 regression)
for A in (FullNormal, DiagNormal, IsoNormal)
g = fit_mle(A, x)
@test fit_mle(A{Float64}, x) == g # instantiated alias
@test fit_mle(typeof(g), x) == g # concrete member type
@test fit_mle(A{Float64}, x, w) == fit_mle(A, x, w)
end
end

@testset "MvNormal affine transformations" begin
Expand Down
Loading