-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Labels
dynamicpplneeds an upstream fix in DynamicPPL or other TuringLang reponeeds an upstream fix in DynamicPPL or other TuringLang repo
Description
using DynamicPPL
using DynamicPPL.TestUtils.AD: run_ad
using Distributions
using ADTypes: AutoForwardDiff, AutoMooncake
import ForwardDiff
import Mooncake
using Random: Xoshiro
y = [1502.39, 1505.62, 1509.48, 1507.72, 1512.58]
@model function dppl_sto_volatility(y, ::Type{Tv}=Vector{Float64}) where {Tv}
T = length(y)
μ ~ Cauchy(0, 10)
ϕ ~ Uniform(-1, 1)
σ ~ truncated(Cauchy(0, 5); lower=0)
h = Tv(undef, T)
h[1] ~ Normal(μ, σ / sqrt(1 - ϕ^2))
y[1] ~ Normal(0, exp(h[1] / 2))
for t in 2:T
h[t] ~ Normal(μ + ϕ * (h[t-1] - μ), σ)
y[t] ~ Normal(0, exp(h[t] / 2))
end
end
model = dppl_sto_volatility(y[1:5])
xs = DynamicPPL.link(VarInfo(Xoshiro(468), model), model)[:]
fd_res = run_ad(model, AutoForwardDiff(); test=false, params=xs)
mc_res = run_ad(model, AutoMooncake(); test=false, params=xs)
fd_res.grad_actual .- mc_res.grad_actual
#=
8-element Vector{Float64}:
0.0
2.7755575615628914e-17
5.551115123125783e-16
-1.9342813113834067e25
0.0
1.9342813113834067e25
0.0
-1.9342813113834067e25
=#
Metadata
Metadata
Assignees
Labels
dynamicpplneeds an upstream fix in DynamicPPL or other TuringLang reponeeds an upstream fix in DynamicPPL or other TuringLang repo