-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path007_objects.py
More file actions
39 lines (26 loc) · 861 Bytes
/
007_objects.py
File metadata and controls
39 lines (26 loc) · 861 Bytes
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
import numpy as np
# initial weights random
np.random.seed(0)
# inputs (input data to NN)
X = [[1.0, 2.0, 3.0, 2.5],
[2.0, 5.0, -1.0, 2.0],
[-1.5 , 2.7, 3.3, -0.8]]
# Dense layer
class Layer_Dense:
def __init__(self, n_inputs, n_neurons):
# shape, size of sample n_inputs,
# 0.10 for normalisation
self.weights = 0.10 * np.random.rand(n_inputs, n_neurons)
self.biases = np.zeros((1, n_neurons))
def forward(self, inputs):
self.output = np.dot(inputs, self.weights) + self.biases
# size of iputs (number of features in each sample);
# number of neurons (any number)
layer1 = Layer_Dense(4, 5)
# size of inputs is the same as the number
# of neurons in the previous layer
layer2 = Layer_Dense(5, 2)
layer1.forward(X)
#print(layer1.output)
layer2.forward(layer1.output)
print(layer2.output)