Skip to content

Latest commit

 

History

History
43 lines (32 loc) · 1.12 KB

File metadata and controls

43 lines (32 loc) · 1.12 KB

Backpropagation Neural Network (XOR Problem Implementation)

Overview

This task implements a simple neural network using Python and NumPy to solve the XOR problem.

The main goal is to demonstrate how the backpropagation algorithm helps a neural network learn non-linear patterns that cannot be solved using a single-layer perceptron.


Problem Statement (XOR Dataset) :

We use the XOR truth table as input.

Why XOR?

  • XOR is not linearly separable
  • A single-layer perceptron cannot solve it
  • A hidden layer is required

Model Architecture

  • Input Layer: 2 neurons
  • Hidden Layer: 2 neurons
  • Output Layer: 1 neuron
  • Activation Function: Sigmoid

Forward Propagation

Inputs are passed through the network:

  1. Input to Hidden Layer
  2. Hidden Layer to Output Layer

Each neuron performs:

  • Weighted sum
  • Sigmoid activation

This generates the final prediction.

Loss Function

The loss is equal to half times the average of the squared difference between the actual output and the predicted output.

In this implementation:

error = targets - final_output

loss = np.mean(error ** 2)