-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.py
35 lines (31 loc) · 1.18 KB
/
layer.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
30
31
32
33
34
35
#Learned from "Neural Networks and Deep Learning" - http://neuralnetworksanddeeplearning.com by Michael Nielson
#See Neural-Net-2 for improved version
import numpy as np #www.numpy.org
import node
class layer:
def __init__(self, in_num, n_nodes, func):
self.input = in_num
self.func = func
self.nnodes = []
for i in range(n_nodes):
self.nnodes += [node.node(b = (2*np.random.random_sample())-1, input_num = in_num, w = (2*np.random.random_sample(in_num))-1, func = func)]
def compute(self, inp):
accum =[]
if (len(inp) != self.input):
return -1
else:
for i in self.nnodes:
accum += [i.compute(inp)]
return accum
def setweights(self, inlist, node = None):
if (node == None):
for i in range(len(self.nnodes)):
self.nnodes[i].setweights(inlist[i])
else:
self.nnodes[node].setweights(inlist)
def setbias(self, inlist, node = None):
if (node == None):
for i in range(len(self.nnodes)):
self.nnodes[i].setbias(inlist[i])
else:
self.nnodes[node].setbias(inlist)