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 / hussieHist.py
Last active December 16, 2015 17:59
Visualization of Andrew Hussie's output. The man is a fiend. See plot outputs at http://www.tombertalan.com/entries/single/102
import time
from datetime import datetime
import matplotlib.pyplot as plt
#get the csv lines as strings
lines = list(open('hussieout.csv'))
lines = lines[:-1] #remove final newline
#split each line on commas (hopefully there's only one per line)
lines = [line.split(',') for line in lines]
#remove whitespace at the ends of the elements (mostly--only?--just \n characters at the ends)
@tsbertalan
tsbertalan / randomInjection.py
Created April 18, 2013 14:50
diffusion with random source/sink injections ∂ θ(x, t) / ∂ t = ∇ 2 θ(x, t) + S(x,t)
from matplotlib import pyplot as plt
from matplotlib import colors
import numpy as np
from tomIntegrate import randr
from time import sleep
NX = NY = 64
figsize=(16, 16)
ptake = 0.001
pgive = 0.0004
# -*- coding: utf-8 -*-
from tomIntegrate import intor, randr
from matplotlib import pyplot as plt
from numpy import array, polyfit, log, exp
def dxdt(X, r=28.):
s = 10.
b = 8. / 3.
x = X[0]
y = X[1]
@tsbertalan
tsbertalan / .gitignore
Last active December 10, 2015 00:09
How to return a double * from swig as a Python list? Use a std::vector instead.
returnList.py
_returnList.so
*_wrap.cxx
@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
@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 / 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 / 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 / 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 / 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: