de.webdings.jannis.neuralnet

Class NeuralNet


public class NeuralNet
extends java.lang.Object

NeuralNet is a wrapper for the actual neural net that is represented in layers.
It provides functionality for setting up, using, training and reconfiguring the net easily as well as saving it to an NNML file.

The net can consist of all known neuron types that are a subclass of the abstract Neuron. It accepts only one such type at a time. So you can't mix different neuron types in one net.

Currently only one neuron type is supported:

Version:
0.1 10.08.2005

Author:
Stefan Thesing
Website: http://www.webdings.de

Field Summary

protected Neuron[][]
layers
layers is an array containing layers of neurons.
protected String
type
type represents the type of neurons of which this net consists.

Constructor Summary

NeuralNet(Class type)
Constructs an empty NeuralNet of the specified type.
NeuralNet(String type)
Constructs an empty NeuralNet of the specified type.
NeuralNet(Neuron layers)
Constructs a NeuralNet using a specified array containing layers of neurons.
NeuralNet(Neuron aFirstInputNeuron)
Constructs a NeuralNet starting with a single specified neuron and automatically determines the type of this neuron.

Method Summary

void
addLayer()
Adds a new empty layer to the net.
void
addLayer(Neuron l)
Adds the specified layer to the net.
void
addLayer(Neuron l, int layerID)
Adds the specified layer to the net using the specified layerID.
void
addLayers(int numberOfLayersToAdd)
Adds a specified number of empty layers to the net.
void
addNeuron(Neuron neuron, int targetLayerID)
Adds a neuron to the specified layer
static boolean
areNeuronTypesConsistent(Neuron layers)
This static method is called by other methods and constructors to ensure that the neuron types used in this net are consistent.
Neuron[][]
getLayers()
String
getType()
void
replaceLayer(Neuron l, int layerID)
Replaces the layer of the specified layerID with the specified layer l.
void
setLayers(Neuron layers)
This methods replaces the actual neural net wrapped by this class with the specified array.
void
toFile(String fileName)
Saves a NNML representation of the net to a file of the specified filename.

Field Details

layers

protected Neuron[][] layers
layers is an array containing layers of neurons. Each layer is an array containing neurons. So layers is the actual neural net wrapped by this class.


type

protected String type
type represents the type of neurons of which this net consists. For example, if a net consists of BiNeurons type reads "de.webdings.jannis.neuralnet.BiNeuron"

Mixing different neuron types is not allowed.

Constructor Details

NeuralNet

public NeuralNet(Class type)
            throws NeuronTypeMismatchException
Constructs an empty NeuralNet of the specified type.

Parameters:
type -

Throws:
NeuronTypeMismatchException -


NeuralNet

public NeuralNet(String type)
            throws NeuronTypeMismatchException
Constructs an empty NeuralNet of the specified type.

Parameters:
type -

Throws:
NeuronTypeMismatchException -


NeuralNet

public NeuralNet(Neuron layers)
            throws NeuronTypeMismatchException
Constructs a NeuralNet using a specified array containing layers of neurons. This constructor automatically determines the type of the neurons that the specified layers contain and rejects layers that contain neurons of unsupported types as well as layers that contain neurons of mixed types.

Parameters:
layers -

Throws:
NeuronTypeMismatchException -


NeuralNet

public NeuralNet(Neuron aFirstInputNeuron)
            throws NeuronTypeMismatchException
Constructs a NeuralNet starting with a single specified neuron and automatically determines the type of this neuron. It rejects unsupported neuron types.

Parameters:
aFirstInputNeuron -

Throws:
NeuronTypeMismatchException -

Method Details

addLayer

public void addLayer()
            throws NeuronTypeMismatchException
Adds a new empty layer to the net.

Throws:
NeuronTypeMismatchException -


addLayer

public void addLayer(Neuron l)
            throws NeuronTypeMismatchException
Adds the specified layer to the net.

Parameters:
l -

Throws:
NeuronTypeMismatchException -


addLayer

public void addLayer(Neuron l,
                     int layerID)
            throws NeuronTypeMismatchException
Adds the specified layer to the net using the specified layerID. If the net already contains a layer with this ID it (and the following layers) will be moved one step farther.
So the ID number of these layers will be increased by one.
If you don't want that, but want to replace the existing layer use the method replaceLayer.

Parameters:
l -
layerID -

Throws:
NeuronTypeMismatchException -


addLayers

public void addLayers(int numberOfLayersToAdd)
            throws NeuronTypeMismatchException
Adds a specified number of empty layers to the net.

Parameters:
numberOfLayersToAdd -

Throws:
NeuronTypeMismatchException -


addNeuron

public void addNeuron(Neuron neuron,
                      int targetLayerID)
            throws LowerLayersEmptyException,
                   NeuronTypeMismatchException,
                   BadArgumentException
Adds a neuron to the specified layer

Parameters:
neuron -
targetLayerID -

Throws:
LowerLayersEmptyException -
NeuronTypeMismatchException -
BadArgumentException -


areNeuronTypesConsistent

public static boolean areNeuronTypesConsistent(Neuron layers)
            throws NeuronTypeMismatchException
This static method is called by other methods and constructors to ensure that the neuron types used in this net are consistent.

Parameters:
layers - The layers of the net that is checked for consistency.

Returns:
true if only one type of Neurons is used in this net, false if there are mixed types.

Throws:
NeuronTypeMismatchException - if the specified layers are empty.


getLayers

public Neuron[][] getLayers()

Returns:
Returns the layers.


getType

public String getType()

Returns:
Returns the neuron type of this net.


replaceLayer

public void replaceLayer(Neuron l,
                         int layerID)
            throws NeuronTypeMismatchException
Replaces the layer of the specified layerID with the specified layer l.

Parameters:
l -
layerID -

Throws:
NeuronTypeMismatchException -


setLayers

public void setLayers(Neuron layers)
            throws NeuronTypeMismatchException
This methods replaces the actual neural net wrapped by this class with the specified array. It does essentially the same as the constructor with the same parameter.

Parameters:
layers - The layers to set.

Throws:
NeuronTypeMismatchException -


toFile

public void toFile(String fileName)
            throws NeuronTypeMismatchException,
                   IOException
Saves a NNML representation of the net to a file of the specified filename.

Parameters:
fileName -

Throws:
NeuronTypeMismatchException - if the neuron type of the net is not supported.


NeuralNet.java - Copyright (c) 2005 by Stefan Thesing

This file is part of Jannis.

Jannis is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

Jannis is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Jannis; if not, write to the
Free Software Foundation, Inc.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA



© 2005 by Stefan Thesing;
Verbatim copying and redistribution of this entire page are permitted provided this notice is preserved.