-
Notifications
You must be signed in to change notification settings - Fork 0
/
neural_network.py
29 lines (23 loc) · 929 Bytes
/
neural_network.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy as np
from neural_layer import NeuralLayer
class NeuralNetwork:
def __init__(self, shape, num_inputs,alpha):
self.num_inputs = num_inputs
self.num_layers = len(shape)
self.network = [NeuralLayer(num_inputs, shape[0])]
self.alpha = alpha
for layer in range(1, self.num_layers):
self.network.append(NeuralLayer(shape[layer-1], shape[layer]))
def feedForward(self, inputs):
for layer in range(self.num_layers):
self.network[layer].setPotentials(inputs)
inputs = self.network[layer].getActivations()
return inputs
def feedBack(self, delta):
#may need to change to not affect 0-layer
for layer in range(self.num_layers-1, -1, -1):
# print 'delta',layer,':',delta
delta = self.network[layer].backPropogate(delta,self.alpha)
delta = delta[1:len(delta)]
def computeDError(self, expected, returned):
return (returned - expected)