
The basic unit of a neural network, consisting of a single neuron
Input Layer
Weights
Bias
Weighted Sum

Activation Function

Learning Algorithm
Preparing Input Data
Initializing Weights and Bias
Feedforward
Error Calculation
Weight Update
Weights and bias are adjusted using the following rule to reduce prediction error:
Here, represents the change in weight, which is defined as follows:
The bias is updated as follows:
Iteration

def AND_gate(x1, x2):
w1, w2, b = 1, 1, -1.5 # Weight and Bias
z = w1 * x1 + w2 * x2 + b
return 1 if z > 0 else 0
def NOT_gate(x):
w, b = -1, 0.5 # Weight and Bias
z = w * x + b
return 1 if z > 0 else 0
def OR_gate(x1, x2):
w1, w2, b = 1, 1, -0.5 # Weight and Bias
z = w1 * x1 + w2 * x2 + b
return 1 if z > 0 else 0
# The XOR gate cannot be implemented with a single perceptron, but can be implemented using a multilayer perceptron
def XOR_gate(x1, x2):
# Combine AND, OR, and NOT gates to implement the XOR gate
s1 = OR_gate(x1, x2) # First Hidden Layer
s2 = AND_gate(x1, x2) # Second Hidden Layer
y = AND_gate(NOT_gate(s2), s1) # Output Layer
return y