Implement Sequential Network

This commit is contained in:
Koshin S Hegde 2024-05-09 11:55:18 +05:30
parent 06c981253c
commit 40601130e0

30
src/neural_network.py Normal file
View File

@ -0,0 +1,30 @@
from layer import Layer
import numpy as np
from abc import ABC, abstractmethod
class NeuralNetwork(ABC):
@property
@abstractmethod
def layers(self) -> list[Layer]:
pass
@abstractmethod
def forward(self, x: np.ndarray) -> np.ndarray:
pass
class SequentialNetwork:
__layers: list[Layer]
def __init__(self, layers: list[Layer]):
self.__layers = layers
def forward(self, x: np.ndarray) -> np.ndarray:
for layer in self.__layers:
x = layer.forward(x)
return x
@property
def layers(self) -> list[Layer]:
return self.__layers