Instantly share code, notes, and snippets.

# Moritz Schauer mschauer

Last active February 19, 2024 14:21
Bayes ball
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 CausalInference, Graphs V = [:U, :T, :P, :O] ι = Dict(v=>i for (i,v) in enumerate(V)) g = digraph([1=>3, 2=>3, 3=>4, 2=>4, 1=>4]) # Can estimate total effect T=>O without observing U? u = ι[:T] v = ι[:O] ∅ = Set{Int}()
Created August 23, 2023 17:58
Fancy mean with Kalman filter
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 Kalman using Kalman.GaussianDistributions using Statistics, LinearAlgebra # prior for time 0 x0 = 0.0 P0 = floatmax(x0) # observation operator H = 1.0
Created May 18, 2023 15:36
Hidden correlation
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 GLMakie using Random # mixture distribution X(c) = rand() < c ? sqrt(rand()) : 1 - sqrt(rand()) # sample Random.seed!(1); A = [0:0.01:1;; X.(0:0.01:1)];
Last active March 2, 2023 08:42
Quasi Gaussian numbers
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
 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
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

Created November 4, 2022 15:14
Dual numbers
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
 struct Dual <: Real value δ # w and Y and tag end Base.show(io::IO, 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
Last active October 17, 2022 07:02