Skip to content

feat: univariate Gaussian likelihood in Gaussian prior #109

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions src/models/Models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ using LogExpFunctions
include("shells.jl")
include("correlated.jl")
include("eggbox.jl")
include("univariagaussiangaussian.jl")

end # module
37 changes: 37 additions & 0 deletions src/models/univariategaussiangaussian.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Distributions
using NestedSamplers
using StatsBase

@doc raw"""
Models.UnivariateGaussianGaussian()

Creates a model with Normal prior and Normal likelihood.

```math
\mathbf\theta \sim \mathcal{N}\left(\mu_p, \sigma_p\right)
```
```math
\mathbf{d} \sim \mathcal{N}\left(\mathbf\theta, \sigma_d\right)
```
the analytical evidence of the model is

```math
Z = \mathcal{N}\left(\mu_p, \sqrt{\sigma_p^2 + \sigma_d^2}\right)
```

## Examples
```jldoctest
julia> model, lnZ = Models.UnivariateNormalNormal(2, 0.5, 1, 0);

julia> lnZ
-2.6305103088617776
```
"""

function UnivariateGaussianGaussian(μp::Float64, σp::Float64, σd::Float64, d::Float64=0.0)
priors = [Normal(μp, σp)] # θ ~ N(μ, σ)
loglike(θ) = logpdf(Normal(d, σd),θ[1]) # d ~ N(θ, σd)
model = NestedModel(loglike, priors)
true_lnZ = logpdf(Normal(μp, sqrt(σp^2 + σd^2)), d) # lnZ is analytical in the data and the prior hyperparameters
return model, true_lnZ
end