-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer.py
28 lines (23 loc) · 1005 Bytes
/
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
# Understood this stuff from "Neural Networks and Deep Learning" by Michael Nielsen (http://neuralnetworksanddeeplearning.com/)
# Improved version from Neural-Net supersedes node.py and layer.py
import numpy as np #www.numpy.org
class layer:
def __init__(self, in_num, n_nodes, func):
self.input = in_num
self.func = func
self.nnodes = n_nodes
self.weights = ((2 * np.random.random_sample((self.nnodes, self.input + 1))) - 1)
def compute(self, inp):
inp_bi = np.append(inp, 1)
return self.func(np.dot(self.weights, inp_bi))
def setweights(self, inlist, node = None):
if (node == None):
self.weights = np.array(inlist)
else:
self.weights[node] = np.array(inlist)
def setbias(self, inlist, node = None):
if (node == None):
for i in range(self.nnodes):
self.weights[i][self.input] = inlist
else:
self.weights[node][len(self.input)] = inlist