Skip to content

Instantly share code, notes, and snippets.

Avatar

Gavin Gray gngdb

View GitHub Profile
View example_usage.py
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import numpy as np
from scipy import optimize
from obj import PyTorchObjective
@gngdb
gngdb / tf-autograd.py
Last active Jun 19, 2020
How to use autograd inside Tensorflow
View tf-autograd.py
import tensorflow as tf
import autograd.numpy as np
from autograd import grad
from tensorflow.python.framework import function
rng = np.random.RandomState(42)
x_np = rng.randn(4,4).astype(np.float32)
with tf.device('/cpu:0'):
x = tf.Variable(x_np)
@gngdb
gngdb / Soap Bubble Effect.ipynb
Created Jun 4, 2020
Soap bubble effect simulation
View Soap Bubble Effect.ipynb
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 Jun 3, 2020
Testing random seed setting in different threads
View sample_output
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 / concrete.ipynb
Last active May 15, 2020
Notes on concrete distributions
View concrete.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / thesis-planning.py
Last active May 7, 2020
Brute Force Ancestral Monte Carlo I used for project planning when writing my PhD thesis
View thesis-planning.py
# 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 Apr 29, 2020
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.
View Iterated Indexing.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gngdb
gngdb / Least Squares in PyTorch.ipynb
Last active Apr 27, 2020
Least Squares in PyTorch
View Least Squares in PyTorch.ipynb
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 Apr 9, 2020
Pure Python Gumbel Dice
View d12.py
import dice
print(dice.roll(12))
@gngdb
gngdb / show.py
Last active Feb 11, 2020
Display Images from arrays and tensors in Python 3 (based on https://github.com/google/deepdream/blob/master/dream.ipynb)
View show.py
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)
You can’t perform that action at this time.