Я делаю прямую связь с нейронной сетью, и я не уверен, почему она не работает: вот код:
import numpy as np
import random
#Hyperparameters
num_iterations = 100000
errors_shown = 1
num_iterations_per_error = num_iterations // errors_shown
learning_rate = 0.01
def nonlin(x, deriv=False):
if deriv == True:
return x * (1 - x)
else:
return 1 / (1 + np.exp(-x))
#Input Data
x = np.array([[9, 2],
[7, 0],
[3, 1],
[5, 0.5],
[5, 0],
[5.6, 0.7],
[10, 0.5],
[9, 0.5],
[8, 3.7],
[3, 0.5],
[4, 2],
[4, 2.5],
[9, 2.5],
[10, 0],
[5, 1],
[8, 3],
[7, 1.7],
[9, 0],
[3, 3]])
#Output Data
y = np.array([[0.87],
[0.12],
[0.09],
[0.12],
[0.13],
[0.47],
[0.39],
[0.36],
[0.97],
[0.19],
[0.23],
[0.67],
[0.94],
[0.33],
[0.57],
[0.91],
[0.73],
[0.63],
[0.32]])
np.random.seed(1)
#Random synapses
syn0 = np.random.random((2, 3))
syn1 = np.random.random((3, 4))
syn2 = np.random.random((4, 3))
syn3 = np.random.random((3, 2))
syn4 = np.random.random((2, 1))
syns = [syn0, syn1, syn2, syn3, syn4]
#Random bias'
b0 = np.random.random((1, 3))
b1 = np.random.random((1, 4))
b2 = np.random.random((1, 3))
b3 = np.random.random((1, 2))
b4 = np.random.random((1, 1))
bias = [b0, b1, b2, b3, b4]
#Neural Network
class NN:
def __init__(self, input_data, expected_output_data, num_iterations, num_iterations_per_error, learning_rate, syns, bias):
self.input_data = input_data
self.expected_output_data = expected_output_data
self.num_iterations = num_iterations
self.num_iterations_per_error = num_iterations_per_error
self.learning_rate = learning_rate
self.syn0 = syns[0]
self.syn1 = syns[1]
self.syn2 = syns[2]
self.syn3 = syns[3]
self.syn4 = syns[4]
self.b0 = bias[0]
self.b1 = bias[1]
self.b2 = bias[2]
self.b3 = bias[3]
self.b4 = bias[4]
#predict
def pred(self):
self.l0 = self.input_data
self.l1 = nonlin(np.dot(self.l0, self.syn0) + self.b0)
self.l2 = nonlin(np.dot(self.l1, self.syn1) + self.b1)
self.l3 = nonlin(np.dot(self.l2, self.syn2) + self.b2)
self.l4 = nonlin(np.dot(self.l3, self.syn3) + self.b3)
self.z = (np.dot(self.l4, self.syn4) + self.b4)
self.pred = nonlin(self.z)
return self.pred
#Cost func
def cost_func(self):
self.l4_error = np.square(self.l4 - self.expected_output_data)
self.l4_delta = self.l4_error * nonlin(self.l4, deriv=True)
self.l3_error = self.l4_delta.dot(self.syn3.T)
self.l3_delta = self.l3_error * nonlin(self.l3, deriv=True)
self.l2_error = self.l3_delta.dot(self.syn2.T)
self.l2_delta = self.l2_error * nonlin(self.l2, deriv=True)
self.l1_error = self.l2_delta.dot(self.syn1.T)
self.l1_delta = self.l1_error * nonlin(self.l1, deriv=True)
self.total_error += self.l4_error
return self.l4_error
#Backprop
def backprop(self):
self.syn3 += self.l3.T.dot(self.l4_delta * self.learning_rate)
self.syn2 += self.l2.T.dot(self.l3_delta * self.learning_rate)
self.syn1 += self.l1.T.dot(self.l2_delta * self.learning_rate)
self.syn0 += self.l0.T.dot(self.l1_delta * self.learning_rate)
def runner(self):
self.total_error = 0
for iteration in range(self.num_iterations):
pred = self.pred()
cost = self.cost_func()
self.backprop()
neuralNet = NN(x, y, num_iterations, num_iterations_per_error, learning_rate, syns, bias)
neuralNet.runner()
, поэтому я не знаю, что с ним не так, пожалуйста, не могли бы выПомоги мне?это ошибка:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-55-e63563ac83ed> in <module>
72 neuralNet = NN(x, y, num_iterations, num_iterations_per_error, learning_rate, syns, bias)
73
---> 74 neuralNet.runner()
<ipython-input-55-e63563ac83ed> in runner(self)
66
67 for iteration in range(self.num_iterations):
---> 68 pred = self.pred()
69 cost = self.cost_func()
70 self.backprop()
TypeError: 'numpy.ndarray' object is not callable
Пожалуйста, просто опубликуйте свои ответы ниже, внизу, в объявлении, так что да, пожалуйста, помогите, и это просто глубокая прямая нейронная сеть