-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.py
26 lines (21 loc) · 863 Bytes
/
node.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
#Learned this stuff from http://neuralnetworksanddeeplearning.com which is "Neural Networks and Deep Learning" by Michael Nielsen
#See Neural-Net-2/layer.py for replacement
import numpy as np #See www.numpy.org
class node:
def __init__(self, func, b, input_num, w = []):
self.function = func
self.bias = b
if (w != [] and len(w) == input_num):
self.weights = w
else:
self.weights = (2*np.random.random_sample(input_num))-1
def setweights(self, w):
if (len(w) == len(self.weights)):
self.weights = w
def setbias(self, b):
self.bias = b
def setfunction(self, func):
self.function = func
def compute(self, inputs):
if (len(inputs) == len(self.weights)):
return self.function(np.dot(self.weights, inputs) + self.bias)