-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnnet.py
More file actions
49 lines (39 loc) · 1.31 KB
/
nnet.py
File metadata and controls
49 lines (39 loc) · 1.31 KB
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
42
43
44
45
46
47
48
49
import numpy as np
import matplotlib.pyplot as plt
import nnfs
nnfs.init()
def create_dataset(points, classes):
X = np.zeros((points * classes, 2))
y = np.zeros(points * classes, dtype='uint8')
for class_number in range(classes):
ix = range(points * class_number, points * (class_number + 1))
r = np.linspace(0.0, 1, points) # radius
t = np.linspace(class_number * 4, (class_number + 1) * 4, points) + np.random.randn(points) * 0.2
X[ix] = np.c_[r * np.sin(t * 2.5), r * np.cos(t * 2.5)]
y[ix] = class_number
return X, y
X, y = create_dataset(100, 3)
plt.scatter(X[:,0], X[:,1])
plt.show()
plt.scatter(X[:,0], X[:,1], c=y, cmap='brg')
plt.show()
'''
# X is our input data set
X = [[1, 2, 3, 2.5],
[2.0, 5.0, -1.0, 2.0],
[-1.5, 2.7, 3.3, -0.8]]
'''
class Layer_Dense:
def __init__(self, n_inputs: int, n_neurons: int):
self.weights = 0.10 * np.random.randn(n_inputs, n_neurons)
self.biases = np.zeros((1, n_neurons))
def forward(self, inputs):
self.output = np.dot(inputs, self.weights) + self.biases
class Activation_ReLU:
def forward(self, inputs):
self.output = np.maximum(0, inputs)
layer1 = Layer_Dense(2, 5)
activation1 = Activation_ReLU()
layer1.forward(X)
activation1.forward(layer1.output)
print(activation1.output)