This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Partial implementation of linear-trend model described in [1] using Turing.jl. | |
# | |
# # References | |
# [1] Taylor, S. J., & Letham, B., Forecasting at scale, PeerJ Preprints, 5(), 3190–2 (2017). http://dx.doi.org/10.7287/peerj.preprints.3190v2 | |
using DataFrames, CSV | |
using Turing | |
using MCMCChain, Plots, StatsPlots | |
pyplot() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MacroTools | |
using Turing | |
using LightGraphs, MetaGraphs | |
# Expressions | |
ex1 = quote | |
m(x) = begin | |
# Assumptions | |
σ ~ InverseGamma(2,3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Distributions, Bijectors | |
using ForwardDiff | |
using Tracker | |
using Turing | |
import Random: AbstractRNG | |
import Distributions: logpdf, rand, rand!, _rand!, _logpdf | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# ADVI on MNIST" | |
] | |
}, | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> using Bijectors | |
julia> using KernelGoodnessOfFit | |
julia> using Random; Random.seed!(123); | |
julia> using ForwardDiff | |
julia> function Distributions.gradlogpdf(d::ContinuousUnivariateDistribution, x::Real) | |
ForwardDiff.derivative(z -> logpdf(d, z), x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> using Turing | |
julia> function condition( | |
model::Turing.Model, | |
latent::NamedTuple; | |
sampler = DynamicPPL.SampleFromPrior() | |
) | |
vi = Turing.VarInfo(model) | |
md = vi.metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@bijector function f(b::Bijector, x) ... end | |
Takes the method `forward` and uses it to define both `transform` | |
and `logabsdetjac`, while ensuring that any shared computation is | |
taken advantage of in `forward`. | |
""" | |
macro bijector(expr) | |
def = MacroTools.splitdef(expr) | |
body = def[:body] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> using Random | |
julia> using Turing | |
julia> rng = MersenneTwister(42); | |
julia> @model function demo(x) | |
s ~ InverseGamma(2, 3) | |
m ~ Normal(0, √s) | |
for i in eachindex(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Turing | |
using TensorBoardLogger, Logging | |
using OnlineStats # used to compute different statistics on-the-fly | |
using StatsBase # Provides us with the `Histogram` which is supported by `TensorBoardLogger.jl` | |
using LinearAlgebra | |
using DataStructures # will use a `CircularBuffer` to only keep track of some `n` last samples | |
struct TBCallback | |
logger::TBLogger | |
end |
OlderNewer