marf.Classification.NeuralNetwork
Class NeuralNetwork

java.lang.Object
  |
  +--marf.Storage.StorageManager
        |
        +--marf.Classification.Classification
              |
              +--marf.Classification.NeuralNetwork.NeuralNetwork
All Implemented Interfaces:
IClassification, IStorageManager, java.io.Serializable

public class NeuralNetwork
extends Classification

Artificial Neural Network-based Classifier.

$Id: NeuralNetwork.java,v 1.45 2005/08/14 01:15:55 mokhov Exp $

Since:
0.0.1
Version:
$Revision: 1.45 $
Author:
Ian Clement, Serguei Mokhov
See Also:
Serialized Form

Field Summary
static int DEFAULT_EPOCH_NUMBER
          Default number of epoch iterations of 64 if none supplied.
static double DEFAULT_MIN_ERROR
          Default minimum training error of 0.1 if none supplied.
static int DEFAULT_OUTPUT_NEURON_BITS
          How many binary Neurons in the output layer.
static double DEFAULT_TRAINING_CONSTANT
          Default training constant of 1 if none supplied.
static java.lang.String JAXP_SCHEMA_LANGUAGE
          JAXP 1.2 Schema.
static java.lang.String JAXP_SCHEMA_SOURCE
          JAXP 1.2 Schema URL.
static java.lang.String OUTPUT_ENCODING
          All output will use this encoding.
static java.lang.String W3C_XML_SCHEMA
          XML 2001 Schema.
 
Fields inherited from class marf.Classification.Classification
oFeatureExtraction, oResultSet, oTrainingSet
 
Fields inherited from class marf.Storage.StorageManager
bDumpOnNotFound, iCurrentDumpMode, oObjectToSerialize, strFilename
 
Fields inherited from interface marf.Classification.IClassification
MARF_INTERFACE_CODE_REVISION
 
Fields inherited from interface marf.Storage.IStorageManager
DUMP_BINARY, DUMP_CSV_TEXT, DUMP_GZIP_BINARY, DUMP_HTML, DUMP_SQL, DUMP_XML, MARF_INTERFACE_CODE_REVISION, STORAGE_FILE_EXTENSIONS
 
Constructor Summary
NeuralNetwork(marf.FeatureExtraction.IFeatureExtraction poFeatureExtraction)
          NeuralNetwork Constructor.
 
Method Summary
 boolean classify()
          Neural Network implementation of classification routine.
 void commit()
          Applies changes made to neurons on every net's layer.
 void dump()
          Dumps Neural Net to an XML file.
 void dumpXML(java.lang.String filename)
          Dumps Neural Network as XML file.
 void generate(int piNumOfInputs, int[] paiHiddenLayers, int piNumOfOutputs)
          Generates a virgin net at random.
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
 double[] getRes()
          Gets outputs of a neural network run.
 marf.Storage.Result getResult()
          Retrieves the minimum-error classification result.
static void indent(java.io.BufferedWriter bw, int n)
          Indents the output according to the requested tabulation.
 void initialize(java.lang.String filename, boolean dtd)
          Parses XML and produces NNet.
 void restore()
          Restores Neural Net from an XML file.
 boolean train()
          Implementes training of Neural Net.
 void train(double[] in, int expected, double trainconst)
          Actual training of the net.
 
Methods inherited from class marf.Classification.Classification
getFeatureExtraction, getResultSet, getTrainingSetFilename, setFeatureExtraction
 
Methods inherited from class marf.Storage.StorageManager
backSynchronizeObject, dumpBinary, dumpCSV, dumpGzipBinary, dumpHTML, dumpSQL, dumpXML, enableDumpOnNotFound, getDefaultExtension, getDefaultExtension, getDumpMode, getFilename, restoreBinary, restoreCSV, restoreGzipBinary, restoreHTML, restoreSQL, restoreXML, setDumpMode, setFilename
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_OUTPUT_NEURON_BITS

public static final int DEFAULT_OUTPUT_NEURON_BITS
How many binary Neurons in the output layer. Presumably int (our ID) is 4 bytes, hence 4 * 8 = 32 bits, and so many outputs.

See Also:
Constant Field Values

DEFAULT_TRAINING_CONSTANT

public static final double DEFAULT_TRAINING_CONSTANT
Default training constant of 1 if none supplied.

See Also:
Constant Field Values

DEFAULT_EPOCH_NUMBER

public static final int DEFAULT_EPOCH_NUMBER
Default number of epoch iterations of 64 if none supplied.

See Also:
Constant Field Values

DEFAULT_MIN_ERROR

public static final double DEFAULT_MIN_ERROR
Default minimum training error of 0.1 if none supplied.

See Also:
Constant Field Values

OUTPUT_ENCODING

public static final java.lang.String OUTPUT_ENCODING
All output will use this encoding.

See Also:
Constant Field Values

JAXP_SCHEMA_LANGUAGE

public static final java.lang.String JAXP_SCHEMA_LANGUAGE
JAXP 1.2 Schema.

See Also:
Constant Field Values

W3C_XML_SCHEMA

public static final java.lang.String W3C_XML_SCHEMA
XML 2001 Schema.

See Also:
Constant Field Values

JAXP_SCHEMA_SOURCE

public static final java.lang.String JAXP_SCHEMA_SOURCE
JAXP 1.2 Schema URL.

See Also:
Constant Field Values
Constructor Detail

NeuralNetwork

public NeuralNetwork(marf.FeatureExtraction.IFeatureExtraction poFeatureExtraction)
NeuralNetwork Constructor.

Parameters:
poFeatureExtraction - FeatureExtraction module reference
Method Detail

train

public final boolean train()
                    throws ClassificationException
Implementes training of Neural Net.

Specified by:
train in interface IClassification
Overrides:
train in class Classification
Returns:
true
Throws:
ClassificationException - if there are any errors
java.lang.NullPointerException - if module parameters are incorrectly set
See Also:
TrainingSet

classify

public final boolean classify()
                       throws ClassificationException
Neural Network implementation of classification routine.

Returns:
true
Throws:
ClassificationException - when input feature vector length does not match the size of the input neuron layer or if there was a StorageException during dump/restore.

initialize

public final void initialize(java.lang.String filename,
                             boolean dtd)
                      throws StorageException
Parses XML and produces NNet.

Parameters:
filename - net's filename
dtd - if true DTD will be generated
Throws:
StorageException

getRes

public double[] getRes()
Gets outputs of a neural network run.

Returns:
array of doubles

indent

public static final void indent(java.io.BufferedWriter bw,
                                int n)
                         throws java.io.IOException
Indents the output according to the requested tabulation. For pretty indentation.

Parameters:
bw - Writer object
n - number of tabs
Throws:
java.io.IOException

dumpXML

public final void dumpXML(java.lang.String filename)
                   throws StorageException
Dumps Neural Network as XML file.

Parameters:
filename - XML file name to write to
Throws:
StorageException

generate

public final void generate(int piNumOfInputs,
                           int[] paiHiddenLayers,
                           int piNumOfOutputs)
                    throws ClassificationException
Generates a virgin net at random.

Parameters:
piNumOfInputs - number of input Neurons in the input layer
paiHiddenLayers - arrays of numbers of Neurons in the hidden layers
piNumOfOutputs - number of output Neurons in the output layer
Throws:
ClassificationException
Since:
0.2.0, Serguei

train

public final void train(double[] in,
                        int expected,
                        double trainconst)
                 throws ClassificationException
Actual training of the net.

Parameters:
in - double[]
expected - int
trainconst - double
Throws:
ClassificationException

commit

public final void commit()
Applies changes made to neurons on every net's layer.


dump

public void dump()
          throws StorageException
Dumps Neural Net to an XML file.

Specified by:
dump in interface IStorageManager
Overrides:
dump in class Classification
Throws:
StorageException

restore

public void restore()
             throws StorageException
Restores Neural Net from an XML file.

Specified by:
restore in interface IStorageManager
Overrides:
restore in class Classification
Throws:
StorageException

getResult

public marf.Storage.Result getResult()
Retrieves the minimum-error classification result.

Returns:
Result object
Since:
0.3.0

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Retrieves class' revision.

Returns:
revision string
Since:
0.3.0