Skip to content

Instantly share code, notes, and snippets.

View tsbertalan's full-sized avatar

Tom Bertalan tsbertalan

  • University of Massachusetts Lowell
  • United States
View GitHub Profile
@tsbertalan
tsbertalan / bpnn.py
Created August 7, 2012 18:30 — forked from raphaelsaunier/bnpnn.py
Back-Propagation Neural Networks by Neil Schemenauer <nas@arctrix.com>
# Back-Propagation Neural Networks
#
# Written in Python. See http://www.python.org/
# Placed in the public domain.
# Neil Schemenauer <nas@arctrix.com>
#
# Changes:
# 2009-01-30 Fix dsigmoid() to use correct derivative rather than an
# approximation. Suggested by Andrew Lionel Blais.
@tsbertalan
tsbertalan / reuben.sh
Created August 19, 2012 18:42
A parameterized song!
#!/bin/sh
echo ""
echo "Reuben, Reuben, I've been thinkin,"
echo "what a fine world it would be,"
echo "if all the $1 were just transported"
echo "all across the northern sea."
echo ""
@tsbertalan
tsbertalan / cosbifier.py
Created September 8, 2012 14:10
Change your name (or any string) to Bill Cosby speak!
#!/usr/bin/python
#http://cheezburger.com/4925161216
parts = {
'a': 'Hip', 'b': 'Dip', 'c': 'Squoo', 'd': 'Bada', 'e': 'Meep',
'f': 'Bloo', 'g': 'Caw', 'h': 'Squee', 'i': 'Woobly', 'j': 'Badum',
'k': 'Loo', 'l': 'Derp', 'm': 'Nerp', 'n': 'Spee', 'o': 'Papa',
'p': 'Moom', 'q': 'Dub', 'r': 'Pa', 's': 'Naw', 't': 'Ka',
'u': 'Mim', 'v': 'Zap', 'w': 'Nup', 'x': 'Na', 'y': 'Yee',
'z': 'Zoop', ' ': ' '
}
@tsbertalan
tsbertalan / graph_hw1.py
Created September 27, 2012 14:15
Make graphs from the output of APC 524's HW1. Be sure to suitable edit the filename and authorname variables near the top.
import csv
import matplotlib.pyplot as plt
def import_text(filename, separator):
for line in csv.reader(open(filename), delimiter=separator, skipinitialspace=True):
if line:
yield line
results = []
t = []
x = []
@tsbertalan
tsbertalan / hw1.m
Created October 1, 2012 05:09
CBE 504 HW1
N = 10;
k = 1;
P0 = [zeros([N, 1]) ; 1];
A = irreversible(N);
f = @(t,P)mastereqn(P,A);
[tvec,P]=ode45(f, [0,25], P0);
tvecsize = size(tvec);
num_timesteps = tvecsize(1);
% % Uncomment to check probability sums:
@tsbertalan
tsbertalan / birthdeath.m
Created October 8, 2012 09:27
CBE 504 HW2
function [nlist, tlist] = birthdeath(l,K,numsteps)
nlist =[0]; % list of numbers of transcripts at corresponding place in t
tlist =[0]; % list of times. drawn from bernoulli distribution.
evlist=[0]; % list of events. degradation is -1, transcription is 1,neither is 0.
t = 0;
n = 0;
ev = 1;
for j=[1:numsteps]
t = t - log(1-rand(1))/(K*n+l);
tlist = [tlist t];
@tsbertalan
tsbertalan / hw3.py
Created October 17, 2012 04:55
CBE 502 HW3
def n232nondiscriminant(a,b):
return(b-a**2-1)
def n232discriminant(a,b):
return((a**2-b+1)**2 - 4*a**2)
if __name__ == "__main__":
stable_real_a = []
stable_real_b = []
unstable_real_a = []
@tsbertalan
tsbertalan / chumhandle.py
Created November 1, 2012 05:30
Generate a random chumhandle!
#!/usr/bin/env python
#with open('/home/tsbertalan/bin/wordlists/nounsb.txt') as f:
with open('/home/tsbertalan/bin/wordlists/nouns/91K nouns.txt') as f:
nouns = f.read().splitlines()
#with open('/home/tsbertalan/bin/wordlists/adjectivesb.txt') as f:
with open('/home/tsbertalan/bin/wordlists/adjectives/28K adjectives.txt') as f:
adjs = f.read().splitlines()
nouns = list(set(nouns))
adjs = list(set(adjs))
from random import choice
@tsbertalan
tsbertalan / hw4.py
Created November 6, 2012 15:41
CBE 502 HW4
from math import exp, cos, sin
def print_answers(fs, fnames, W, tx=4.0):
for (name, f) in zip(fnames, fs):
print name+'(', tx, '):', f(tx)
print " W(", tx, "):", W(tx)
def n32b():
f1 = lambda t: exp(float(t)) * (3.0 / 4.0 - t / 2) - exp(-1.0 * t) / 4
f1p = lambda t: exp(float(t))*(1./4-t/2)+exp(-t)/4
@tsbertalan
tsbertalan / beat.py
Created November 25, 2012 06:35
Graphical demonstration of beat frequency as heard when tuning a violin
# Really, when tuning, you have a reference note a fifth above or below the
# target note. But, just to show a beat-frequency effect, having the reference
# and target notes be about the same frequency is fine.
import numpy as np
import matplotlib.pylab as plt
length = 444 # make this larger if the waves shown are not very wave-like
resolution = 10000.0
xl = list(np.arange(1, length, length / resolution))
w1 = 1.0