In [1]:
import numpy as np
from sklearn.preprocessing import normalize
In [57]:
z = np.zeros((3,3))
z
Out[57]:
In [75]:
ndone = np.array([[1,1,1], [2,2,2], [3,3,3]])
np.concatenate((z, ndone), axis=1)
Out[75]:
In [21]:
y = np.append(z, 1)
print(y, z)
In [42]:
a = np.array([2, 3, 2])
b = np.array([6, 6, 6])
In [47]:
def test1():
error_matrix = [a[i] * (1 - a[i]) * (b[i] - a[i]) for i, neuron in enumerate(a)]
%timeit test1()
In [48]:
def test2():
temp_matrix = np.multiply(a, 1 - a)
error_matrix2 = np.multiply(temp_matrix, b - a)
return error_matrix2
%timeit test2()
error_matrix2
Out[48]:
In [63]:
neurons = [[6,7], [6,9], [10,3]]
neurons = np.array(neurons)
temps = [[1,2,3],[3,4,5]]
la_neurons = [np.array(x) for x in temps]
la_error_matrix = error_matrix2[0:2]
def bptest():
error_matrix3 = []
for i, neuron in enumerate(neurons):
temp_err = 0
for j, la_neuron in enumerate(la_neurons):
temp_err += la_neurons[j][i] * la_error_matrix[j]
error_matrix3.append(a[i] * (1 - a[i]) * temp_err)
return error_matrix3
%timeit bptest()
error_matrix3 = bptest()
print(error_matrix3)
In [69]:
lans = np.column_stack(la_neurons)
lans
Out[69]:
In [76]:
error_matrix4 = []
la_error_matrix = np.array(error_matrix[0:2])
def bptest2():
lans = np.column_stack(la_neurons)
temp = np.dot(lans, la_error_matrix)
error_matrix4 = np.multiply(temp, np.multiply(a, 1 - a))
return error_matrix4
%timeit bptest2()
print(bptest2())
In [4]:
b = np.array([18., 32., 3., 61., -8., -1000., 2., 100.])
c = normalize(b)
c
Out[4]: