Implement Sequential Network
This commit is contained in:
parent
06c981253c
commit
40601130e0
30
src/neural_network.py
Normal file
30
src/neural_network.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user