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 / mnist_autoencoder.jl
Created February 26, 2022 12:50
MNIST autoencoder network with ~251k weights in Flux.jl, running on CPU and GPU.
using MKL
using CUDA
import Flux
import MLDatasets
import Images
import BSON: @load,@save
import NNlib
using Dates
function logn(args...)
@dermesser
dermesser / lazyloader.jl
Last active February 26, 2022 12:51
LazyLoader: A Julia utility to lazily load images from disk for use in e.g. Flux for machine learning. Can be used as replacement for Flux.DataLoader if the dataset is too large for memory.
import Glob
import CUDA: CuArray
import Images
import Flux: gpu
import Flux
using Dates
function logn(args...)
println(now(), " ", args...)
@dermesser
dermesser / mst.ipynb
Created February 15, 2022 08:12
Three different implementations for minimum spanning trees in Gurobi
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dermesser
dermesser / manybody.jl
Last active January 7, 2022 19:30
Trivial n-body simulation.
using DifferentialEquations
using Plots
# Many-body, 2D.
const F = Float64
const D = 2
const G = 6.6743e-11 # m³/kg s²
@dermesser
dermesser / lattice2d.jl
Last active January 5, 2022 20:19
Simple 2D lattice dynamics calculation for a cubic structure with next-neighbor coupling only. Example: https://borgac.net/~lbo/asset/jl_62ec52.gif. Eigenmmodes: https://borgac.net/~lbo/asset/eigenmodes_5x5/
# (c) 2022 Lewin Bormann
# Full and updated code at https://borgac.net/lbo/hg/lattice2d/
using Plots
using DifferentialEquations
import LinearAlgebra
using SparseArrays
theme(:juno)
@dermesser
dermesser / linearchain.jl
Last active January 5, 2022 20:19
Solve a chain of harmonic oscillators using Julia's DifferentialEquations package. This is fairly easy using matrix calculations. Anharmonic terms in 3rd order can be included, too. Example (7 particles, first is displaced at t=0, anharmonic term: k/2 x^2 - 0.1 x^3): https://borgac.net/~lbo/asset/lc7.png
# (c) 2022 Lewin Bormann
# Have fun!
# Full and update code at https://borgac.net/lbo/hg/lattice2d/
import LinearAlgebra
using DifferentialEquations
using Plots
theme(:juno)
@dermesser
dermesser / paramagnet.pluto.jl
Created December 30, 2021 15:50
A simple paramagnetic annealing notebook.
### A Pluto.jl notebook ###
# v0.17.2
using Markdown
using InteractiveUtils
# ╔═╡ 8513f9b6-6973-11ec-35d7-cbf5183ebc84
begin
import Plots
using Random
@dermesser
dermesser / tsp_annealing.jl
Last active December 29, 2021 19:55
TSP Annealing: A simple tuneable implementation of solving Travelling Sales Person using Simulated Annealing, including a MIP program to check against the provably optimal version. Often a lot faster than a (naive) MIP implementation. Annealing process shown here: https://youtu.be/KhLE6YKeTqg
### A Pluto.jl notebook ###
# v0.17.2
using Markdown
using InteractiveUtils
# ╔═╡ 5c207166-67e2-11ec-192d-0debd3bc8e59
begin
import Plots
import JuMP
@dermesser
dermesser / lv.py
Last active December 23, 2021 10:06
Lotka-Volterra automatically differentiated using tensorflow.
import numpy as np
import tensorflow as tf
def LV(N1, N2, eps1, eps2, gam1, gam2):
dt = tf.constant(1.)
states = [(N1, N2)]
for i in range(1, 13):
states.append((states[i-1][0] + (states[i-1][0] * (eps1-gam1*states[i-1][1])) * dt, states[i-1][1] - states[i-1][1] * (eps2-gam2*states[i-1][0])) * dt)
return states[-1]
@dermesser
dermesser / miniautodiff.py
Last active December 22, 2021 17:28
A very simple reverse-mode automatic differentiation in Python for demo purposes.
import numpy as np
class Expression:
def __init__(self, left, right):
self.l = left
self.r = right
self.eval_l = None
self.eval_r = None