Numpy Pure Functions for performance, caching
I'm writing some moderately performance critical code in numpy. This code will be in the inner most loop, of a computation that's run time is measured in hours. A quick calculation suggest that this code will be executed up something like 10^12 times, in some variations of the calculation. So the function is to calculate sigmoid(X) and another to calculate its derivative (gradient). Sigmoid has the property that for y=sigmoid(x), dy/dx= y(1-y) In python for numpy this looks like: sigmoid = vectorize(lambda(x): 1.0/(1.0+exp(-x))) grad_sigmoid = vectorize(lambda (x): sigmoid(x)*(1-sigmoid(x)))