Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factor out homoscadasticity check in elbo #130

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
23 changes: 11 additions & 12 deletions src/SparseVariationalApproximationModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,26 +306,16 @@ Statistics. PMLR, 2015.
"""
function AbstractGPs.elbo(
sva::SparseVariationalApproximation,
fx::FiniteGP{<:AbstractGP,<:AbstractVector,<:Union{Diagonal{<:Real,<:Fill},ScalMat}},
fx::FiniteGP,
y::AbstractVector{<:Real};
num_data=length(y),
quadrature=DefaultExpectationMethod(),
)
σ² = fx.Σy[1]
σ² = _get_homoscedastic_noise(fx.Σy)
lik = GaussianLikelihood(σ²)
return elbo(sva, LatentFiniteGP(fx, lik), y; num_data, quadrature)
end

function AbstractGPs.elbo(
::SparseVariationalApproximation, ::FiniteGP, ::AbstractVector; kwargs...
)
return error(
"The observation noise fx.Σy must be homoscedastic.\n",
"To avoid this error, construct fx using: f = GP(kernel); fx = f(x, σ²)",
", where σ² is a positive Real.",
)
end

"""
elbo(
sva::SparseVariationalApproximation,
Expand Down Expand Up @@ -372,4 +362,13 @@ function _prior_kl(sva::SparseVariationalApproximation{NonCentered})
return (trace_term + m_ε'm_ε - length(m_ε) - logdet(C_ε)) / 2
end

_get_homoscedastic_noise(Σy::Union{Diagonal{<:Real,<:Fill},ScalMat}) = Σy[1]
function _get_homoscedastic_noise(_)
return error(
"The observation noise fx.Σy must be homoscedastic.\n",
"To avoid this error, construct fx using: f = GP(kernel); fx = f(x, σ²)",
", where σ² is a positive Real.\n"
rossviljoen marked this conversation as resolved.
Show resolved Hide resolved
)
end

end