Deep Learning_day5
Fri, Sep 01, 2023
<Deep Neural Network>
class AffineFunction:
def __init__(self, w, b):
self.w = w
self.b = b
def forward(self, x):
z = np.dot(self.w, x) + self.b
return z
class Sigmoid:
def forward(self, z):
y = 1 / (1 + np.exp(-z))
return y
class Artificial Neuron:
def __init__(self, w, b):
self.affine = AffineFunction(w=w, b=b)
self.activation = Sigmoid()
def forward(self, x):
z = self.affine.forward(x)
y = self.activation.forward(z)
return y
# NN(Neural Network)
class Model:
def __init__(self):
self.AND = ArtificialNeuron([5, 5], -7.5)
self.NAND = ArtificialNeuron([-5, -5], 7.5)
self.OR = ArtificialNeuron([5, 5], -2.5)
# Hidden Layer
def forward(self, x):
a1 = self.AND.forawrd(x)
a2 = self.OR.forward(x)
a3 = self.NAND.forward(x)
a = np.array([a1, a2, a3])
return a
x = [0, 1]
model = Model()
a = model.forward(x)
print(f'x: {x}')
print(f'a: {a}')