Interactive Neural Network Simulator
Train a neural network and inspect the matrices that make it work.
Custom training data
Enter one example per line in the format
x1, x2, target. Use values between 0 and 1.
Training Results
The network's predictions after training.
Predictions for the training dataset
| Input x₁ | Input x₂ | Target | Network output | Predicted class |
|---|
Training loss
Binary cross-entropy loss during training. Lower values indicate better predictions.
Network architecture
A simplified view of the connections between neurons.
Inspect the Weight Matrices and Biases
These are the learned parameters. Every weight controls the strength of a connection between neurons.
First-layer weight matrix W₁
Dimensions: hidden neurons × input neurons.
Second-layer weight matrix W₂
Dimensions: output neurons × hidden neurons.
First-layer bias vector b₁
Output-layer bias vector b₂
Forward Propagation: Inspect One Example
Select an input pair to see how the trained network transforms it through its layers.
How Neural Networks Use Matrices
A neural network is built from layers of interconnected neurons. Each layer receives numerical values, combines them using weights and biases, and applies an activation function.
Matrix notation makes these calculations compact and efficient. Rather than calculating every neuron separately, a complete layer can be calculated using a matrix multiplication.
For this simulator, the dimensions are:
| Parameter or value | Dimensions | Role |
|---|---|---|
| X | \(2\times1\) | Input vector |
| W₁ | \(h\times2\) | Input-to-hidden weights |
| b₁ | \(h\times1\) | Hidden-layer bias |
| A₁ | \(h\times1\) | Hidden-layer activations |
| W₂ | \(1\times h\) | Hidden-to-output weights |
| b₂ | \(1\times1\) | Output bias |
| Ŷ | \(1\times1\) | Predicted output |
Here, \(h\) is the number of hidden neurons selected in the simulator. Each example is represented as a column vector.
Step 1: Forward Propagation
Forward propagation is the process of moving input data through the network to calculate a prediction.
For example, an input pair can be represented as:
\[ X=\begin{bmatrix}1\\0\end{bmatrix} \]The hidden layer combines the two inputs using its learned weights.
\[ Z^{[1]}=W^{[1]}X+b^{[1]} \]A nonlinear function transforms the weighted sums into hidden activations.
\[ A^{[1]}=f(Z^{[1]}) \]The second weight matrix combines hidden activations to produce the output prediction.
\[ Z^{[2]}=W^{[2]}A^{[1]}+b^{[2]} \] \[ \hat{Y}=\sigma(Z^{[2]}) \]Step 2: Calculate the Loss
A neural network needs a way to measure how far its predictions are from the desired answers. This measurement is called the loss function.
This simulator uses binary cross-entropy, which is commonly used for binary classification with a sigmoid output.
Here, \(m\) is the number of training examples, \(y_i\) is the correct target and \(\hat y_i\) is the network's predicted probability.
A lower loss means that the predictions are generally closer to the training targets. A loss close to zero indicates that the network is making confident and correct predictions on the training data.
Step 3: Backpropagation
Backpropagation calculates how each weight and bias contributes to the prediction error. It applies the chain rule, starting at the output layer and working backward through the hidden layer.
Output-layer error
For a sigmoid output combined with binary cross-entropy, the output error simplifies to:
Output weight gradient
The gradient of the output weight matrix is the outer product of the output error and the hidden activation vector:
Hidden-layer error
The output error is propagated backward through the second weight matrix. The derivative of the hidden activation function determines how much each hidden neuron contributed to the error.
First-layer weight gradient
The symbol \(\circ\) represents element-wise multiplication. The gradients for the bias vectors are the corresponding error terms.
Step 4: Gradient Descent and Weight Updates
Once the gradients have been calculated, gradient descent updates the weights and biases to reduce the loss.
The learning rate \(\eta\) controls the size of each update. A very small learning rate may make learning slow, while an excessively large learning rate can cause unstable updates or prevent convergence.
The simulator uses full-batch gradient descent: it calculates the average gradient over all training examples before updating the parameters once per epoch.
Why XOR Is an Important Neural Network Example
XOR, or exclusive OR, returns 1 when its two inputs are different and 0 when they are equal.
| Input x₁ | Input x₂ | XOR output |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
XOR is not linearly separable. A single linear classifier cannot separate its two output classes using one straight decision boundary.
A network with a nonlinear hidden layer can learn the pattern by combining multiple transformations. This makes XOR a useful demonstration of why nonlinear activation functions are important.
Activation Functions
Activation functions introduce nonlinearity into neural networks. Without nonlinear activation functions, stacking ordinary linear transformations would still produce a single linear transformation.
Sigmoid
The sigmoid function maps real values to the interval (0, 1). It is useful for interpreting a single binary output as a probability.
Tanh
Tanh maps values to the interval (-1, 1). It is zero-centered and can be useful in a small hidden layer.
ReLU
ReLU is widely used in deep learning because of its simple computation. However, a neuron that remains in the negative region can receive zero gradient under ordinary ReLU.
Applications of Neural Networks in Artificial Intelligence
1. Image recognition
Neural networks can learn visual patterns from images. Their weight matrices transform pixel information into increasingly useful representations for recognizing objects and other visual features.
2. Natural language processing
Neural networks are used in language classification, translation, text generation, search and conversational AI. Large language models use much more complex architectures than the small network in this simulator.
3. Recommendation systems
Neural networks can learn relationships between users, products and preferences. Matrix operations help transform user and item representations into recommendation scores.
4. Forecasting
Neural networks can learn patterns from historical observations and use them to estimate future values in areas such as demand planning, energy consumption and financial time series.
5. Anomaly detection
A trained model can identify observations that differ from patterns learned from normal data. Applications include equipment monitoring, network security and quality control.
Frequently Asked Questions
How do matrices work in a neural network?
Matrices store the weights connecting one layer to another. Matrix multiplication combines the incoming activations with these weights, while bias vectors shift the results before activation functions are applied.
What is the difference between forward propagation and backpropagation?
Forward propagation calculates the network's prediction. Backpropagation calculates gradients that indicate how the weights and biases should change to reduce prediction error.
Why does the network need an activation function?
Activation functions introduce nonlinearity. Without them, a sequence of linear layers would be equivalent to one linear transformation, limiting the types of patterns the network could learn.
Can this simulator train a network to solve XOR?
Yes. The network has a nonlinear hidden layer and can learn the XOR pattern. Training results depend on the initialization, learning rate, activation function and number of epochs.
What does the learning rate control?
The learning rate controls the size of the weight and bias updates. A low value can make training slow, while a high value can make optimization unstable.
What does a decreasing loss mean?
A decreasing training loss means that the model is improving its predictions on the training examples according to the selected loss function. It does not automatically guarantee good performance on new, unseen data.
Is this a large language model?
No. This is a small feedforward neural network designed to teach matrix operations and basic learning. Large language models use substantially more parameters, larger datasets and more advanced architectures, including transformer networks.
Does the simulator send my data to a server?
No. The training calculations in this educational simulator run locally in your browser. No external AI API or model service is used.
Related Matrix and Linear Algebra Simulators
Explore the mathematical operations that also appear in machine learning.
Matrix Multiplication Simulator → Eigenvalue & Eigenvector Simulator → SVD Simulator → Matrix Iteration Simulator → Gaussian Elimination Simulator →