public class NeuralNet
extends java.lang.Object
The net can be trained by providing 'perfect' data in a given pattern using the train method. Its memory can be saved to a file and later loaded to allow for persistent learning. A custom backpropagation model defines what algorithm is used to train the net.
As of v0.2.0a Edges between nodes can be broken and moved manually. This is extremely powerful but also extremely dangerous as the net does not check for circular links. If you are to add entropy to link management it is probably wise to implement a checking algorithm.
| Modifier and Type | Field and Description |
|---|---|
java.lang.String[] |
supportedVersions
The versions from which this version can load files.
|
java.lang.String |
version
The version of the net code.
|
| Constructor and Description |
|---|
NeuralNet(double[] p_inputs,
int[] p_layers,
ThresholdingAlgorithm p_thresholdModel,
BackPropagationMethod p_backprop)
Creates a new net with p_layers.length+1 layers, each with n nodes in them.
|
NeuralNet(java.io.FileReader p_file,
ThresholdingAlgorithm p_thresholdModel,
BackPropagationMethod p_backprop)
Create a net from a saved net file.
|
| Modifier and Type | Method and Description |
|---|---|
BackPropagationMethod |
getBackPropagationMethod()
Returns the BackPropagationMethod used to train the net.
|
NeuronLayer |
getLayer(int p_index)
Returns a layer such that one may edit its nodes and structure manually.
|
int[] |
getLayerStructure()
Returns an array of integers representing the structure of the net.
|
Neuron |
getNeuron(int p_layerIndex,
int p_neuronIndex)
Returns a neuron from anywhere in the current net.
|
int |
getNumberOfLayers()
Returns the number of layers in the net, without any extra information.
|
double[] |
getOutput()
Returns the output of the net as an array of doubles as long as the amount of output Neurons.
|
java.lang.String[] |
getSupportedFileVersions()
Returns an array of strings that represent (and correlate with) version ids from which this net can load files.
|
void |
preCalculate()
Precalculates all neuron values in order to speed up the net's calculation.
|
void |
prune(double p_threshold)
Removes edges with absolute values below the threshold given.
|
void |
removeNeuron(Neuron p_neuron)
Removes a neuron and all edges that point to and from it.
|
void |
save(java.io.FileWriter p_file)
Saves all net memory to a file.
|
void |
setBackPropagationMethod(BackPropagationMethod p_backprop)
Sets the BackPropagationMethod that willl be used to train the net.
|
void |
setInputValue(double p_value,
int p_index)
Allows the user to set the value of one input Neuron.
|
void |
setInputValues(double[] p_values)
Sets input values from an array of doubles.
|
java.lang.String |
toString()
Returns a string representing the object.
|
double |
train(double[] p_desirable)
Runs the back propogation algorithms on the whole net.
|
public final java.lang.String version
public final java.lang.String[] supportedVersions
public NeuralNet(double[] p_inputs,
int[] p_layers,
ThresholdingAlgorithm p_thresholdModel,
BackPropagationMethod p_backprop)
throws IndexOutOfBoundsException,
ValueOutOfBoundsException
p_inputs - The array of inputs. Length of the input layer is taken from these.p_layers - An array holding how many Neurons per NeuronLayer to maintain.p_thresholdModel - The thresholding model to use for all neuronsp_backprop - The back propagation system to use for the net's trainingIndexOutOfBoundsException - if p_layers[] has fewer than 2 aspectsValueOutOfBoundsException - if not enough Neurons exist in each layer to make the net functional (p_layers[i] < 1)public NeuralNet(java.io.FileReader p_file,
ThresholdingAlgorithm p_thresholdModel,
BackPropagationMethod p_backprop)
throws java.io.IOException
Files are saved in a human-readable format which, as of version 0.1.0a has the following outline, with values being indexed in the [layer,neuron,edge weight] system
0.2.0a //version 0.0040 //learning rate 3 //numver of layers 2 //nodes in layer 0, inputLayer 3 //nodes in hiden layers 4 //nodes in output layer 0.6 //input 0 0.8 //input 1 matrix data
When loading a net you must use the same threshold model as it was built with. Failure to do this results in very unpredictable behaviour. Changing its backpropagation model might cause the net to 'un-learn' its previous method of achieving results and learn a new method.
p_file - The file to load.p_thresholdModel - The thresholding model to use for this reconstucted netp_backprop - The backpropagation model to use.java.io.IOException - if the file is not valid and thus cannot be loadedpublic BackPropagationMethod getBackPropagationMethod()
public void setBackPropagationMethod(BackPropagationMethod p_backprop)
p_backprop - The BackPropagationMethod that will be used when train is called to adjust weightspublic NeuronLayer getLayer(int p_index) throws IndexOutOfBoundsException
When requesting layers be aware of any polymorphism that may be all cunning and sneaky.
p_index - The index of the layer to acquire, with 0 being the input layer.IndexOutOfBoundsException - if the index provided is out of bounds.getNumberOfLayers()public Neuron getNeuron(int p_layerIndex, int p_neuronIndex) throws IndexOutOfBoundsException
p_layerIndex - The index number of the layer in which the Neuron residesp_neuronIndex - The index number of the neuron witin the specified layerIndexOutOfBoundsException - in the event that either of the indices is out of rangepublic void preCalculate()
public void setInputValues(double[] p_values)
throws IndexOutOfBoundsException,
ValueOutOfBoundsException
Note that this value automatically calls preCalculate and hence inherits some slowness.
p_values - An array of doubles to set the input nodes as.IndexOutOfBoundsException - if the wrong amount of aspects are found in p_values, passed back from NeuronLayer.setInputValuesValueOutOfBoundsException - if the wrong values are contained in p_values, passed back from NeuronLayer.setInputValuesNeuronLayer,
setInputValue(double, int),
preCalculate()public void setInputValue(double p_value,
int p_index)
throws IndexOutOfBoundsException,
ValueOutOfBoundsException
p_value - The value, between 0 and 1, to set the Neuron to.p_index - The index of the input node to set.IndexOutOfBoundsException - in the event that the index given is invalidValueOutOfBoundsException - in the event that the given value is outside of the permissable input range of the function givensetInputValues(double[])public int getNumberOfLayers()
public int[] getLayerStructure()
NeuronLayerpublic double[] getOutput()
public double train(double[] p_desirable)
throws IndexOutOfBoundsException
p_desirable - An array of desirable output doubles, matched in length to the amount of output Neurons (those in the final layer).IndexOutOfBoundsException - if the wrong amount of desirable outputs is passedpublic void removeNeuron(Neuron p_neuron) throws ItemNotFoundException
p_neuron - The neuron to remove from this net. Various other methods allow for finding this.ItemNotFoundException - if the neuron passed is not in the net.public void prune(double p_threshold)
p_threshold - The value under which to remove an edge. (ie if (Math.abs(edge.getWeight()) < p_threshold))public void save(java.io.FileWriter p_file)
throws java.io.IOException
p_file - The file to save tojava.io.IOExceptionNeuralNet(FileReader, ThresholdingAlgorithm, BackPropagationMethod)public java.lang.String[] getSupportedFileVersions()
public java.lang.String toString()
toString in class java.lang.Object