https://github.com/goessl/MachineLearning
An easy neural network for Java!
https://github.com/goessl/MachineLearning
artificial-intelligence begginer easy-to-use hidden-layers java learning learning-rate lightweight machine-learning matrices matrix matrix-calculations neural-network neurons prediction weight weights
Last synced: 6 months ago
JSON representation
An easy neural network for Java!
- Host: GitHub
- URL: https://github.com/goessl/MachineLearning
- Owner: goessl
- License: mit
- Created: 2017-06-29T22:22:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-03-03T18:29:28.000Z (over 6 years ago)
- Last Synced: 2025-03-29T23:21:43.721Z (6 months ago)
- Topics: artificial-intelligence, begginer, easy-to-use, hidden-layers, java, learning, learning-rate, lightweight, machine-learning, matrices, matrix, matrix-calculations, neural-network, neurons, prediction, weight, weights
- Language: Java
- Homepage:
- Size: 42 KB
- Stars: 126
- Watchers: 16
- Forks: 35
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Machine Learning
# Deprecated
**This repository is deprecated! Please use [NeuralNetwork](https://github.com/sebig3000/NeuralNetwork) instead!**Java collection that provides Java packages for developing machine learning algorithms and that is
- easy to use -> great for small projects or just to learn how machine learning works
- small and simple -> easy to understand and make changes
- lightweight (mostly because I'm a student who just started to learn how to code Java and can't code more complex :P)## Getting Started
### Prerequisites
This project is written in pure vanilla Java so there is nothing needed than the standard libraries.
### Installation
Just add all packages with the source files in the [Source folder /src](src) to your project and you are ready to go!
Every class has a main test method. After installation just run any class so you can check if the installation was successful.## Code Example
### [Neural Network](src/main/java/neural)
Initialize a new network with a given architecture (number or inputs, number of neurons in the hidden layers and each layers activation function)
(If you don't know what to choose, here is a rule of thumb for a average looking network:
- number of hidden layers = 2
- number of neurons per layer: number of inputs (except the last layer is the output layer = as many neurons as outputs)
- activation functions: none)```
//New network
final Network net = new Network(
2, //2 inputs
new int[]{3, 1}, //2 layers with 3 & 1 neurons
new Network.ActivationFunction[]{
Network.ActivationFunction.NONE, //both layers with ...
Network.ActivationFunction.NONE}); //... no activation function
```Then you can seed the weights in the network (= randomize it).
```
net.seedWeights(-1, 1);
```Prepare your training data and put it into a [Matrix] (src/main/java/neural/Matrix.java)
```
//Generate 10 training sets
//Every row represents one training set (10 rows = 10 sets)
//Every column gets fed into the same input/comes out of the same output
//(first column gets into the first input)
//(2 columns = 2 inputs / 1 column = 1 output)
final Matrix trainInput = new Matrix(10, 2);
final Matrix trainOutput = new Matrix(10, 1);
//Fill the training sets
//Inputs: two random numbers
//Outputs: average of these two numbers
final Random rand = new Random();
for(int set=0; set