Skip to content

Instantly share code, notes, and snippets.

View mschauer's full-sized avatar

Moritz Schauer mschauer

View GitHub Profile
@mschauer
mschauer / sde.jl
Last active May 12, 2021 15:32
Elementary sample SDE using forward simulation and random walk on Wiener process ("Crank-Nicolson" scheme).
using AdvancedMH
using Distributions
using Random
using MCMCChains
using StructArrays
struct MvWiener{Tu0,Ttrange} <: ContinuousMatrixDistribution
u0::Tu0
trange::Ttrange
end
@mschauer
mschauer / lingauss.jl
Created May 9, 2021 09:24
Bayesian linear Gaussian models
using LinearAlgebra, Test, Random, Statistics
outer(x) = x*x'
lchol(x) = cholesky(Symmetric(x)).L
Random.seed!(1)
# dimensions
n = 10 # observed
p = 5 # latent
# parameters
@mschauer
mschauer / solver.jl
Created May 4, 2021 15:36
Zero cost abstraction Maruyama solver
using StaticArrays
struct EulerMaruyama!
end
"""
tangent!(du, u, dz, P)
"""
@mschauer
mschauer / create_gist.jl
Created May 1, 2021 12:23
create_gist.jl
using GitHub, JSON
#myauth = GitHub.authenticate(ENV["GITHUB_AUTH"])
gist_json(fn; description="$fn", public=true) = JSON.parse(
"""
{
"description": "$description",
"public": $public,
"files": {
@mschauer
mschauer / mappairreduce.jl
Created April 30, 2021 16:51
Map (running) pairs with f and reduce with r
function mappairreduce(r, f, itr, dec)
ϕ = iterate(itr)
if ϕ === nothing
return dec
end
xlast, state = ϕ
while true
ϕ = iterate(itr, state)
if ϕ === nothing
return dec
@mschauer
mschauer / shadercalibration.jl
Created April 14, 2021 14:57
Calibration test image for Makie
using Makie
using Colors
n = 100
f(x) = 0.5 .*reim(((x[1] + x[2]*im)/33)^2)
function f2(x)
0.5.*abs(2*(x[1] + x[2]*im)/1089)
end
#f(x) = (x[1],x[2])
#f2(x) = 1.0
@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