-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneural_network.py
41 lines (31 loc) · 966 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
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
def sigmoid(x):
return 1 / (1+ np.exp(-x))
class neuron:
def __init__(self, weights, bias):
self.weights = weights
self.bias = bias
def feedfwd(self,input):
total = np.dot(self.weights, input) + self.bias
return sigmoid(total)
weights = np.array([0,1])
bias = np.random.randint(5)
print("Bias =",bias)
n = neuron(weights,bias)
x = np.array([2,3])
print(n.feedfwd(x))
class NeuralNetwork:
def __init__(self):
weights = np.array([0,1])
bias = 0
self.h1 = neuron(weights ,bias)
self.h2 = neuron(weights, bias)
self.output = neuron(weights, bias)
def feedfwd(self,x):
out_h1 = self.h1.feedfwd(x)
out_h2 = self.h2.feedfwd(x)
out_output = self.output.feedfwd(np.array([out_h1,out_h2]))
return out_output
network = NeuralNetwork()
x = np.array([2,3])
print(network.feedfwd(x))