Skip to content

Zero-dependency Neural Network implementation in Java from scratch, trained on the MNIST dataset.

License

Notifications You must be signed in to change notification settings

mivige/JNeuralNet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JNeuralNet

JNeuralNet is a fully independent Neural Network written in Java from scratch, designed to train and evaluate on the MNIST dataset (handwritten digits 0-9). The project demonstrates the core concepts of neural networks without relying on external libraries.

Architecture

The default network architecture configured in Main.java is:

  • Input Layer: 784 neurons (28x28 flattened MNIST images)
  • Hidden Layer 1: 128 neurons (ReLU Activation)
  • Output Layer: 10 neurons (Softmax Activation paired with CrossEntropy Loss)
  • Optimizer: Stochastic Gradient Descent (SGD)

Prerequisites

  • Java 17 or higher
  • Maven (Required for compilation and testing)

Warning

Maven Requirement & Installation This project uses Maven to manage compilation and the testing suite. If Maven is not installed on your system, commands like mvn clean test will fail.

To install Maven on Windows: You can download it directly via Winget or script. If you just installed it, be sure to restart your terminal or IDE (like VS Code, Eclipse, or IntelliJ) so the PATH changes take effect. You can verify the installation by running:

mvn -version

Getting Started

1. Compile the Project

To compile the Java source files, run:

mvn clean compile

2. Run the Main Training Loop

This will load the MNIST dataset from the local MNIST Dataset folder, initialize the network, and begin training across epochs.

mvn exec:java -Dexec.mainClass="Main"

3. Run Automated Tests

The project includes a suite of JUnit 5 tests covering the discrete mathematics (Sigmoid, Matrix shapes, XOR convergence) and dataset parsing.

mvn test

Structure

  • src/main/math: Pure java manual implementations of Sigmoid, ReLU, Softmax, MSE, and CrossEntropy.
  • src/main/nn: Core implementation of Neural Components (Neuron, Layer, NeuralNetwork, Trainer).
  • src/main/data: Dataset parsers targeting .idx file formats.
  • src/test: Unit tests proving convergence mechanics on logic gates like XOR.

Useful Resources

About

Zero-dependency Neural Network implementation in Java from scratch, trained on the MNIST dataset.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages