Skip to content

Instantly share code, notes, and snippets.

@mschauer
Created March 10, 2021 10:25
Show Gist options
  • Save mschauer/fa68d1d5ddcf08a87525e8318e8ca195 to your computer and use it in GitHub Desktop.
Save mschauer/fa68d1d5ddcf08a87525e8318e8ca195 to your computer and use it in GitHub Desktop.
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
1/3 1/3 1/3
]
kappa = TransitionKernel(A)
x = 2
kappa(x) == [0.0, 0.3,0.7]
function backward(kappatilde::TransitionKernel, h)
hout = kappatilde.A*h
message = (hout, h)
return message, hout
end
function forward(kappa::TransitionKernel, message, x)
A = kappa.A
hout, h = message
samplefrom = A[x, :] .* h
samplefrom ./ sum(samplefrom)
end
hT = [0, 0, 1]
message, hout = backward(kappatilde, hT)
...
...
x = sample(forward(kappa, message, x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment