Skip to content

Instantly share code, notes, and snippets.

View mschauer's full-sized avatar

Moritz Schauer mschauer

View GitHub Profile
@mschauer
mschauer / Reproducible error.txt
Created April 9, 2021 15:29
Julia reproducible error
julia>
shell> cd example/phylo3/
/Users/smoritz/.julia/dev/MitosisStochasticDiffEq/example/phylo3
julia> include("phylo_autobffg3.jl")
Activating environment at `~/.julia/dev/MitosisStochasticDiffEq/example/phylo3/Project.toml`
Internal error: encountered unexpected error in runtime:
BoundsError(a=Array{Int64, (30,)}[0, 0, 2, 2, 2, 1, 0, 0, 0, 0, 2, 2, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 0, 0, 0, 1, 0, 0, 0], i=(66,))
jl_bounds_error_ints at /Applications/Julia-1.6.app/Contents/Resources/julia/lib/julia/libjulia-internal.1.6.dylib (unknown line)
@mschauer
mschauer / zigzaginno.jl
Created April 8, 2021 18:22
zigzag on Innovation
using ZigZagBoomerang
using SparseArrays
using ForwardDiff
using ForwardDiff: Dual, value, partials
const D1 = Dual{Nothing, Float64, 1}
const D𝕏 = typeof(D1.(zero(𝕏)))
function partiali(F, z, i)
z[i] = Dual(z[i], 1.0)
r = partials(F(z))[]
z[i] = Dual(z[i], 0.0)
@mschauer
mschauer / gist:517b1b3d8eb8301823864ba67bd67f4d
Last active October 22, 2022 22:16
Precision Brownian motion
d = 100
ts_ = range(0, 1, length=d+1)[2:end]
Γ = SymTridiagonal([2.0ones(d-1); 1.0], -ones(d-1))/ts_[1]
# Note the covariance matrix of B.M is
ts = range(0, 1, length=d+1)[2:end]
Γ0 = inv([min(i,j) for i in ts_, j in ts_])
@test norm(Γ0 - Γ) < 1e-7
@mschauer
mschauer / bouncy.jl
Last active April 3, 2021 10:54
Linear regression, p = 5, n = 10_000_000, with subsampling and approx ML estimate as control variate
using ZigZagBoomerang
using StaticArrays
using LinearAlgebra
using SparseArrays
using Random
using Test
using Statistics
Random.seed!(2)
using StaticArrays
@mschauer
mschauer / hiddenmarkov.jl
Created March 28, 2021 10:15
Parameter inference for discrete hidden Markov model using autodial
using Random, LinearAlgebra, Distributions, StatsBase
using StaticArrays
# use representation x*exp(l) to compute the likelihood without underflow
struct Exp{T} <: Number
x::T
l::T
end
Exp(x::T) where {T<:Real} = Exp(x, zero(x))
@mschauer
mschauer / sparsezigzag.jl
Last active March 16, 2021 11:09
Simplistic ZigZag for Soss
using Soss: logdensity, xform, ConditionalModel
using ZigZagBoomerang
using ForwardDiff
using ForwardDiff: gradient!
using LinearAlgebra
using SparseArrays
using StructArrays
using TransformVariables
@mschauer
mschauer / chain.jl
Created March 10, 2021 10:25
Sketch BFFG markov chain
xnew = sample(A[x, :])
struct TransitionKernel
A::Matrix
end
(kappa::TransitionKernel)(x) = kappa.A[x, :]
A = [0.5 0.5 0
0 0.3 0.7
@mschauer
mschauer / basemeasure.jl
Last active March 7, 2021 23:41
Get reference measure
export basemeasure
import MeasureTheory
function MeasureTheory.basemeasure(c::ConditionalModel{A,B,M}, x=NamedTuple()) where {A,B,M}
_basemeasure(M, Model(c), argvals(c), observations(c), x)
end
export sourceBasemeasure
@mschauer
mschauer / condbin.jl
Last active March 3, 2021 15:27
Guided processes for conditional mixed Bernoulli
using Mitosis
using MeasureTheory
using Random
using Test
n = 30
ρ = rand(n)
struct PlusBernoulli{S,T} <: MeasureTheory.AbstractMeasure
x::S
@mschauer
mschauer / zigzagregression.jl
Created February 19, 2021 13:00
1 Million data points
using ZigZagBoomerang
using Distributions
using SparseArrays
using LinearAlgebra
using Random
Random.seed!(1)
# Million data points, 5 parameters + intercept
N = 1000000
k = 5;
X = randn(N,k);