Skip to content

Commit

Permalink
STASH norm prior logd
Browse files Browse the repository at this point in the history
  • Loading branch information
oschulz committed Oct 23, 2024
1 parent 6d4c6e0 commit c54f477
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ DistributionsAD = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
HeterogeneousComputing = "2182be2a-124f-4a91-8389-f06db5907a21"
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down Expand Up @@ -47,6 +48,7 @@ DistributionsAD = "0.6"
DocStringExtensions = "0.8, 0.9"
FillArrays = "1.1.1"
HeterogeneousComputing = "0.2"
IrrationalConstants = "0.2.2"
IterativeSolvers = "0.8, 0.9"
LineSearches = "7"
LinearAlgebra = "1"
Expand Down
1 change: 1 addition & 0 deletions src/MGVI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ using Distributions
using DistributionsAD
using FillArrays
using HeterogeneousComputing: GenContext, allocate_array
using IrrationalConstants: log2π
using LineSearches
using LinearMaps
using Parameters
Expand Down
10 changes: 8 additions & 2 deletions src/mgvi_impl.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# This file is a part of MGVI.jl, licensed under the MIT License (MIT).

function _mv_normal_logdensity(x::AbstractVector{<:Real})
T = eltype(x)
r = - dot(x, x)/2 - T(length(x)) * T(log2π/2)
return r
end

function posterior_loglike(model, p, data)
likelihood_value = logdensityof(model(p), data)
# normal prior, leaving out `+ length(p)*log2π/2` normalization constant
prior_density = - dot(p, p)/2
# standard multivariate normal prior:
prior_density = _mv_normal_logdensity(p)
return likelihood_value + prior_density
end

Expand Down

0 comments on commit c54f477

Please sign in to comment.