In [1]:
import numpy as np
from scipy.special import expit
from operator import add
In [10]:
x = np.random.random((8,3))
In [ ]:
sigmoid = lambda x: 1.0/(1.0+np.exp(-x))
In [ ]:
%timeit y = sigmoid(x)
In [ ]:
%timeit y = expit(x)
In [ ]:
x
In [11]:
%timeit x.flatten()
In [5]:
error = .235
vector = np.asarray([1,2,3,4,5,6,7])
weights = np.asarray([1,2,3,4,5,6,7])
def loop(error, weights, vector):
l_rate = .1
correction = l_rate * error
for idx, item in enumerate(vector):
weights[idx] += (item * correction)
%timeit loop(error, weights, vector)
In [6]:
error = .235
vector = np.asarray([1,2,3,4,5,6,7])
weights = np.asarray([1,2,3,4,5,6,7])
def loop(error, weights, vector):
l_rate = .1
correction = l_rate * error
y = [x * correction for x in vector]
map(add, weights, y)
%timeit loop(error, weights, vector)
In [8]:
error = .235
vector = np.asarray([1,2,3,4,5,6,7])
weights = np.asarray([1,2,3,4,5,6,7])
def map_loop(error, weights, vector):
l_rate = .1
error = .235
correction = l_rate * error
corr_matrix = np.multiply(vector, correction)
weights = np.asarray(map(add, weights, corr_matrix))
%timeit map_loop(error, weights, vector)