Instantly share code, notes, and snippets.

• Sort options
Last active Aug 4, 2020
Wrap PyTorch functions for scipy's optimize.minimize: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html
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
Last active Jun 19, 2020
How to use autograd inside Tensorflow
 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)
Created Jun 4, 2020
Soap bubble effect simulation
View Soap Bubble Effect.ipynb Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Last active May 15, 2020
Notes on concrete distributions
View concrete.ipynb Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
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, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Last active Apr 27, 2020
Least Squares in PyTorch
View Least Squares in PyTorch.ipynb 