Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions src/Emulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ function Emulator(

if !isnothing(obs_noise_cov)
if haskey(encoder_kwargs, :obs_noise_cov)
@warn "Keyword argument `obs_noise_cov=` is deprecated and will be ignored in favor of `encoder_kwargs[:obs_noise_cov]`."
@warn "Keyword argument `obs_noise_cov=` is deprecated and will be ignored in favor of `encoder_kwargs=(obs_noise_cov=...)`."
else
@warn "Keyword argument `obs_noise_cov=` is deprecated. Please use `encoder_kwargs[:obs_noise_cov]` instead."
@warn "Keyword argument `obs_noise_cov=` is deprecated. Please use `encoder_kwargs=(obs_noise_cov=...)` instead."
end
end

Expand Down
25 changes: 14 additions & 11 deletions src/MarkovChainMonteCarlo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,14 @@ autodiff_hessian(model::AdvancedMH.DensityModel, params, sampler::MH) where {MH
"""
$(DocStringExtensions.TYPEDSIGNATURES)

Defines the internal log-density function over a vector of observation samples using an assumed conditionally indepedent likelihood, that is with a log-likelihood of `ℓ(y,θ) = sum^n_i log( p(y_i|θ) )`.
Defines the internal log-density function over a vector of observation samples using an assumed conditionally indepedent likelihood, that is with a log-likelihood of `ℓ(y,θ) = sum^n_i log( p(y_i|θ) )`.

Inputs:
=======
- θ: Parameters in physical (constrained) coordinates.
- prior: Prior distribution as a ParameterDistribution
- em: Emulator object with predict(.) method, evaluations returned in encoded space
- obs_vec: encoded data vector sample(s)
"""
function emulator_log_density_model(
θ,
Expand All @@ -242,21 +249,17 @@ function emulator_log_density_model(
obs_vec::AV,
) where {FT <: AbstractFloat, AV <: AbstractVector}

# θ: model params we evaluate at; in original coords.
# transform_to_real = false means g, g_cov, obs_sample are in decorrelated coords.
#
# transform_to_real = false means g, g_cov, obs_sample are in encoded coords.

# Recall predict() written to return multiple N_samples: expects input to be a
# Matrix with N_samples columns. Returned g is likewise a Matrix, and g_cov is a
# Vector of N_samples covariance matrices. For MH, N_samples is always 1, so we
# have to reshape()/re-cast input/output; simpler to do here than add a
# predict() method.
# predict is written to apply to columns.
# Returned g is a length-1, Vector{Real} or Vector{Vector}, and g_cov is length-1 Vector{Vector} or Vector{Matrix} respectively
g, g_cov = Emulators.predict(em, reshape(θ, :, 1), transform_to_real = false)

if isa(g_cov[1], Real)

return 1.0 / length(obs_vec) * sum([logpdf(MvNormal(obs, g_cov[1] * I), vec(g)) for obs in obs_vec]) + logpdf(prior, θ)
return sum([logpdf(MvNormal(obs, g_cov[1] * I), vec(g)) for obs in obs_vec]) + logpdf(prior, θ)
else
return 1.0 / length(obs_vec) * sum([logpdf(MvNormal(obs, g_cov[1]), vec(g)) for obs in obs_vec]) + logpdf(prior, θ)
return sum([logpdf(MvNormal(obs, g_cov[1]), vec(g)) for obs in obs_vec]) + logpdf(prior, θ)
end

end
Expand Down
Loading