This project implements a simple neural network in C that can learn the XOR function. The XOR (exclusive OR) problem is a classic problem in neural network literature, demonstrating a case where linear classifiers fail, and non-linear solutions are required. This neural network uses a single hidden layer and is trained using backpropagation.
- Sigmoid activation function for non-linearity.
- Initialization of weights with random values.
- Implementation of the forward pass and backpropagation to adjust weights based on errors.
- Use of a simple shuffle function to randomize the order of training data for each epoch.
- C compiler (e.g., GCC, Clang)
- Standard C libraries (
stdio.h
,stdlib.h
,math.h
)
- Clone this repository to your local machine.
- Compile the source code using a C compiler. For example, using GCC:
Note: The
gcc -o xor_nn xor_nn.c -lm
-lm
flag is necessary to link the math library. - Run the compiled executable:
./xor_nn
The network uses the sigmoid function for activation, providing a smooth gradient for backpropagation.
Weights are initialized to random values using init_weights
function, which generates numbers between 0 and 1.
Hardcoded to represent the XOR truth table.
Set to 0.1, adjustable based on training needs.
The network trains for 10,000 epochs, which can be adjusted based on convergence requirements.
Contributions to this project are welcome. Please fork the repository and submit a pull request with your improvements.
This project is open-source and available under the MIT License.