Skip to content

Instantly share code, notes, and snippets.

View popcornell's full-sized avatar
:octocat:

Samuele Cornell popcornell

:octocat:
  • Carnegie Mellon University
  • Pittsburgh
View GitHub Profile
@popcornell
popcornell / gf2elim.py
Last active May 16, 2023 05:20
Gaussian elimination for binary matrices ( all elements in GF(2) ) implemented in numba python and numpy for efficiency.
import numpy as np
import numba
@numba.jit(nopython=True, parallel=True) #parallel speeds up computation only over very large matrices
# M is a mxn matrix binary matrix
# all elements in M should be uint8
def gf2elim(M):
m,n = M.shape
@popcornell
popcornell / tf_p_inv.py
Created April 28, 2018 10:10
Moore-Penrose Pseudo-Inverse in TensorFlow
import tensorflow as tf
def p_inv(matrix):
"""Returns the Moore-Penrose pseudo-inverse"""
s, u, v = tf.svd(matrix)
threshold = tf.reduce_max(s) * 1e-5
@popcornell
popcornell / tfZCA.py
Last active December 31, 2018 14:31
A class which implements ZCA whitening aka Mahalanobis transformation in TensorFlow.
import tensorflow as tf
from keras.datasets import mnist
import numpy as np
tf.enable_eager_execution()
assert tf.executing_eagerly()