Skip to content

Instantly share code, notes, and snippets.

View mschauer's full-sized avatar

Moritz Schauer mschauer

View GitHub Profile
@mschauer
mschauer / harpoon.tex
Last active April 11, 2020 19:55
Nice over-harpoons
% https://tex.stackexchange.com/a/530909/194729
\makeatletter
% \overarrow@ and \arrowfill@ are defined in amsmath
\newcommand*{\overrightharpoonup}{\mathpalette{\overarrow@\rightharpoonupfill@}}
\newcommand*{\overleftharpoonup}{\mathpalette{\overarrow@\leftharpoonupfill@}}
\newcommand*{\rightharpoonupfill@}{\arrowfill@\relbar\relbar\rightharpoonup}
\newcommand*{\leftharpoonupfill@}{\arrowfill@\leftharpoonup\relbar\relbar}
@mschauer
mschauer / bffg.jl
Last active April 13, 2020 14:36
Reference implementation of backwards filtering, forward guiding with https://arxiv.org/abs/1712.03807
using LinearAlgebra
using Random
using GaussianDistributions
using GaussianDistributions: logpdf
pair(u) = u[1], u[2]
pair(p::Gaussian) = p.μ, p.Σ
skiplast(r) = r[1:end-1]
# time grid
@mschauer
mschauer / savepng.jl
Created March 30, 2020 07:10
Simon's png saving experiment
using WGLMakie, AbstractPlotting, FileIO
WGLMakie.activate!()
pl1 = WGLMakie.scatter(rand(10), rand(10))
using FileIO, AbstractPlotting, WGLMakie
using WGLMakie.JSServe
output = []
function save_plot(path::String, scene::Scene)
return JSServe.with_session() do session, request
three, canvas = WGLMakie.three_display(session, scene)
@mschauer
mschauer / doi2bibtex
Created March 20, 2020 18:21
Query bibtex from doing.org
function doi2bibtex(doi)
url = startswith(doi, "http") ? doi : joinpath("https://doi.org/", doi)
resp = HTTP.get(url, ["Accept"=>"application/x-bibtex; charset=utf-8"]; forwardheaders=true)
strip(String(resp.body))
end
@mschauer
mschauer / julia.jl
Created March 12, 2020 14:15 — forked from c42f/Manifest.toml
Julia Fractals via inverse iteration
using Colors
using ColorVectorSpace
using FileIO
using REPL
using ImageTransformations
using ImageView
@inline function inv_julia_map(z, c, n)
ws = (1.0, exp(2/3*pi*im), exp(-2/3*pi*im))
ws[n]*(z - c)^(1/3)
@mschauer
mschauer / jsparticles.jl
Last active March 10, 2020 23:17
Serve particles with WGLMakie and JSServe
using JSServe, WGLMakie, AbstractPlotting
using JSServe: JSServe.DOM, @js_str, onjs
global three, scene
using StaticArrays
using Colors
using Random
rebirth(α, R) = x -> (rand() > α ? x : (2rand(typeof(x)) .- 1).*R)
const 𝕏 = SVector
@mschauer
mschauer / JuliaSquared.jl
Last active March 9, 2020 11:28 — forked from zenon/JuliaSquared.jl
Julia^2: Julia sets in Julia, using Interact. I'd like it faster.
using Plots, Interact, Base.Threads, BenchmarkTools
# only called by resize.
function batchify(maxIndex, numBatches)
if mod(maxIndex, numBatches) == 0
n = numBatches
else
n = numBatches - 1
end
batchSize = div(maxIndex, n)
@mschauer
mschauer / picalc.jl
Last active February 12, 2020 17:06
"Calculate" pi in threads with avx
using LoopVectorization
using Base.Threads
function picalc_(r, a, b)
su = 0.0
@avx for j in a:b
su += 4.0/(1.0 + r[j]*r[j])
end
su
end
@mschauer
mschauer / moebius2.jl
Created February 4, 2020 10:31
Makie Möbius band
t = 0:0.1:2pi+0.1
tslider, tau = textslider(1:200, "n", start = 1);
lower = lift(tau) do i
[Point3f0(.2cos(3s + i/10),0.0, 0.0) .+ (1 + 0.2sin(3s + i/10))*Point3f0(0, cos(s), sin(s)) for s in t]
end
upper = lift(tau) do i
[Point3f0(-.2cos(3s + i/10),0.0, 0.0) .+ (1 - 0.2sin(3s + i/10)).*Point3f0(0, cos(s), sin(s)) for s in t]
end
hbox(tslider, band(lower, upper, color = [1.0:length(t)÷2; length(t)÷2:-1:1.0; length(t)÷2:-1:1.0; 1.0:length(t)÷2]))
@mschauer
mschauer / example.jl
Last active October 2, 2020 17:20
Stochastic process example with Girsanov likelihood
struct StoProMeasure
θ::Float64
end
struct WienerMeasure
end
function logdensity(P::StoProMeasure, tr, ::WienerMeasure)
som = 0.0
t, x = tr