"""Implementing the Forward Pass """ import numpy as np class SimpleNN: def __init__(self, architecture): self.architecture = architecture self.weights = [] self.biases = [] # Initialize weights and biases np.random.seed(99) for i in range(len(architecture) - 1): self.weights.append(np.random.uniform( low=-1, high=1, size=(architecture[i], architecture[i+1]) )) self.biases.append(np.zeros((1, architecture[i+1]))) @staticmethod def relu(x): #implementing the relu activation function return np.maximum(0, x) def forward(self, X): #iterating through all layers for W, b in zip(self.weights, self.biases): #applying the weight and bias of the layer X = np.dot(X, W) + b #doing ReLU for all but the last layer if W is not self.weights[-1]: X = self.relu(X) #returning the result return X def predict(self, X): y = self.forward(X) return y.flatten() #defining a model architecture = [2, 64, 64, 64, 1] # Two inputs, two hidden layers, one output model = SimpleNN(architecture) # Generate predictions prediction = model.predict(np.array([0.1,0.2])) print(prediction)