Skip to content

Instantly share code, notes, and snippets.

View justanotherminh's full-sized avatar
🙉

Luong-Minh Nguyen justanotherminh

🙉
  • Microsoft
  • North Carolina
View GitHub Profile
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
def softmax(logits):
e = np.exp(logits)
return e / np.expand_dims(e.sum(axis=1), axis=1)
import time
inv = 0
def mergesort(arr):
global inv
if len(arr) <= 1:
return arr
else:
counts = 0
def quicksort(arr):
global counts
if len(arr) >= 1:
counts += len(arr)-1
if len(arr) <= 1:
return arr
else:
import time
import random
import copy
# j4f
def runtime(func, args):
now = time.time()
func(args)
return time.time() - now
import time
from collections import deque
import sys
sys.setrecursionlimit(10000)
class Node(object):
def __init__(self, name):
self.name = name
self.explored = False
@justanotherminh
justanotherminh / rbm.py
Created February 21, 2017 13:34
Restricted Boltzmann Machine for the MNIST dataset implemented in pure NumPy
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
def sample_vector(v, w, b, bernoulli=True):
h = 1 / (1 + np.exp(-(v.dot(w) + b)))
if bernoulli:
h = np.random.binomial(1, h)
return h
# Sometimes it works, sometimes it doesn't
import numpy as np
import gym
class Net(object):
def __init__(self, input, output):
# W = 0.01 * np.random.randn(input, output)
# b = np.zeros([1, output]) # Random initialization
W = np.array([[-0.60944746, 0.45539405],
@justanotherminh
justanotherminh / layers.py
Last active September 1, 2018 23:40
Simple 2-layer feedforward neural networ from scratch with brand new SELU activation
import numpy as np
def sigmoid(v):
return 1 / (1 + np.exp(-v))
def one_hot(x):
N = x.size
D = x.max() + 1
@justanotherminh
justanotherminh / repository.json
Last active January 16, 2018 05:17
Needed for headless TX2 setup
{
"package": {
"version": "3.1",
"division": [
{
"alias": "tx2_64bit",
"selected": "1",
"name": "Jetson TX2"
},
{
from fractions import Fraction
import numpy as np
def print_matrix(matrix):
def tostr(i):
return str(i) if i.denominator == 1 else '{}\\{}'.format(i.numerator, i.denominator)
print '\n'.join(['\t'.join([tostr(col) for col in row]) for row in matrix])