Skip to content

Instantly share code, notes, and snippets.

@dean-shaff
dean-shaff / christoffel.py
Last active August 29, 2015 14:21
GR_stuff
import sympy as sym
x1, x2 = sym.symbols("x1 x2")
coord = [x1, x2]
g = sym.Matrix([[1,0],[0,x1**2]])
ginv = g.inv()
def christoffel(coord, g, ginv, index1, index2, index3):
"""
coord is the list of coordinates, eg coord = [r, theta, phi]
@dean-shaff
dean-shaff / feedforward.py
Last active August 29, 2015 14:28
feedforward step for neural net
def feed_forward(self,x):
"""
Calculate the value(s) of the neural net at the output level.
"""
y_guess = self.act(T.dot(x,self.W[0])+ self.b[0])
for i in xrange(1,len(self.W)):
W = self.W[i]
b = self.b[i]
if i == len(self.W)-1:
y_guess = T.nnet.softmax(T.dot(y_guess,W)+b)
void loop() {
randNumber1 = random(0,100);
randNumber2 = random(0,100);
int bigger;
if (randNumber1 > randNumber2){
bigger = 1;
}else{
bigger = 0;
}
while (digitalRead(pin_in1) == HIGH){
@dean-shaff
dean-shaff / live_plot_arduino.py
Created September 21, 2015 03:33
gravity snake game using arduino pressure sensor
"""
Took the main functionality of this code from https://www.lebsanft.org/?p=48
"""
import serial
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import numpy as np
import time
import sys
@dean-shaff
dean-shaff / random_squares.pde
Created October 25, 2015 16:35
Random Squares computer art, originally by Bill Kolomyjec
/*
Random Squares, originally by Bill Kolomyjec
*/
int max_sqrs = 9 ;
int large_sqr_dim = 7;
int sqr_dim ; //= width / 7 ;
int init_sqr_dim ; // = sqr_dim / 5 ;
boolean zero_sqr = false;
@dean-shaff
dean-shaff / MLP_torch_dean.lua
Last active March 14, 2016 12:53
Building and training a simple MLP in torch
-- building the MLP
net = nn.Sequential()
net:add(nn.Linear(150,400))
net:add(nn.Linear(400,300))
net:add(nn.Linear(300,200))
net:add(nn.Tanh()) -- tanh squashing function
net:add(nn.Linear(200,2))
net:add(nn.LogSoftMax())
-- Training the net
from PyQt4 import QtCore, QtGui
from mainui import MainUI
import time
from hardware_controller import Hardware_Controller
class Worker(QtCore.QThread):
update_text_signal = QtCore.pyqtSignal(str) #have to pass the type str
def __init__(self, hdwr_ctrl, update_rate):
function Array2D(...)
local args = {...}
if #args == 0 then
args = {{{}}}
end
local array2d = {
__index = self,
vals = args[1],
shape = {#args[1], #args[1][1]},
@dean-shaff
dean-shaff / theano_numpy_diffeq.py
Created September 3, 2016 20:45
Theano and Numpy speed comparison for Lorenz Attractor
import theano
import theano.tensor as T
import numpy as np
import h5py
import os
import time
def rungekuttastep(h,y,fprime,*args):
k1 = h*fprime(y,*args)
import time
import pdb
import numpy as np
import theano
import theano.tensor as T
import h5py
class LSTMLayer(object):