JPF utilizes the Java object oriented programming paradigm to implement parameterized functions. This package contains features which allow users the ability to create, fit, evaluate, save, and load machine learning models using native Java.
Project start date: October 3rd, 2020
I was motivated to create this project for several reasons.
First, I was intrigued by the mathematics behind supervised machine learning and figured that the best way to learn them would be to understand the multivariate calculus behind it and then implement the techniques myself.
Second, I wanted to focus on my Java programming skills and decided that this project would provide an excellent opportunity. Specifically, I could use Java's object oriented design features to build a software package containing components that were easily testable, extendable, and understandable. The Tensorflow and Keras machine learning packages that are widely used in Python are important inspirations for this project. These packages made prototyping neural network and machine learning techniques easy, fast, and intuitive.
The JPF package is designed using Java's object oriented design and abstraction mechanisms. Use of abstract classes and interfaces allows for fast development of classes through code reuse and inheritance of data and behaviors. The complete UML summary design is available here. The Model class hierarchy, which is a subset of the complete package design, demonstrates these class relationships:
More sections of this package's design are discussed in the various pages of documentation.
This design also makes it easier for users to extend classes to create their own components that seamlessly integrate with this package. For example, following the documentation for extending classes, a user can create their own layers, loss functions, optimizers, and activation functions.
- Model (abstract class)
- SimpleModel (abstract class)
- NeuralNetwork
- Layer (abstract class)
- ActivationFunction (abstract class)
- Layer (abstract class)
- Loss (interface)
- Optimizer (interface)
- Examples
- Miscellaneous classes
- Extending classes
This project demonstrates software testing via black box and unit tests.
The black box tests are used to test correctness of the LinearModel, PolynomialModel, and NeuralNetwork classes. These black box tests work by conducting several scenarios involving parameterized functions and seeing if their behavior matches what is expected. For example, when fitting a Neural Network to some training data, it is expected that the training loss will decrease. These black box tests are implemented as examples that have clear goals for expected outcomes. Check the "Running examples" subsection in the "How to use/run" section to learn how to run these examples.
Unit testing is done on both the Utility and LinearAlgebra classes. These classes are well suited for unit testing since they contain very small static helper functions with predictable outputs. The unit test cases are located in Tests.java file. Check the "Running tests" subsection in the "How to use/run" section to learn how to run these tests.
A jar file containing the JPF package can be created by using the following make command in the main directory:
make jpf.jar
This will compile all of the package source files and place the resulting class files into a jar file located in the main directory. This jar file can then be moved into a separate project directory, where the package can then be imported as "import jpf.*;".
Javadocs can be created using the following make command in the main directory:
make javadocs
This will create a directory called "javadocs" in the main directory which contains the Javadocs as html files. Of particular interest is the index.html file, which is a good starting point to explore all of the Javadocs.
The examples documentation describes what each specific example does and the sample output. To run the examples, simply use the following commands in the main directory:
make examples
java Examples
The "make examples" command will run a script to create the jpf.jar if needed, then compile the Examples.java source code alongside the jpf.jar package code.
The "java Examples" command will run the Examples program and print out the various command line arguments that can be used to run the examples.
To run a specific example after the Examples.java class is compiled, simply provide the name of the example as a command line argument. For example:
java Examples simplelinear
To run the unit tests for the Utility.java and LinearAlgebra.java classes, simply use the following commands in the main directory:
make tests
java -ea Tests
The "make tests" command will run a script to create the jpf.jar if needed, then compile the Tests.java source code alongside the jpf.jar package code.
The "java -ea Tests" command will run the tests with assert statements enabled, which will warn the user if a test case failed.