A simple neural network written in Dart that learns to approximate the sine function.
This project demonstrates how a minimal feedforward network can be built from scratch using custom matrix operations and activation functions.
- Neural network built entirely in Dart
- Custom matrix and activation function support
- Trains a 1β10β1 feedforward network to approximate
sin(x) - Includes training and evaluation logic
- No external ML libraries required
git clone https://github.com/AlanMet/SineWaveNN.git
cd SineWaveNN- Run the program Make sure you have the Dart SDK installed.
Copy
Edit
dart run main.dartData Generation The generateData() function creates pairs of random inputs x β [0, 1) and their corresponding sine values sin(x).
A simple feedforward neural network is created with the architecture: 1 input β 10 hidden units (tanh) β 1 output (tanh)
The network is trained on 10,000 examples for 10,000 epochs.
Mean squared error loss is minimized using basic gradient descent.
After training, the model is tested on 10,000 new samples.
Accuracy is calculated by comparing rounded outputs (toStringAsFixed(2)).
bash Copy Edit Training complete. Accuracy: 92.34% (Note: Accuracy is based on matching rounded sine predictions)