Neural Network Library

From SolarStrike wiki
Revision as of 14:40, 17 February 2018 by Elverion (talk | contribs) (NeuralNet:feed())
Jump to: navigation, search

What Neural Networks Can Do

How It Works

Documentation

Including the library in your project

Before you can use the neural network library, you must tell your project to include the necessary files. To do so, you can simply use the require call, like so:

require('neuralnet/net');

It is highly recommended to do this at the top of your main project file (probably main.lua).

Creating an instance of a neural network

Before you can create an instance of a neural network, you will need to know what your network topology looks like. That is, how many inputs, how many outputs, how many hidden layers you would like, and how many neurons in each hidden layer. Hidden layers will generally have a number of neurons between the number of inputs and number of outputs. You generally only need one hidden layer for simple tasks and two for more complex tasks. For example, if you have 10 inputs and 2 outputs, you might consider one hidden layer of 4-6 neurons and may want to try experimenting to see which gives the best results.



class NeuralNet(...)

You may either pass a table of numbers or a variable number of number arguments to the constructor in order to create a network with that topology. The first argument (or table value) will be the number of inputs, the second argument will be the number of neurons in the first hidden layer, you may then provide additional data for extra hidden layers, and the final argument will be the number of outputs.

For example:

net = NeuralNet(10, 6, 2); -- Create a neural network with 10 inputs, one hidden layer with 6 neurons, and 2 outputs.
net2 = NeuralNet(32, 24, 16, 8); -- 32 inputs, 24 neurons in hidden layer #1, 16 neurons in hidden layer #2, and 8 outputs.

local topology = {6, 3, 1}; -- Alternatively we can pass the topology as a table
net3 = NeuralNet(topology);

NeuralNet:feed()

NeuralNet:feed(...)

This function is used feed' data into the network's inputs and perform calculations on it. You will use this both while training and for getting results once training is complete. Again, this function accepts either a variable number of arguments or table of values.

The number of values that you pass in must be exactly the same number of inputs for the network.

net = NeuralNet(2, 2, 1);
net:feed(0.0, 1.0); -- Feed two values, 0.0 and 1.0, into the networks inputs.

NeuralNet:backPropagation()

NeuralNet:getRecentAverageError()

NeuralNet:getResults()

NeuralNet:getExportTable()

NeuralNet:save()

NeuralNet:load()

Examples