Skip to content

Commit c54f477

Browse files
committed
STASH norm prior logd
1 parent 6d4c6e0 commit c54f477

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Diff for: Project.toml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ DistributionsAD = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
1313
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1414
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1515
HeterogeneousComputing = "2182be2a-124f-4a91-8389-f06db5907a21"
16+
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"
1617
IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153"
1718
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
1819
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -47,6 +48,7 @@ DistributionsAD = "0.6"
4748
DocStringExtensions = "0.8, 0.9"
4849
FillArrays = "1.1.1"
4950
HeterogeneousComputing = "0.2"
51+
IrrationalConstants = "0.2.2"
5052
IterativeSolvers = "0.8, 0.9"
5153
LineSearches = "7"
5254
LinearAlgebra = "1"

Diff for: src/MGVI.jl

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ using Distributions
2222
using DistributionsAD
2323
using FillArrays
2424
using HeterogeneousComputing: GenContext, allocate_array
25+
using IrrationalConstants: log2π
2526
using LineSearches
2627
using LinearMaps
2728
using Parameters

Diff for: src/mgvi_impl.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
# This file is a part of MGVI.jl, licensed under the MIT License (MIT).
22

3+
function _mv_normal_logdensity(x::AbstractVector{<:Real})
4+
T = eltype(x)
5+
r = - dot(x, x)/2 - T(length(x)) * T(log2π/2)
6+
return r
7+
end
8+
39
function posterior_loglike(model, p, data)
410
likelihood_value = logdensityof(model(p), data)
5-
# normal prior, leaving out `+ length(p)*log2π/2` normalization constant
6-
prior_density = - dot(p, p)/2
11+
# standard multivariate normal prior:
12+
prior_density = _mv_normal_logdensity(p)
713
return likelihood_value + prior_density
814
end
915

0 commit comments

Comments
 (0)