Skip to content

Instantly share code, notes, and snippets.

@gngdb
gngdb / Basin Hopping.ipynb
Last active September 24, 2022 12:03
An example using scipy.optimize's basin hopping with torch calculating gradients
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This gist shows how to use rebase to change the Git history of a repo. Imagine you realise that the first commit to your repo should be different (maybe it's incomplete, includes something it shouldn't or simply could be cleaner). However, since then you and others have made many changes to the repo that you want to preserve. Here we show how to split the first commit into multiple and re-attach the remaining version history to these new commits.

Let's make a dummy git repo rebase-root and add two files to it. We commit them with the commit #1.

@gngdb
gngdb / Soap Bubble Effect.ipynb
Created June 4, 2020 19:53
Soap bubble effect simulation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / sample_output
Last active June 3, 2020 16:39
Testing random seed setting in different threads
Tuples sampled in parallel or sequentially are equal:
0.496, 0.549, 0.844 == 0.496, 0.549, 0.844
0.758, 0.417, 0.134 == 0.758, 0.417, 0.134
0.615, 0.436, 0.956 == 0.615, 0.436, 0.956
0.004, 0.551, 0.238 == 0.004, 0.551, 0.238
0.560, 0.967, 0.236 == 0.560, 0.967, 0.236
0.830, 0.222, 0.623 == 0.830, 0.222, 0.623
0.572, 0.893, 0.793 == 0.572, 0.893, 0.793
0.535, 0.076, 0.324 == 0.535, 0.076, 0.324
0.598, 0.873, 0.227 == 0.598, 0.873, 0.227
@gngdb
gngdb / thesis-planning.py
Last active May 7, 2020 16:42
Brute Force Ancestral Monte Carlo I used for project planning when writing my PhD thesis
# renders a MAP estimate of the PhD thesis timeline along with estimate of the
# 50%, 90% and 99% chance of thesis being complete
import numpy as np
import time
import datetime
from datetime import timedelta
def main():
# model the PhD as a sequence of events of random length.
@gngdb
gngdb / Iterated Indexing.ipynb
Last active April 29, 2020 19:32
I often come across the problem that I have an array of indexes I want to match to a elements along a dimension. It's solved by gather.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / d12.py
Created April 9, 2020 21:48
Pure Python Gumbel Dice
import dice
print(dice.roll(12))
@gngdb
gngdb / show.py
Last active February 11, 2020 16:10
Display Images from arrays and tensors in Python 3 (based on https://github.com/google/deepdream/blob/master/dream.ipynb)
from io import BytesIO
import PIL.Image
from IPython.display import clear_output, Image, display
def showarray(a, fmt='jpeg'):
a = a - a.min()
a = 255.*(a/a.max())
a = np.uint8(np.clip(a, 0, 255))
f = BytesIO()
PIL.Image.fromarray(a).save(f, fmt)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / Parameter Redundancy Through Time.ipynb
Last active October 17, 2019 20:05
Parameter redundancy from 5 pruning papers through time.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.