Skip to content

Instantly share code, notes, and snippets.


Moritz Schauer mschauer

View GitHub Profile
mschauer / kalmanmean.jl
Created August 23, 2023 17:58
Fancy mean with Kalman filter
View kalmanmean.jl
using Kalman
using Kalman.GaussianDistributions
using Statistics, LinearAlgebra
# prior for time 0
x0 = 0.0
P0 = floatmax(x0)
# observation operator
H = 1.0
mschauer / mixture.jl
Created May 18, 2023 15:36
Hidden correlation
View mixture.jl
using GLMakie
using Random
# mixture distribution
X(c) = rand() < c ? sqrt(rand()) : 1 - sqrt(rand())
# sample
A = [0:0.01:1;; X.(0:0.01:1)];
mschauer / quasigaussian.txt
Last active March 2, 2023 08:42
Quasi Gaussian numbers
View quasigaussian.txt
0.0 0.0
-0.032984387220723596 0.030216400626819087
0.005532055967160396 -0.06303492443179701
0.04716487617405366 0.06151822897388728
-0.08816371845816047 -0.01559492041364278
0.0844812855043274 -0.05374007858781831
-0.02848102330289795 0.10594798706320867
-0.054631054889518714 -0.10518877181328493
0.1190544569384441 0.04347849672678073
-0.12429436989984163 0.05130690904254036
mschauer /
Last active December 7, 2022 10:39
Being a bit didactic with ChatGPT.
  • You must have heard the term detailed balance in the context of Markov chains before.

Yes, I have heard of the term detailed balance in the context of Markov chains. In the context of Markov chains, detailed balance refers to a condition that must be satisfied in order for a given system to be in equilibrium. This condition states that the product of the transition probabilities between any two states in the system must be equal to the product of the reverse transition probabilities between those same two states. This ensures that the system will not tend to move towards one particular state over another, and will instead remain in a state of equilibrium.

  • That is not quite correct, let's see. Lets denote the transition probability from state x to state y by p(x → y). Detailed balance holds if there is a probability distribution π(x) over the states such that u(x,y) = π(x)p(x → y) is a symmetric function, hence u(x,y) = u(y,x).

You are correct. My previous explanation was not entirely accurate. Deta

mschauer / dual.jl
Created November 4, 2022 15:14
Dual numbers
View dual.jl
struct Dual <: Real
# w and Y and tag
end, x::Dual) = print(io, x.value, " + ", x.δ, " ϵ")
Base.:+(x::Dual, y::Dual) = Dual(x.value + y.value, x.δ + y.δ)
Base.:*(x::Dual, y::Dual) = Dual(x.value*y.value, x.δ*y.value + x.value*y.δ)
Dual(x) = Dual(x, zero(x))
Base.promote_rule(::Type{Dual},::Type{<:Real}) = Dual
mschauer / introx.jl
Last active October 17, 2022 07:02
Adam to maximise expectation or variational inference with
View introx.jl
using StochasticAD, Distributions, Optimisers, GLMakie
import Random # hide
Random.seed!(1234) # hide
# Function we want to maximize the expectation of
function X(p)
a = p*(1-p)
b = rand(Binomial(10, p))
c = 2 * b + 3 * rand(Bernoulli(p))
return a * c * rand(Normal(b, a))
View Project.toml
ArraysOfArrays = "65a8f2f4-9b39-5baf-92e2-a9cc46fdf018"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
Pathfinder = "b1d3bc72-d0e7-4279-b92f-7fa5d6d2d454"
StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
ZigZagBoomerang = "36347407-b186-4a6a-8c98-4f4567861712"
mschauer / antisocial.jl
Last active September 29, 2022 14:16
Antisocial dance (naive/knn)
View antisocial.jl
# using naive search
using GLMakie, LinearAlgebra
using StaticArrays
rot(θ) = @SMatrix [cos(θ) -sin(θ); sin(θ) cos(θ) ]
x = [Point2f(0,1), Point2f(1,0), Point2f(3, 0)]
xnew = copy(x)
δ = 0.001
xall = [copy(x)]
i = 1
mschauer / partialqueue.jl
Last active September 1, 2022 19:53
keeping track of local minima in threaded programs with PartialQueue
View partialqueue.jl
ZigZagBoomerang.jl has implemented something like a priority queue keeping track of
local minima (or high priority task).
Think of graph where vertices are tasks that are assigned priorities (smaller = higher priority)
and edges between two tasks indicate if the higher priority task has to be worked on before the
lower priority task (edge) or both can be worked on in parallel (no edge).
It’s thread-safe in the sense that priorities can be updated in different threads
if one has a proper coloring of the vertices and updates the task of one color in @threads
mschauer / Project.toml
Last active June 16, 2022 14:17
Logistic SOSS&Pathfinder&BPS
View Project.toml
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
Pathfinder = "b1d3bc72-d0e7-4279-b92f-7fa5d6d2d454"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
SampleChainsDynamicHMC = "6d9fd711-e8b2-4778-9c70-c1dfb499d4c4"
Soss = "8ce77f84-9b61-11e8-39ff-d17a774bf41c"
TupleVectors = "615932cf-77b6-4358-adcd-5b7eba981d7e"