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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / EM.jl
Created March 13, 2022 08:04
Expectation Maximization comboined with k-means clustering for reconstructing 2D Normal distributions including visualization
### A Pluto.jl notebook ###
# v0.18.1
using Markdown
using InteractiveUtils
# ╔═╡ a49da1ae-3f4a-11ec-1504-eb883d8604e2
begin
import Plots
using Distributions
@dermesser
dermesser / textgen.jl
Last active March 15, 2022 13:41
Generate random text using an LSTM network in Flux/Julia.
using MKL
using CUDA
import Flux
import Plots
import BSON
import Zygote # for BSON
import Dates: now
import Random
import Distributions as D