Skip to content

Instantly share code, notes, and snippets.

View rbrigden's full-sized avatar

Ryan Brigden rbrigden

  • @inokyo
  • San Francisco, CA
View GitHub Profile
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
class MLP(nn.Module):
def __init__(self, input_size, feature_categories):
super(MLP, self).__init__()
self.feature_categories = feature_categories
@rbrigden
rbrigden / weight_ops.py
Created June 20, 2018 02:31
Apply torch functions to weight parameters
import torch
import torch.nn as nn
from torch.autograd import Variable
affine = nn.Linear(10, 10)
# A linear mapping to a random vector... just for quick demo purposes
x = Variable(torch.randn(100, 10))
y = Variable(torch.randn(100, 10))
weird_loss = torch.mean(torch.exp(affine.weight))
@rbrigden
rbrigden / quiz13.py
Last active April 25, 2018 05:03
Template for solving question 4 for of quiz 13
import numpy as np
import copy
# NOTE: a = 1 is a(-), a = 0 is a(+)
gamma = 0.9
action_space = 2
state_space = 4
eps = 1e-9
# Action conditioned reward function
@rbrigden
rbrigden / wsj_loader.py
Last active March 9, 2020 01:32
Load the WSJ speech dataset
import numpy as np
import os
class WSJ():
""" Load the WSJ speech dataset
Ensure WSJ_PATH is path to directory containing
all data files (.npy) provided on Kaggle.
Example usage:
@rbrigden
rbrigden / setup_vim_ubuntu.sh
Created December 20, 2017 22:42
setup vim on ubuntu with my configs
#!/bin/bash
cd ~
apt-get install git
# setup dotfiles
rm -rf .vim*
git clone https://github.com/rbrigden/dotfiles.git .dotfiles
ln -s .dotfiles/.vimrc .vimrc
@rbrigden
rbrigden / ten_armed_bandit.py
Created August 8, 2017 04:27
Ten Armed Bandit
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import random
class TenArmedBandit(object):
def __init__(self):
self.action_space = 10
self.q_true = np.random.randn(self.action_space)
@rbrigden
rbrigden / autoencoder.py
Last active July 7, 2017 23:09
autoencoder
from __future__ import division, print_function, absolute_import
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
# Import MNIST data
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data", one_hot=False)

HW0 of 11-364

Objective

The original assignment set forth instructed students to implement a feedforward artificial neural network (ANN) in a relatively low level language or framework. Although higher level scripting languages such as Python and Lua have wrapped heavily optimized libraries that perform the same functions, the goal of this assignment is to truly understand the theoretical underpinnings of feedforward neural networks by writing the routines from scratch (almost).

#!/bin/python
# author: Ryan Brigden
# The "brute" in brute force
# Question: Given a (large) list of words and a list of top-level domains (TLDs)
# from the Internet Assigned Numbers Authority (IANA), such as ".com" and ".net",
# find all of the possible "singleton" domains that can be registered with words
# from the word list. A singleton domain is defined as a sensical word (ie from
# the word list) whose suffix is a legitimate TLD (ie from the TLD list). You are
# given a function (is_available) that checks whether a given domain name is
abdominocardiac abdominocardi.ac
autotractor autotr.actor
cephalotractor cephalotr.actor
cocontractor cocontr.actor
coenactor coen.actor
cornfactor cornf.actor
counteractor counter.actor
effractor effr.actor
idemfactor idemf.actor
lithofractor lithofr.actor