Skip to content

Instantly share code, notes, and snippets.

View john-bradshaw's full-sized avatar

John Bradshaw john-bradshaw

View GitHub Profile
@john-bradshaw
john-bradshaw / flax_mem_leak.py
Created August 12, 2022 17:11
Showing how flax's nn.compact if used incorrectly can cause memory leaks.
"""
Simple demonstration of memory leak.
XLA_PYTHON_CLIENT_PREALLOCATE=false CUDA_VISIBLE_DEVICES=0 python flax_mem_leak.py
Breaks on last iter through loop.
# Tested on version:
Name: flax
Version: 0.4.1
Summary: Flax: A neural network library for JAX designed for flexibility
@john-bradshaw
john-bradshaw / different_smiles_same_fp.ipynb
Last active April 28, 2022 00:26
Notebook showing how different SMILES can sometimes have the same fingerprint
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@john-bradshaw
john-bradshaw / split_reagents.py
Last active March 11, 2022 20:44
Code to split up reactants and reagents (currently untested, WIP)
"""
Module for identifying for RDKit functions working with reaction SMILES strings.
"""
import collections
import itertools
import functools
import typing
@john-bradshaw
john-bradshaw / tf_control_dep_demo2.py
Created April 18, 2018 14:35
Demo on using control dependencies version 2.
import tensorflow as tf
def main1():
sess = tf.Session()
x = tf.Variable(1.)
sess.run(tf.initialize_variables([x]))
@john-bradshaw
john-bradshaw / tf_control_dep_demo.py
Created April 18, 2018 14:20
Tensorflow Control Dependencies. Resouce Variables versus normal variables.
import numpy as np
import tensorflow as tf
def main1():
x = tf.get_variable("x", initializer=np.float64(0))
x_id = tf.identity(x)
x_rd = x.read_value()
x_p0 = x + 0
with tf.control_dependencies([x_id, x_rd, x_p0]):
@john-bradshaw
john-bradshaw / gpdnns.py
Last active February 5, 2024 21:04
GPDNN example on MNIST GPflow git commit f42fc3ea33ec3a8c37a45d3ccdd41e60bed5690e (unchecked accuracy results but seems to run okay)
import os
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data as mnist_input_data
import numpy as np
from sklearn import cluster
from scipy.spatial import distance
import pandas as pd
@john-bradshaw
john-bradshaw / bayesian_optimisation_simple_demo.py
Created November 15, 2017 18:49
Simple example to run Bayesian Optimisation GPs. Works with Python3, TF1.4, python-fire, GPflow git commit 4ff00cbbc83efff8cb537f16a7eb1c1e11de3a75
import enum
import numpy as np
from scipy import stats
import fire
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.widgets import Button
@john-bradshaw
john-bradshaw / mnist_gpdnn_example.py
Created November 7, 2017 14:16
Shows how to combine NN with GP for end to end training. run with TF 1.4, GPflow git commit f618fe4d9aa096b32a3d24576d68f46a3f260116
import os
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data as mnist_input_data
import numpy as np
from sklearn import cluster
from scipy.spatial import distance
import pandas as pd
@john-bradshaw
john-bradshaw / mixture_of_gaussians_morphing.py
Last active October 17, 2017 21:49
Mixture of Gaussians variational morphing similar to Fig 1c of Saul, L.K. and Jordan, M.I., 1997
"""
Code for Figure 1c of
Saul, L.K. and Jordan, M.I., 1997. A variational principle for model-based morphing.
In Advances in Neural Information Processing Systems (pp. 267-273).
Note not exactly the same setup and do not know settings of ell and variance to use
Also not sure how to deal with the change points
Written in a bit of a rush and not thoroughly tested so use with caution
"""
@john-bradshaw
john-bradshaw / gaussian_morphing.py
Last active October 15, 2017 16:13
Model Based Morphing for a Two dimensional Gaussian (reproduction of Saul, L.K. and Jordan, M.I., 1997 Fig 1a)
"""
Code for Figure 1a of
Saul, L.K. and Jordan, M.I., 1997. A variational principle for model-based morphing.
In Advances in Neural Information Processing Systems (pp. 267-273).
"""
import numpy as np
from scipy.integrate import odeint
from scipy.optimize import fsolve
from scipy import stats