|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.classifiers.Classifier
weka.classifiers.functions.MultilayerPerceptron
A Classifier that uses backpropagation to classify instances. This network can be built by hand, created by an algorithm or both. The network can also be monitored and modified during training time. The nodes in this network are all sigmoid (except for when the class is numeric in which case the the output nodes become unthresholded linear units).
Nested Class Summary | |
(package private) class |
MultilayerPerceptron.ControlPanel
This provides the basic controls for working with the neuralnetwork |
protected class |
MultilayerPerceptron.NeuralEnd
This inner class is used to connect the nodes in the network up to the data that they are classifying, Note that objects of this class are only suitable to go on the attribute side or class side of the network and not both. |
private class |
MultilayerPerceptron.NodePanel
Inner class used to draw the nodes onto. |
Field Summary | |
private boolean |
m_accepted
a flag to state that the network should be accepted the way it is. |
private double[] |
m_attributeBases
The base values for all the attributes. |
private double[] |
m_attributeRanges
The ranges for all the attributes. |
private boolean |
m_autoBuild
A flag to tell the build classifier to automatically build a neural net. |
private MultilayerPerceptron.ControlPanel |
m_controlPanel
The control panel. |
private Instance |
m_currentInstance
The current instance running through the network. |
private boolean |
m_decay
This flag states that the user wants the learning rate to decay. |
private int |
m_driftThreshold
The number to to use to quit on validation testing. |
private int |
m_epoch
Shows the number of the epoch that the network just finished. |
private double |
m_error
Shows the error of the epoch that the network just finished. |
private FastVector |
m_graphers
A Vector list of the graphers. |
private boolean |
m_gui
A flag to state that the gui for the network should be brought up. |
private java.lang.String |
m_hiddenLayers
The string that defines the hidden layers |
private MultilayerPerceptron.NeuralEnd[] |
m_inputs
The input units. |
private Instances |
m_instances
The training instances. |
private double |
m_learningRate
This is the learning rate for the network. |
private LinearUnit |
m_linearUnit
This is a linear unit. |
private double |
m_momentum
This is the momentum for the network. |
private NeuralConnection[] |
m_neuralNodes
All the nodes that actually comprise the logical neural net. |
private int |
m_nextId
The next id number available for default naming. |
private MultilayerPerceptron.NodePanel |
m_nodePanel
The panel the nodes are displayed on. |
private NominalToBinary |
m_nominalToBinaryFilter
The actual filter. |
private boolean |
m_normalizeAttributes
This flag states that the user wants the input values normalized. |
private boolean |
m_normalizeClass
This flag states that the user wants the class to be normalized while processing in the network is done. |
private int |
m_numAttributes
The number of attributes. |
private int |
m_numClasses
The number of classes. |
private int |
m_numEpochs
The number of epochs to train through. |
private boolean |
m_numeric
A flag to say that it's a numeric class. |
private MultilayerPerceptron.NeuralEnd[] |
m_outputs
The output units. |
private java.util.Random |
m_random
The actual random number generator. |
private long |
m_randomSeed
The number used to seed the random number generator. |
private boolean |
m_reset
This flag states that the user wants the network to restart if it is found to be generating infinity or NaN for the error value. |
private FastVector |
m_selected
A Vector list of the units currently selected. |
private SigmoidUnit |
m_sigmoidUnit
this is a sigmoid unit. |
private boolean |
m_stopIt
a flag to state if the network should be running, or stopped. |
private boolean |
m_stopped
a flag to state that the network has in fact stopped. |
private boolean |
m_useNomToBin
A flag to state that a nominal to binary filter should be used. |
private int |
m_valSize
An int to say how big the validation set should be. |
private javax.swing.JFrame |
m_win
The window for the network. |
Fields inherited from class weka.classifiers.Classifier |
m_Debug |
Constructor Summary | |
MultilayerPerceptron()
The constructor. |
Method Summary | |
private void |
addNode(NeuralConnection n)
Call this function to place a node into the network list. |
java.lang.String |
autoBuildTipText()
|
void |
blocker(boolean tf)
A function used to stop the code that called buildclassifier from continuing on before the user has finished the decision tree. |
void |
buildClassifier(Instances i)
Call this function to build and train a neural network for the training data provided. |
private double |
calculateErrors()
This will cause the error values to be calculated for all nodes. |
private void |
calculateOutputs()
This will cause the output values of all the nodes to be calculated. |
java.lang.String |
decayTipText()
|
double[] |
distributionForInstance(Instance i)
Call this function to predict the class of an instance once a classification model has been built with the buildClassifier call. |
boolean |
getAutoBuild()
|
boolean |
getDecay()
|
boolean |
getGUI()
|
java.lang.String |
getHiddenLayers()
|
double |
getLearningRate()
|
double |
getMomentum()
|
boolean |
getNominalToBinaryFilter()
|
boolean |
getNormalizeAttributes()
|
boolean |
getNormalizeNumericClass()
|
java.lang.String[] |
getOptions()
Gets the current settings of NeuralNet. |
long |
getRandomSeed()
|
boolean |
getReset()
|
int |
getTrainingTime()
|
int |
getValidationSetSize()
|
int |
getValidationThreshold()
|
java.lang.String |
globalInfo()
This will return a string describing the classifier. |
java.lang.String |
GUITipText()
|
java.lang.String |
hiddenLayersTipText()
|
java.lang.String |
learningRateTipText()
|
java.util.Enumeration |
listOptions()
Returns an enumeration describing the available options. |
static void |
main(java.lang.String[] argv)
Main method for testing this class. |
java.lang.String |
momentumTipText()
|
java.lang.String |
nominalToBinaryFilterTipText()
|
java.lang.String |
normalizeAttributesTipText()
|
java.lang.String |
normalizeNumericClassTipText()
|
java.lang.String |
randomSeedTipText()
|
private boolean |
removeNode(NeuralConnection n)
Call this function to remove the passed node from the list. |
private void |
resetNetwork()
this will reset all the nodes in the network. |
java.lang.String |
resetTipText()
|
void |
setAutoBuild(boolean a)
This will set whether the network is automatically built or if it is left up to the user. |
private Instances |
setClassType(Instances inst)
This function sets what the m_numeric flag to represent the passed class it also performs the normalization of the attributes if applicable and sets up the info to normalize the class. |
void |
setDecay(boolean d)
|
private void |
setEndsToLinear()
This will go through all the nodes and check if they are connected to a pure output unit. |
void |
setGUI(boolean a)
This will set whether A GUI is brought up to allow interaction by the user with the neural network during training. |
void |
setHiddenLayers(java.lang.String h)
This will set what the hidden layers are made up of when auto build is enabled. |
void |
setLearningRate(double l)
The learning rate can be set using this command. |
void |
setMomentum(double m)
The momentum can be set using this command. |
void |
setNominalToBinaryFilter(boolean f)
|
void |
setNormalizeAttributes(boolean a)
|
void |
setNormalizeNumericClass(boolean c)
|
void |
setOptions(java.lang.String[] options)
Parses a given list of options. |
void |
setRandomSeed(long l)
This seeds the random number generator, that is used when a random number is needed for the network. |
void |
setReset(boolean r)
This sets the network up to be able to reset itself with the current settings and the learning rate at half of what it is currently. |
void |
setTrainingTime(int n)
Set the number of training epochs to perform. |
private void |
setupHiddenLayer()
Call this function to automatically generate the hidden units |
private void |
setupInputs()
This creates the required input units. |
private void |
setupOutputs()
This creates the required output units. |
void |
setValidationSetSize(int a)
This will set the size of the validation set. |
void |
setValidationThreshold(int t)
This sets the threshold to use for when validation testing is being done. |
java.lang.String |
toString()
|
java.lang.String |
trainingTimeTipText()
|
private void |
updateDisplay()
Call this function to update the control panel for the gui. |
private void |
updateNetworkWeights(double l,
double m)
This will cause the weight values to be updated based on the learning rate, momentum and the errors that have been calculated for each node. |
java.lang.String |
validationSetSizeTipText()
|
java.lang.String |
validationThresholdTipText()
|
Methods inherited from class weka.classifiers.Classifier |
classifyInstance, debugTipText, forName, getDebug, makeCopies, setDebug |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private Instances m_instances
private Instance m_currentInstance
private boolean m_numeric
private double[] m_attributeRanges
private double[] m_attributeBases
private MultilayerPerceptron.NeuralEnd[] m_outputs
private MultilayerPerceptron.NeuralEnd[] m_inputs
private NeuralConnection[] m_neuralNodes
private int m_numClasses
private int m_numAttributes
private MultilayerPerceptron.NodePanel m_nodePanel
private MultilayerPerceptron.ControlPanel m_controlPanel
private int m_nextId
private FastVector m_selected
private FastVector m_graphers
private int m_numEpochs
private boolean m_stopIt
private boolean m_stopped
private boolean m_accepted
private javax.swing.JFrame m_win
private boolean m_autoBuild
private boolean m_gui
private int m_valSize
private int m_driftThreshold
private long m_randomSeed
private java.util.Random m_random
private boolean m_useNomToBin
private NominalToBinary m_nominalToBinaryFilter
private java.lang.String m_hiddenLayers
private boolean m_normalizeAttributes
private boolean m_decay
private double m_learningRate
private double m_momentum
private int m_epoch
private double m_error
private boolean m_reset
private boolean m_normalizeClass
private SigmoidUnit m_sigmoidUnit
private LinearUnit m_linearUnit
Constructor Detail |
public MultilayerPerceptron()
Method Detail |
public static void main(java.lang.String[] argv)
argv
- should contain command line options (see setOptions)public void setDecay(boolean d)
d
- True if the learning rate should decay.public boolean getDecay()
public void setReset(boolean r)
r
- True if the network should restart with it's current options
and set the learning rate to half what it currently is.public boolean getReset()
public void setNormalizeNumericClass(boolean c)
c
- True if the class should be normalized (the class will only ever
be normalized if it is numeric). (Normalization puts the range between
-1 - 1).public boolean getNormalizeNumericClass()
public void setNormalizeAttributes(boolean a)
a
- True if the attributes should be normalized (even nominal
attributes will get normalized here) (range goes between -1 - 1).public boolean getNormalizeAttributes()
public void setNominalToBinaryFilter(boolean f)
f
- True if a nominalToBinary filter should be used on the
data.public boolean getNominalToBinaryFilter()
public void setRandomSeed(long l)
l
- The seed.public long getRandomSeed()
public void setValidationThreshold(int t)
t
- The threshold to use for this.public int getValidationThreshold()
public void setLearningRate(double l)
l
- The New learning rate.public double getLearningRate()
public void setMomentum(double m)
m
- The new Momentum.public double getMomentum()
public void setAutoBuild(boolean a)
a
- True if the network should be auto built.public boolean getAutoBuild()
public void setHiddenLayers(java.lang.String h)
h
- A string with a comma seperated list of numbers. Each number is
the number of nodes to be on a hidden layer.public java.lang.String getHiddenLayers()
public void setGUI(boolean a)
a
- True if gui should be created.public boolean getGUI()
public void setValidationSetSize(int a)
a
- The size of the validation set, as a percentage of the whole.public int getValidationSetSize()
public void setTrainingTime(int n)
n
- The number of epochs to train through.public int getTrainingTime()
private void addNode(NeuralConnection n)
n
- The node to place in the list.private boolean removeNode(NeuralConnection n)
n
- The neuralConnection to remove.
private Instances setClassType(Instances inst) throws java.lang.Exception
inst
- the instances.
java.lang.Exception
public void blocker(boolean tf)
tf
- True to stop the thread, False to release the thread that is
waiting there (if one).private void updateDisplay()
private void resetNetwork()
private void calculateOutputs()
private double calculateErrors() throws java.lang.Exception
java.lang.Exception
private void updateNetworkWeights(double l, double m)
l
- The learning rate to update with.m
- The momentum to update with.private void setupInputs() throws java.lang.Exception
java.lang.Exception
private void setupOutputs() throws java.lang.Exception
java.lang.Exception
private void setupHiddenLayer()
private void setEndsToLinear()
public void buildClassifier(Instances i) throws java.lang.Exception
buildClassifier
in class Classifier
i
- The training data.
Throws
- exception if can't build classification properly.
java.lang.Exception
- if the classifier has not been
generated successfullypublic double[] distributionForInstance(Instance i) throws java.lang.Exception
distributionForInstance
in class Classifier
i
- The instance to classify.
if
- can't classify instance.
java.lang.Exception
- if distribution could not be
computed successfullypublic java.util.Enumeration listOptions()
listOptions
in interface OptionHandler
listOptions
in class Classifier
public void setOptions(java.lang.String[] options) throws java.lang.Exception
-L num
Set the learning rate.
(default 0.3)
-M num
Set the momentum
(default 0.2)
-N num
Set the number of epochs to train through.
(default 500)
-V num
Set the percentage size of the validation set from the training to use.
(default 0 (no validation set is used, instead num of epochs is used)
-S num
Set the seed for the random number generator.
(default 0)
-E num
Set the threshold for the number of consequetive errors allowed during
validation testing.
(default 20)
-G
Bring up a GUI for the neural net.
-A
Do not automatically create the connections in the net.
(can only be used if -G is specified)
-B
Do Not automatically Preprocess the instances with a nominal to binary
filter.
-H str
Set the number of nodes to be used on each layer. Each number represents
its own layer and the num of nodes on that layer. Each number should be
comma seperated. There are also the wildcards 'a', 'i', 'o', 't'
(default 4)
-C
Do not automatically Normalize the class if it's numeric.
-I
Do not automatically Normalize the attributes.
-R
Do not allow the network to be automatically reset.
-D
Cause the learning rate to decay as training is done.
setOptions
in interface OptionHandler
setOptions
in class Classifier
options
- the list of options as an array of strings
java.lang.Exception
- if an option is not supportedpublic java.lang.String[] getOptions()
getOptions
in interface OptionHandler
getOptions
in class Classifier
public java.lang.String toString()
public java.lang.String globalInfo()
public java.lang.String learningRateTipText()
public java.lang.String momentumTipText()
public java.lang.String autoBuildTipText()
public java.lang.String randomSeedTipText()
public java.lang.String validationThresholdTipText()
public java.lang.String GUITipText()
public java.lang.String validationSetSizeTipText()
public java.lang.String trainingTimeTipText()
public java.lang.String nominalToBinaryFilterTipText()
public java.lang.String hiddenLayersTipText()
public java.lang.String normalizeNumericClassTipText()
public java.lang.String normalizeAttributesTipText()
public java.lang.String resetTipText()
public java.lang.String decayTipText()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |