It is a pure python library for numerical computations.
Linear algebra example:
A = Matrix([[1,2],[4,9]])
print 1/A
print (A+2)*A
B = Matrix(2,2,lambda i,j: i+j**2)
Fitting
points = [(x0,y0,dy0), (x1,y1,dy1), (x2,y2,dy2), ...]
coefficients, chi2, fitting_function = fit_least_squares(points,POLYNOMIAL(2))
for x,y,dy in points:
print x, y, '~', fitting_function(x)
Solvers:
from math import sin
def f(x): return sin(x)-1+x
x0 = solve_newton(f, 0.0, ap=0.01, rp=0.01, ns=100)
print 'f(%s)=%s ~ 0' % (x0, f(x0))
(ap is target absolute precision, rp is target relative precision, ns is max number of steps)
Optimizers:
def f(x): return (sin(x)-1+x)**2
x0 = optimize_newton(f, 0.0, ap=0.01, rp=0.01, ns=100)
print 'f(%s)=%s ~ min f' % (x0, f(x0))
print 'f'(%s)=%s ~ 0' % (x0, D(f)(x0))
Statistics:
x = [random.random() for k in range(100)]
print 'mu =', mean(x)
print 'sigma =', sd(x)
print 'E[x] =', E(lambda x:x, x)
print 'E[x^2] =', E(lambda x:x2, x)
print 'E[x^3] =', E(lambda x:x3, x)
y = [random.random() for k in range(100)]
print 'corr(x,y) = ', correlation(x,y)
print 'cov(x,y) = ', covariance(x,y)
Finance:
google = YStock('GOOG')
current = google.current()
print current['price']
print current['market_cap']
for day in google.historical():
print day['date'], day['adjusted_close'], day['log_return']
Persistant Storage:
d = PersistentDictionary(path='test.sqlite')
d['key'] = 'value'
print d['key']
del d['key']
d works like a drop-in preplacement for any normal Python dictionary except that the data is stored in a sqlite database in a file called "test.sqlite" so it is still there if you re-start the program. Kind of like the shelve module but shelve files cannot safely be accessed by multiple threads/processes unless locked and locking the entire file is not efficient.
Neural Network:
pat = [[[0,0], [0]], [[0,1], [1]], [[1,0], [1]], [[1,1], [0]]]
n = NeuralNetwork(2, 2, 1)
n.train(pat)
n.test(pat)
[0, 0] -> [0.00...]
[0, 1] -> [0.98...]
[1, 0] -> [0.98...]
[1, 1] -> [-0.00...]
Plotting:
data = [(x0,y0), ...]
Canvas(title='my plot').plot(data, color='red').save('myplot.png')