Difference between revisions of "Neural Network Library"

From SolarStrike wiki
Jump to: navigation, search
m (Including the library in your project)
(Creating an instance of a neural network)
Line 14: Line 14:
  
 
==Creating an instance of a neural network==
 
==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:
 +
<source lang="lua">
 +
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.
 +
</source>
 +
 
==NeuralNet:feed()==
 
==NeuralNet:feed()==
 
==NeuralNet:backPropagation()==
 
==NeuralNet:backPropagation()==

Revision as of 14:29, 17 February 2018

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.

NeuralNet:feed()

NeuralNet:backPropagation()

NeuralNet:getRecentAverageError()

NeuralNet:getResults()

NeuralNet:getExportTable()

NeuralNet:save()

NeuralNet:load()

Examples