Skip to content

Instantly share code, notes, and snippets.

View dermesser's full-sized avatar
🐢
a bit of time :-)

Lewin Bormann dermesser

🐢
a bit of time :-)
View GitHub Profile
@dermesser
dermesser / mmi.ipynb
Last active December 10, 2021 09:23
Calculating Multimode Interferometer (rectangular) in Julia using elementary math
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dermesser
dermesser / multibisect.py
Created November 29, 2021 19:30
Annotated version of a multi-bisect algorithm finding all places where "performance became worse" in a commit list.
import numpy as np
#perf = [10, 10, 10, 10, 9, 9, 9, 9, 9, 9, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2]
perf = np.concatenate([4*np.ones(25), 2*np.ones(25), np.ones(25)])
#perf = list(range(40, 0, -1))
count = 0
def worseCommit(a, b):
global count
count += 1
@dermesser
dermesser / gpr_diff.jl
Created October 26, 2021 11:59
Differentiating a GPR model
### A Pluto.jl notebook ###
# v0.16.0
using Markdown
using InteractiveUtils
# ╔═╡ b70ce3a6-30e8-11ec-3f2a-59d54d66bfbd
begin
import Zygote
import Plots
@dermesser
dermesser / max_likelihood.jl
Created August 8, 2021 08:55
Simple example for fitting a normal distribution using max likelihood and gradient descent
### A Pluto.jl notebook ###
# v0.15.1
using Markdown
using InteractiveUtils
# ╔═╡ cc62dbce-f820-11eb-168f-670217a987d9
begin
import Pkg
import Distributions
@dermesser
dermesser / simplegrad.jl
Last active August 22, 2021 15:12
Simple numeric gradients
# Author: Lewin Bormann, 2021
# A simple finite difference algorithm for differentiating a function numerically with respect to multiple dimensions.
function mydiff(func, theta, releps=1e-3, reltol=1e-3)
scale_eps = 1/2
grad = zeros(size(theta))
upper, lower = theta[:], theta[:]
for (i, t) in enumerate(theta)
count = 0
flipflop = 0
@dermesser
dermesser / GPR.jl
Last active July 18, 2021 19:21
Julia version of the very excellent introduction to gaussian process regression at https://peterroelants.github.io/posts/gaussian-process-tutorial/
### A Pluto.jl notebook ###
# v0.14.7
using Markdown
using InteractiveUtils
# ╔═╡ 8560c782-e7f0-11eb-1b79-21d0c85978db
begin
import CairoMakie as CM
import LinearAlgebra
@dermesser
dermesser / bioassay_metropolis.jl
Created June 17, 2021 11:51
Replication of PyMC3's simple introduction example in Julia, for the purpose of my understanding
### A Pluto.jl notebook ###
# v0.14.7
using Markdown
using InteractiveUtils
# ╔═╡ 8ce57352-cf5b-11eb-2624-976564fd9572
using Plots
# ╔═╡ 22e5afa5-03a5-4c6c-9744-7417f1176839
@dermesser
dermesser / metropolishastings.jl
Last active June 30, 2021 15:38
Very very simple implementation of multi-dimensional Metropolis-Hastings algorithm
### A Pluto.jl notebook ###
# v0.14.7
using Markdown
using InteractiveUtils
# ╔═╡ 4f4ffc64-cdf9-11eb-32ef-e5e79401898e
using Random
# ╔═╡ fdc3d3af-f680-41b0-903e-779be1b24206
@dermesser
dermesser / kirchhoff.jl
Last active May 23, 2021 11:53
Calculate Kirchhoff-Fresnel diffraction integrals with visualization. Explanation: https://lewinb.net/posts/diffraction/ - example: http://borgac.net/~lbo/doc/kirchhoff.pdf
### A Pluto.jl notebook ###
# v0.14.3
using Markdown
using InteractiveUtils
# ╔═╡ 6d796395-5024-4129-a250-df2401327711
using Setfield
# ╔═╡ 87c80fda-9eda-11eb-2ac5-b7b5006b19b7
@dermesser
dermesser / sinfit.jl
Created March 31, 2021 12:08
Quite accurately estimate the four wave parameters for a (co)sine wave, using some simple statistics and FFT.
using DataFrames
import FFTW
import Statistics
"""
estimate_wave_params(df::DataFrame, xsym::Symbol, ysym::Symbol)
Use Fourier analysis and statistics to find the best monochromatic sine wave parameters for data.
`xsym` and `ysym` are the column symbols for the x and y columns within DataFrame `df`, respectively.