havBpNet:J
|
All Packages Class Hierarchy This Package Previous Next Index
havBpNet:J Home Page
Class havNN.havBpNet.havBpLayer
java.lang.Object
|
+----havNN.havBpNet.havBpLayer
- public class havBpLayer
- extends Object
The havBpLayer class implements a neural net "layer" - a
collection of nodes.
havBpLayer is the class that provides the basic applications interface of havBpNet-J
and should be well understood by application developers.
The user defines a network by creating several instances of havBpLayer and then
connecting the instances together to form a network. When creating an instance of havBpLayer,
the user specifies ...
• the instance of havBpNodeList with which the layer will be associated,
• the number of nodes in the layer,
• the “type” of the layer, and
• the transfer-function to be implemented in the layer’s nodes,
• the error function to be used (meaningful for output layers only - and optional).
Besides the creator methods, other methods supplied for havBpLayer allow the user to...
• connect the layer as input to one or more layers,
• set and query various parameters for nodes in the layer - like learning rate and
momentum, cascade coefficient, the so-called “training epoch”, etc.,
• establish and manipulate the level of random noise imposed on training patterns as they
pass through a layer,
• enable/disable layer training (i.e. turn weight adjustment on/off),
• assign user-specified activation-values and expected-values to one or all nodes in the
layer,
• process data forward through the layer using either the standard feed-forward mechanism
(inner-product) or a node-for-node “weighted” copy operation,
• retrieve the layer’s node values or errors,
• update the weights in the layer,
• save and restore the layer and its nodes to/from a user-specified file, and
• print both comprehensive and abbreviated state-reports of the layer and its nodes.
Additional methods are supplied for querying layer information such as the layer “type”,
transfer-function, layer’s size (number of nodes), etc.
Design, Implementation and Usage Notes
The havBpLayer class was designed to protect the user from having to deal directly with nodes
in the network. For example, the user is not required to create all node instances and assign
each to a layer; rather, the user is only required to create a layer and indicate the number
of nodes in the layer. Node creation is handled automatically by layer creation.
The user is allowed to specify that certain actions are to be performed for a particular
node in a layer. For example, the user may assign a value to a particular node in a layer.
Most applications won’t need to use these capabilities.
When a user connects a layer (say L1) as input to another layer (say L2), then backward
connections for error backpropagation between L2 and L1 are automatically defined.
A layer may be connected as input to any number of other layers.
It is possible for a layer to be connected to itself; however, this is not recommended
for it will cause a “delay-skew” in the layer’s nodes as their activation values are
calculated.
If you choose to connect a layer to itself in order to gain recurrent functionality,
then you should use the TrainRandom() method rather than the Train() method when training
the layer. The TrainRandom() method will cause the nodes in the layer to be processed in
a random order. Over a period of time, this should remove or, at least, lessen the effects
of delay skew. Use of the TrainRandom() method will add overhead to the training process
by calls to randomization.
Instead of connecting a layer to itself, we suggest that recurrency be implemented using
the form of the Simple Recurrent Net (also called a sequential net) of the form described
by Jordan (1986) and Elman (1990). Using this recommended form, a layer would
not be connected to the "recurrent" layer using the Connect() method. Rather, there
would be a node-for-node weighted copy from the layer tothe recurrent layer using the Copy()
method.
In the interests of processing speed, only minimal error checking is performed in member
functions.
The user is responsible for restoring layers in the same order as they were saved. If
the layers were saved in the order L1, L2, L3, then they should be restored in the same
order (i.e. L1, L2, L3).
- Version:
- 1.1(java) 1/1/98
-
havBpLayer(havBpNodeList, int, int, int)
-
Creates a new Layer and all nodes in the layer using the default
error function (squared error).
-
havBpLayer(havBpNodeList, int, int, int, int)
-
Creates a new Layer and all nodes in the layer using a specified error function.
-
havBpLayer(havBpNodeList, StreamTokenizer)
-
This method will restore a layer (and its nodes) from a specified file.
-
CalculateUpdates()
-
This method will perform the error calculation and calculate input weight changes for each node
in the layer.
-
Connect(havBpLayer)
-
This method can be used to connect the recieving layer as input to
to another layer (to).
-
Connect(havBpLayer, double, double)
-
This method can be used to connect the recieving layer as input to
to another layer (to).
-
Copy(havBpLayer, double)
-
This method will peform a dampened, node-to-node copy/add for each node in the
receiving layer.
-
Cycle()
-
This method will perform the feed-forward processing of the receiving layer.
-
CycleRandom()
-
This method will perform the feed-forward processing of the receiving layer.
-
Dump(String)
-
This method will produce a report (to stdout) of certain layer information.
-
GetBeta()
-
Returns the layer's learning rate.
-
GetCascade()
-
Returns the cascade coefficient for nodes in the layer
-
GetDecay()
-
Returns the decay rate of nodes in the layer
-
GetEpochSize()
-
This method will return the layer's epoch size.
-
GetError(double[])
-
This method will return the error of each node in the layer.
-
GetError(int)
-
Returns the current Error of a specified node in the layer.
-
GetErrorFunction()
-
Returns the layer's error function
-
GetErrorThreshold()
-
This method will return the layer's error threshold.
-
GetLayerFunction()
-
Returns the code of the layer's selected transfer function type.
-
GetLayerSize()
-
Returns the number of nodes in the layer.
-
GetLayerType()
-
Returns the "type" code.
-
GetMomentum()
-
This method will return the layer's training momentum.
-
GetNodeInputWeights(int)
-
Returns a pointer to the indicated node's input weight list.
-
GetNumberOfInputs(int)
-
Returns the number of nodes connected as input to node n.
-
GetScaledError()
-
This method will return the sum of the layer's node's scaled errors divided by the
layer's error function type.
-
GetSquaredError()
-
This method will return the sum of the squared error of all nodes in the layer.
-
GetValue(double[])
-
This method will return the value of all nodes in the layer.
-
GetValue(int)
-
Returns the current activation value of the specified node in the layer.
-
InitValue(double)
-
This method will set the activation value of all nodes in the layer
to a caller supplied value.
-
NormalizeWeights()
-
This method will normalize the INPUT weights of EACH of its nodes
such that their ABS VALUES sum to 1.0.
-
NormalizeWeights(double)
-
This method will normalize the INPUT weights of EACH of its nodes
such that their ABS VALUES sum to the value specified for fact.
-
PutBeta(double)
-
Sets the layer's learning constant (Beta) to the caller specified value.
-
PutCascade(double)
-
Sets the cascade coefficient for nodes in the layer
-
PutDecay(double)
-
Sets the layer's decay rate.
-
PutEpochSize(int)
-
Sets the layer's epoch value.
-
PutErrorFunction(int)
-
Sets the layer's error function.
-
PutErrorThreshold(double)
-
This method will set the error threshold for all nodes in the layer to a specified value.
-
PutExpected(double[])
-
This method will set the expected values of all nodes in the receiving layer
to the values in a caller supplied array of double values.
-
PutExpected(int, double)
-
This method will assign a caller supplied expected value to a caller specified node
in the receiving layer.
-
PutMomentum(double)
-
Sets the layer's learning momentum to the caller specified value.
-
PutNoise(double)
-
Sets the layer's noise level.
-
PutValue(double[])
-
This method will set the activation values of all nodes in the receiving layer
to the values in a caller supplied vector of double values.
-
PutValue(int, double)
-
This method will assign a caller supplied activation value to a caller specified node
in the receiving layer.
-
ReduceBeta(double)
-
This method will reduce the layer's learning constant (Beta) by a percentage of it's
current level.
-
ReduceMomentum(double)
-
This method will reduce the layer's momentum by a percentage of it's current level.
-
ReduceNoise(double)
-
This method will reduce the layer's noise level by a percentage of it's current level.
-
Restore(StreamTokenizer)
-
This method will restore a layer (and its nodes) from a specified file.
-
Save(FileOutputStream)
-
This method will save the appropriate layer information and data to the
caller specified file.
-
SetTraining(int)
-
Enable/Disable training (weight updates) for the layer's nodes.
-
Train()
-
This method will perform the error calculation and back propagation for each node
in the layer.
-
TrainRandom()
-
This method will perform the error calculation and back propagation for each node
in the layer.
-
UpdateWeights()
-
This member function will apply the weight updates calculated by the
CalculateUpdates(...) member functions
-
WTA(double)
-
Winner take all - set all nodes to 0.0 except the best
node which will be set to the value of the v argument.
havBpLayer
public havBpLayer(havBpNodeList net,
int nnodes,
int t,
int f)
- Creates a new Layer and all nodes in the layer using the default
error function (squared error).
- Parameters:
- net - The NodeList to which the layer will belong.
- nnodes - The number of nodes in the layer.
- t - The layer type (i.e. havINPUT, havHIDDEN, havOUTPUT)
- f - The transfer function of nodes in the layer (i.e. havLINEAR, havSIGMOID, etc.)
- See Also:
- NodeList, havBpNode, havBpSys
havBpLayer
public havBpLayer(havBpNodeList net,
int nnodes,
int t,
int f,
int ef)
- Creates a new Layer and all nodes in the layer using a specified error function.
- Parameters:
- net - The NodeList to which the layer will belong.
- nnodes - The number of nodes in the layer.
- t - The layer type (i.e. havINPUT, havHIDDEN, havOUTPUT)
- f - The transfer function of nodes in the layer (i.e. havLINEAR, havSIGMOID, etc.)
- ef - The error function to be used by nodes in the layer (i.e. havSQUARED, havCUBE, etc.)
- See Also:
- NodeList, havBpSys
havBpLayer
public havBpLayer(havBpNodeList net,
StreamTokenizer in) throws IOException
- This method will restore a layer (and its nodes) from a specified file.
NOTE: The current layer structure (size etc.) and settings (Beta, etc)
as well as all of the nodes in the current layer will be destroyed and replaced
by the structure and settings of the restored layer.
- Parameters:
- net - The NodeList to which the layer will belong.
- in - A StreamTokenizer of the file in which the layer was saved.
- Throws: IOException
- Throws an exception if any errors occur.
- See Also:
- StreamTokenizer, NodeList, havBpSys
PutValue
public void PutValue(double values[])
- This method will set the activation values of all nodes in the receiving layer
to the values in a caller supplied vector of double values.
If the layer's noise level is > 0.0, then a random amount of noise, between + - noise level)
will be added to each value.
NOTE: The IS NO ERROR checking to ensure that the number of values in the argument
vector is equal to the number of nodes in the layer. If there are fewer values
in the argument vector than nodes in the layer, then results are unpredictable.
- Parameters:
- values - An array of double values to be assigned to the nodes in the layer.
PutValue
public void PutValue(int node,
double value)
- This method will assign a caller supplied activation value to a caller specified node
in the receiving layer.
If the layer's noise level is > 0.0, then a random amount of noise, between + - noise level)
will be added to the value.
NOTE: If the receiving layer has no node indexible by the caller supplied index,
then the function simply returns.
- Parameters:
- node - The index (from 0) of the node whos value is to be set.
- value - The double value to be assigned to the specified node.
GetEpochSize
public int GetEpochSize()
- This method will return the layer's epoch size.
- Returns:
- The number of training patterns between error application.
GetMomentum
public double GetMomentum()
- This method will return the layer's training momentum.
- Returns:
- The momentum value assigned to nodes in the layer.
GetErrorThreshold
public double GetErrorThreshold()
- This method will return the layer's error threshold.
- Returns:
- The error threshold node 0.
GetValue
public void GetValue(double rtn[])
- This method will return the value of all nodes in the layer.
Values are returned in a caller supplied array of double;
It is the caller's responsibility to ensure that the size of the
returned values array is large enough.
- Parameters:
- rtn - The caller supplied (and sized) array for the returned values.
PutExpected
public void PutExpected(double values[])
- This method will set the expected values of all nodes in the receiving layer
to the values in a caller supplied array of double values.
NOTE: The IS NO ERROR checking to ensure that the number of values in the argument
array is equal to the number of nodes in the layer. If there are fewer values
in the argument array than nodes in the layer, then results are unpredictable.
- Parameters:
- values - An array of double expected values to be assigned to the
nodes in the layer.
PutExpected
public void PutExpected(int node,
double value)
- This method will assign a caller supplied expected value to a caller specified node
in the receiving layer.
NOTE: If the receiving layer has no node indexible by the caller supplied index,
then the function simply returns.
- Parameters:
- node - The index (from 0) of the node whos expected value is to be set.
- value - The double expected value to be assigned to the specified node.
CycleRandom
public void CycleRandom()
- This method will perform the feed-forward processing of the receiving layer. Nodes are
cycled in random order rather than in simple sequential order.
If the layer's type is havINPUT, then no processing is performed and the method
simply returns.
NOTE: The layer's function type is used to determine which specific
method will be called for each node in the layer.
Cycle
public void Cycle()
- This method will perform the feed-forward processing of the receiving layer.
If the layer's type is havINPUT, then no processing is performed and the method
simply returns.
NOTE: The layer's function type is used to determine which specific
method will be called for each node in the layer.
WTA
public int WTA(double v)
- Winner take all - set all nodes to 0.0 except the best
node which will be set to the value of the v argument.
Returns the index of the best node
if more than one node is best, then the first (from index 0)
will be set to v ... all others will be set to 0.0
- Parameters:
- v - The value to which the winning node is to be set
TrainRandom
public void TrainRandom()
- This method will perform the error calculation and back propagation for each node
in the layer. Nodes are processed in Random Order rather than simple
sequential order.
NOTE: The layer's function type and momentum setting are used to determine
the specific method to be used for processing the nodes in the layer.
Train
public void Train()
- This method will perform the error calculation and back propagation for each node
in the layer. Nodes are processed in simple sequential order.
NOTE: The layer's function type and momentum setting are used to determine
the specific method to be used for processing the nodes in the layer.
CalculateUpdates
public void CalculateUpdates()
- This method will perform the error calculation and calculate input weight changes for each node
in the layer.
NOTE: The layer's function type and momentum setting are used to determine
the specific method to be used for processing the nodes in the layer.
UpdateWeights
public void UpdateWeights()
- This member function will apply the weight updates calculated by the
CalculateUpdates(...) member functions
NormalizeWeights
public void NormalizeWeights()
- This method will normalize the INPUT weights of EACH of its nodes
such that their ABS VALUES sum to 1.0.
If fact is not specified, then it defaults to 1.0.
NormalizeWeights
public void NormalizeWeights(double fact)
- This method will normalize the INPUT weights of EACH of its nodes
such that their ABS VALUES sum to the value specified for fact.
- Parameters:
- fact - The value to which inout weights are normalized.
GetError
public void GetError(double rtn[])
- This method will return the error of each node in the layer.
NOTE: The caller is responsible for supplying the double vector in which
error values will be returned. The vector should exist as an allocated
vector (array) of double values.
- Parameters:
- rtn - The double array in which values will be returned.
GetError
public double GetError(int node)
- Returns the current Error of a specified node in the layer.
NOTE: If the specified node does not exist
in the layer, then a value of 0.0 is returned.
- Parameters:
- node - The node of interest's index number (from 0) in the layer.
GetSquaredError
public double GetSquaredError()
- This method will return the sum of the squared error of all nodes in the layer.
NOTE: There is no checking for numeric error conditions (like overflow)
performed by this method.
GetScaledError
public double GetScaledError()
- This method will return the sum of the layer's node's scaled errors divided by the
layer's error function type.
ie. ...
- sum(e[i]**2)/2
- sum(|e[i]|**3)/3
- sum(e[i]**4)/4
NOTE: There is no checking for numeric error conditions (like overflow)
performed by this method.
Save
public int Save(FileOutputStream out) throws IOException
- This method will save the appropriate layer information and data to the
caller specified file. All nodes in the layer will also be saved as part
of this method's operation.
If an error occurs during the save operation, then the standar int value
resulting from the fprpintf(...) is returned.
- Parameters:
- out - An opened and positioned FileOutputStream into which the layer
will be saved.
Restore
public int Restore(StreamTokenizer in) throws IOException
- This method will restore a layer (and its nodes) from a specified file.
NOTE: The current layer structure (size etc.) and settings (Beta, etc)
as well as all of the nodes in the current layer
will be destroyed and replaced by the structure and settings of the
restored layer.
- Parameters:
- in - The opened and positioned Save file from which the layer is to be restored.
- Throws: IOException
- If an I/O error occurs
GetLayerFunction
public int GetLayerFunction()
- Returns the code of the layer's selected transfer function type.
i.e. havLINEAR, havSIGMOID, havHTAN, havSIN, havHERMITE
GetLayerType
public int GetLayerType()
- Returns the "type" code.
i.e. havINPUT, havHIDDEN, havOUTPUT
GetLayerSize
public int GetLayerSize()
- Returns the number of nodes in the layer.
GetBeta
public double GetBeta()
- Returns the layer's learning rate.
SetTraining
public int SetTraining(int state)
- Enable/Disable training (weight updates) for the layer's nodes.
- Parameters:
- state - the state (havON or havOFF) to be set
PutBeta
public void PutBeta(double b)
- Sets the layer's learning constant (Beta) to the caller specified value.
NOTE: No range checking is performed on the caller supplied value.
- Parameters:
- b - The new value of Beta to be set.
PutDecay
public void PutDecay(double d)
- Sets the layer's decay rate.
NOTE: No range checking is performed on the caller supplied value.
- Parameters:
- d - The new decay value to be set.
GetDecay
public double GetDecay()
- Returns the decay rate of nodes in the layer
PutCascade
public void PutCascade(double c)
- Sets the cascade coefficient for nodes in the layer
- Parameters:
- c - the new cascade coefficient value to be set
GetCascade
public double GetCascade()
- Returns the cascade coefficient for nodes in the layer
PutMomentum
public void PutMomentum(double mu)
- Sets the layer's learning momentum to the caller specified value.
NOTE: No range checking is performed on the caller supplied value.
- Parameters:
- mu - The new momentum value to be set.
Connect
public void Connect(havBpLayer to,
double lo,
double hi)
- This method can be used to connect the recieving layer as input to
to another layer (to).
NOTE: This is the standard user application interface used
to connect two layers.
This method uses the Private method Connect(int nnodes, int *index_list)
to connect each node in the current layer as input to each node in the "to" layer.
- Parameters:
- to - THe layer to which this layer is to connect as input.
- lo - The low value to be used for random value weights
- hi - The high value to be used for random value weights
Connect
public void Connect(havBpLayer to)
- This method can be used to connect the recieving layer as input to
to another layer (to). In this version, all connection weights are
initialized to random values between -0.5 and +0.5
NOTE: This is the standard user application interface used
to connect two layers.
This method uses the Private method Connect(int nnodes, int *index_list)
to connect each node in the current layer as input to each node in the "to" layer.
- Parameters:
- to - THe layer to which this layer is to connect as input.
- lo - The low value to be used for random value weights
- hi - The high value to be used for random value weights
GetValue
public double GetValue(int node)
- Returns the current activation value of the specified node in the layer.
NOTE: If the specified node (indicated by an index) does not exist
in the layer, then a value of 0.0 is returned.
- Parameters:
- node - The index (from 0) of the node who's value is to be returned.
InitValue
public void InitValue(double v)
- This method will set the activation value of all nodes in the layer
to a caller supplied value.
- Parameters:
- v - The value to which all nodes in the layer are to be set.
Copy
public void Copy(havBpLayer from,
double alpha)
- This method will peform a dampened, node-to-node copy/add for each node in the
receiving layer. This means that the first node in the receiving layer will
be assigned a value from the first node in the "from" layer, the second node
from the second node, etc...
The "dampening" is accomplished by adding a percent (alpha) of the input node's
value to one minus that percentage (1-alpha) of the receiving layer's node's
current value.
if the receiving layer has fewer nodes that the "from" layer, then the number of
node-to-node copies will be limited to the number of nodes in the receiving layer.
Conversly, if there are fewer nodes in the "from" layer, then the number of
node-to node copies will be limited to the number of nodes in the "from" layer.
NOTE: No range checking is performed on the value of alpha.
- Parameters:
- from - The layer FROM whioch values are to be copied
- alpha - The "dampening" weight to be used for all copied node values
GetNodeInputWeights
public double[] GetNodeInputWeights(int n)
- Returns a pointer to the indicated node's input weight list.
If n is < 0 or >= number of nodes in the layer, then 0 is returned.
- Parameters:
- n - The index (from 0) of the node who's input weight list is to be returned.
GetNumberOfInputs
public int GetNumberOfInputs(int n)
- Returns the number of nodes connected as input to node n.
If n is < 0 or <= number_of_nodes return 0
- Parameters:
- n - The index (from 0) of the node who's number of inputs is to be returned.
Dump
public void Dump(String id)
- This method will produce a report (to stdout) of certain layer information.
- Layer Type,
- Layer Transfer function,
- Layer Beta and
- a brief dump of all nodes in the layer.
- Parameters:
- id - A name tag to be printed as the label of the layed being dumped.
PutEpochSize
public void PutEpochSize(int e)
- Sets the layer's epoch value.
- Parameters:
- e - The new eopch value to be set.
GetErrorFunction
public int GetErrorFunction()
- Returns the layer's error function
PutErrorFunction
public int PutErrorFunction(int f)
- Sets the layer's error function.
Returns havTRUE if the operation was ok.
Returns havFALSE if the indicated error function (f) was bad.
If havFALSE is returned, the current error function was not changed.
- Parameters:
- f - The error function to be set for the layer. (i.e. havSQUARED, havCUBE, havQUAD)
PutNoise
public void PutNoise(double percent)
- Sets the layer's noise level.
NOTE: This message is ignored if the layer is not of type havINPUT
- Parameters:
- percent - The amount of noise (as a percent) to be applied
ReduceNoise
public void ReduceNoise(double percent)
- This method will reduce the layer's noise level by a percentage of it's current level.
NOTE: This message is ignored if the layer is not of type havINPUT
- Parameters:
- percent - The percent of the current noise level assigned to the layer.
ReduceBeta
public void ReduceBeta(double percent)
- This method will reduce the layer's learning constant (Beta) by a percentage of it's
current level.
- Parameters:
- percent - The percent of the current learning rate assigned to the layer.
ReduceMomentum
public void ReduceMomentum(double percent)
- This method will reduce the layer's momentum by a percentage of it's current level.
- Parameters:
- percent - The percent of the current momentuml assigned to the layer.
PutErrorThreshold
public int PutErrorThreshold(double t)
- This method will set the error threshold for all nodes in the layer to a specified value.
- Parameters:
- t - The error threshold to be applied to the layer's nodes.
All Packages Class Hierarchy This Package Previous Next Index
Copyright © 1998 by hav.Software. All Rights Reserved.