com.opttek.optquest
Class COptNeuralNet

java.lang.Object
  extended by com.opttek.optquest.COptNeuralNet

public class COptNeuralNet
extends java.lang.Object

The COptNeuralNet is used to create, train, and predict an OptQuest Neural Network. Nodes are defined using COptNeuralNetNode. Arcs are defined using COptNeuralNetArc. These nodes and arcs are added to the COptNeuralNet to create the OptQuest Neural Network. The network can then be trained using OptQuest Engine techniques. Once the network is trained, the network can be used to predict outputs from inputs. The structure can be saved and read back in.


Field Summary
static int SECTION_ACTIVATION
           
static int SECTION_ARCNODENODEWEIGHT
           
static int SECTION_EPOWER
           
static int SECTION_NODELEVEL
           
static int SECTION_NUMLEVELS
           
static int SECTION_NUMNODESATLEVEL
           
static int SECTION_VERSION
           
 
Constructor Summary
COptNeuralNet()
          Default Constructor.
COptNeuralNet(int license)
           
 
Method Summary
 double ActivationFunction(COptNeuralNetNode cNode, double inputValue)
           
 void AddArc(COptNeuralNetArc arc)
          Adds an arc to the OptQuest Neural Network.
 void AddBiasNode(COptNeuralNetNode node)
          Adds a Bias node to the OptQuest Neural Network.
 void AddHiddenNode(COptNeuralNetNode node)
          Adds the input node as a hidden node.
 void AddInputNode(COptNeuralNetNode node)
          Adds the input node to the OptQuest Neural Network.
 void AddOutputNode(COptNeuralNetNode node)
          Adds the specified output node to the OptQuest Neural Network.
 void AddRandomWeights()
          AddRandomWeights() sets the random values to all of the weights in the network.
 void CreateAndAddBiasNodes()
          Allows the user to add a default bias node.
 void CreateAndAddHiddenNodes(int numNodes, int level)
          Adds default hidden nodes where each nodes uses the default activation function.
 void CreateAndAddInputNodes(int numNodes)
          Adds input nodes without creating individual objects.
 void CreateAndAddOutputNodes(int numNodes, int level)
          Adds default output nodes where each node uses the default activation function.
 void DeleteArc(COptNeuralNetArc arc)
          Deletes an arc from the OptQuest Neural Network.
 void DeleteNode(COptNeuralNetNode node)
          Deletes a node from the OptQuest Neural Network.
 void FixAllWeights(boolean val)
           
 void FullyConnectNetwork()
          Creates a fully connected default network.
 double GetBestObjectiveValue()
          GetBestObjectiveValue() gets the best objective so far.
 double GetCutOff()
           
 double GetEPower()
          GetEPower() returns the coefficient of the power for the sigmoid.
 int GetIteration()
          Deprecated. - use COptQuestOptimization.GetNumberOfCompletedIterations() GetIteration() gets the current iteration.
 int GetNumberOfCompletedIterations()
           
 int GetNumberOfHidden()
          Returns the number of total hidden nodes in the network.
 int GetNumberOfInputs()
          Returns the number of input nodes in the network.
 int GetNumberOfIterations()
          GetNumberOfIterations() returns the number of iterations set.
 int GetNumberOfOutputs()
          Returns the number of output nodes in the network.
 int GetRepeat()
          GetRepeat() gets the current repeat.
 void MonitorStatus()
          Monitor Status is used to monitor the progress of the training.
 void Predict(double[] input, double[] predict)
          Predict() predicts the outputs from the supplied inputs.
 void Predict(int numObs, double[][] input, double[][] predict)
          Predict() predicts the outputs from the supplied inputs.
 void ReadNetworkDefinition(java.lang.String filename)
          ReadNetworkDefinition() reads the network definition from a file and creates the network from the information provided in the file.
 void SetCutOff(double cutOff)
           
 void SetDefaultActivation(int useActivationFunction)
          SetDefaultActivation() sets the default activation function for the OptQuest Neural Network.
 void SetEPower(double power)
          SetEPower() sets the coefficient of the power for the sigmoid.
 void SetInputScale()
          SetInputScale() sets the scaling of the input to a [0,1] value based on the minimum/maximum values in the training set.
 void SetLicense(int license)
           
 void SetLowerBound(double lowerBound)
          SetLowerBound() sets the lower bound of the weights.
 void SetMeanErrorPower(double val)
          SetMeanErrorPower() sets the power to which the absolute difference is raised when calculating the objective for the training.
 void SetOptimizeCutOff(double lowerbound, double upperbound)
          SetOptimizePower() indicates to optimize the power coefficient during training.
 void SetOptimizePower(double lowerbound, double upperbound)
          SetOptimizePower() indicates to optimize the power coefficient during training.
 void SetOutputNodesToBinary(double cutoff)
          Sets all output nodes to use the binary activation function.
 void SetOutputScale()
          SetOutputScale() sets the scaling of the output to a [0,1] value based on the minimum/maximum values in the training set.
 void SetRegressionForLastLevel(boolean bUseRgr)
          SetRegressionForLastLevel() sets whether or not to use linear regression for the arc weights coming into the output nodes.
 void SetRepeat(int repeat)
          SetRepeat() repeats the training for the given number of times (default = 1).
 void SetStoppingRuleError(double val)
          SetStoppingRuleError() sets the error for which the training stops before the number of iterations is complete().
 void SetStoppingRuleIterations(int iterations)
          SetStoppingRuleIterations() sets the number of iterations to run during training.
 void SetTrainingSetMemory(int numObs, double[][] inputMatrix, double[][] expectedMatrix, double[][] predictedMatrix)
          SetInputTypeMemory() sets the training set input.
 void SetTrainingTypeAll()
          SetTrainingTypeAll() trains all non-fixed weights.
 void SetTrainingTypeLevel()
          SetTrainingTypeLevel() trains each all non-fixed weights at each level, starting at the outputs.
 void SetTrainingTypeNode()
          SetTrainingTypeNode() trains each all non-fixed weights coming in to each node, node by node.
 void SetTrainingTypeNodeRandom()
          SetTrainingTypeNodeRandom() trains each all non-fixed weights coming in to each node, node by node in a random order.
 void SetTrainingTypeRandom(int numWeights)
          SetTrainingTypeRandom() randomly selects "numWeights" number of non-fixed weights to train.
 void SetUpperBound(double upperBound)
          SetUpperBound() sets the upper bound of the weights.
 void Stop()
          Stop() stops the training.
 void Train()
          Train() trains the network based on the training parameters set.
 void WriteNetworkDefinition(java.lang.String filename)
          WriteNetworkDefinition() writes the network definition into a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECTION_VERSION

public static final int SECTION_VERSION
See Also:
Constant Field Values

SECTION_NUMLEVELS

public static final int SECTION_NUMLEVELS
See Also:
Constant Field Values

SECTION_NUMNODESATLEVEL

public static final int SECTION_NUMNODESATLEVEL
See Also:
Constant Field Values

SECTION_NODELEVEL

public static final int SECTION_NODELEVEL
See Also:
Constant Field Values

SECTION_ARCNODENODEWEIGHT

public static final int SECTION_ARCNODENODEWEIGHT
See Also:
Constant Field Values

SECTION_ACTIVATION

public static final int SECTION_ACTIVATION
See Also:
Constant Field Values

SECTION_EPOWER

public static final int SECTION_EPOWER
See Also:
Constant Field Values
Constructor Detail

COptNeuralNet

public COptNeuralNet()
Default Constructor.


COptNeuralNet

public COptNeuralNet(int license)
Method Detail

SetLicense

public void SetLicense(int license)

CreateAndAddInputNodes

public void CreateAndAddInputNodes(int numNodes)
                            throws COptNeuralNetException
Adds input nodes without creating individual objects. Default nodes are creates whic use the default activation function and are at level 1.

Parameters:
numNodes - - the number of input nodes.
Throws:
COptNeuralNetException

CreateAndAddBiasNodes

public void CreateAndAddBiasNodes()
                           throws COptNeuralNetException
Allows the user to add a default bias node. The node is at level 1.

Throws:
COptNeuralNetException

CreateAndAddHiddenNodes

public void CreateAndAddHiddenNodes(int numNodes,
                                    int level)
                             throws COptNeuralNetException
Adds default hidden nodes where each nodes uses the default activation function.

Parameters:
numNodes - - the number of hidden nodes.
level - - the level of hidden nodes.
Throws:
COptNeuralNetException

CreateAndAddOutputNodes

public void CreateAndAddOutputNodes(int numNodes,
                                    int level)
                             throws COptNeuralNetException
Adds default output nodes where each node uses the default activation function.

Parameters:
numNodes - - the number of hidden nodes.
level - - the level of hidden nodes.
Throws:
COptNeuralNetException

SetOutputNodesToBinary

public void SetOutputNodesToBinary(double cutoff)
Sets all output nodes to use the binary activation function.

Parameters:
cutoff - - the cut off value between 0 and 1.

FixAllWeights

public void FixAllWeights(boolean val)

FullyConnectNetwork

public void FullyConnectNetwork()
Creates a fully connected default network.


AddInputNode

public void AddInputNode(COptNeuralNetNode node)
                  throws COptNeuralNetException
Adds the input node to the OptQuest Neural Network. The node contains the information about the level, type, etc.

Parameters:
node - - the node to add to the network.
Throws:
COptNeuralNetException

AddHiddenNode

public void AddHiddenNode(COptNeuralNetNode node)
                   throws COptNeuralNetException
Adds the input node as a hidden node. The node contains the information about the level, type, etc.

Parameters:
node - - the node to add to the network.
Throws:
COptNeuralNetException

AddOutputNode

public void AddOutputNode(COptNeuralNetNode node)
                   throws COptNeuralNetException
Adds the specified output node to the OptQuest Neural Network. The node contains the information about the level, type, etc.

Parameters:
node - - the node to add to the network.
Throws:
COptNeuralNetException

AddBiasNode

public void AddBiasNode(COptNeuralNetNode node)
                 throws COptNeuralNetException
Adds a Bias node to the OptQuest Neural Network. The node contains the information about the level, type, etc.

Parameters:
node - - the node to add to the network.
Throws:
COptNeuralNetException

DeleteNode

public void DeleteNode(COptNeuralNetNode node)
Deletes a node from the OptQuest Neural Network.

Parameters:
node - - the node to remove from the network.

GetNumberOfInputs

public int GetNumberOfInputs()
Returns the number of input nodes in the network.


GetNumberOfOutputs

public int GetNumberOfOutputs()
Returns the number of output nodes in the network.


GetNumberOfHidden

public int GetNumberOfHidden()
Returns the number of total hidden nodes in the network.


AddArc

public void AddArc(COptNeuralNetArc arc)
            throws COptNeuralNetException
Adds an arc to the OptQuest Neural Network. The arc contains the information about the from/to nodes and the weight.

Parameters:
arc - - the arc to add to the network.
Throws:
COptNeuralNetException

DeleteArc

public void DeleteArc(COptNeuralNetArc arc)
Deletes an arc from the OptQuest Neural Network.

Parameters:
arc - - the arc to delete from the network.

ActivationFunction

public double ActivationFunction(COptNeuralNetNode cNode,
                                 double inputValue)
                          throws COptNeuralNetException
Throws:
COptNeuralNetException

Predict

public void Predict(int numObs,
                    double[][] input,
                    double[][] predict)
             throws COptNeuralNetException
Predict() predicts the outputs from the supplied inputs.

Parameters:
numObs - - number of observations in the input matrix
input - - input matrix of input values. The first index is the observation (0 to numObs-1). The second index is the input node (1 to Number of Input Nodes). The order is the same as they were added to the network.
predict - - output matrix of predicted values. The first index is the observation (0 to numObs-1). The second index is the output node (1 to Number of Output Nodes). The order is the same as they were added to the network.
Throws:
COptNeuralNetException

Predict

public void Predict(double[] input,
                    double[] predict)
             throws COptNeuralNetException
Predict() predicts the outputs from the supplied inputs.

Parameters:
input - - input array of input values. The index is the input node (1 to Number of Input Nodes). The order is the same as they were added to the network.
predict - - output matrix of predicted values. The index is the output node (1 to Number of Output Nodes). The order is the same as they were added to the network.
Throws:
COptNeuralNetException

SetDefaultActivation

public void SetDefaultActivation(int useActivationFunction)
SetDefaultActivation() sets the default activation function for the OptQuest Neural Network.

Parameters:
useActivationFunction -
  • COptNeuralNetNode.SIGMOID01ACTIVATION. The network uses the [0,1] sigmoid function as the activation function.
  • COptNeuralNetNode.SIGMOIDNEG11ACTIVATION. The network uses the [-1,1] sigmoid function as the activation function.
  • COptNeuralNetNode.IDENTITYACTIVATION. The network uses the identity function as the activation function. No function is applied to the value.

SetCutOff

public void SetCutOff(double cutOff)

GetCutOff

public double GetCutOff()

SetEPower

public void SetEPower(double power)
SetEPower() sets the coefficient of the power for the sigmoid. Changing the power coefficient changes the slope of the sigmoid. Default value is 1.

Parameters:
power - - new power coefficient

GetEPower

public double GetEPower()
GetEPower() returns the coefficient of the power for the sigmoid.


SetOptimizePower

public void SetOptimizePower(double lowerbound,
                             double upperbound)
SetOptimizePower() indicates to optimize the power coefficient during training.

Parameters:
lowerbound - - lower bound of the power coefficient.
upperbound - - upper bound of the power coefficient.

SetOptimizeCutOff

public void SetOptimizeCutOff(double lowerbound,
                              double upperbound)
SetOptimizePower() indicates to optimize the power coefficient during training.

Parameters:
lowerbound - - lower bound of the power coefficient.
upperbound - - upper bound of the power coefficient.

ReadNetworkDefinition

public void ReadNetworkDefinition(java.lang.String filename)
                           throws COptNeuralNetException
ReadNetworkDefinition() reads the network definition from a file and creates the network from the information provided in the file.

Parameters:
filename - - filename containing the network definition.
Throws:
COptNeuralNetException

WriteNetworkDefinition

public void WriteNetworkDefinition(java.lang.String filename)
                            throws COptNeuralNetException
WriteNetworkDefinition() writes the network definition into a file. This file can later be read in via ReadNetworkDefinition() for predicting or for further training.

Parameters:
filename - - filename containing the network definition.
Throws:
COptNeuralNetException

Stop

public void Stop()
Stop() stops the training.


AddRandomWeights

public void AddRandomWeights()
                      throws COptQuestException
AddRandomWeights() sets the random values to all of the weights in the network.

Throws:
COptQuestException

Train

public void Train()
           throws COptNeuralNetException,
                  COptQuestException
Train() trains the network based on the training parameters set.

Throws:
COptNeuralNetException
COptQuestException

SetTrainingTypeRandom

public void SetTrainingTypeRandom(int numWeights)
SetTrainingTypeRandom() randomly selects "numWeights" number of non-fixed weights to train. Weights can be fixed by the user or by the use of regression.

Parameters:
numWeights -

SetTrainingTypeAll

public void SetTrainingTypeAll()
SetTrainingTypeAll() trains all non-fixed weights. Weights can be fixed by the user or by the use of regression.


SetTrainingTypeNode

public void SetTrainingTypeNode()
SetTrainingTypeNode() trains each all non-fixed weights coming in to each node, node by node. Weights can be fixed by the user or by the use of regression. If all weights coming into a node is fixed, that node is skipped.


SetTrainingTypeNodeRandom

public void SetTrainingTypeNodeRandom()
SetTrainingTypeNodeRandom() trains each all non-fixed weights coming in to each node, node by node in a random order. Weights can be fixed by the user or by the use of regression. If all weights coming into a node is fixed, that node is skipped.


SetTrainingTypeLevel

public void SetTrainingTypeLevel()
SetTrainingTypeLevel() trains each all non-fixed weights at each level, starting at the outputs. Weights can be fixed by the user or by the use of regression. If all weights at a level is fixed, that level is skipped.


SetStoppingRuleIterations

public void SetStoppingRuleIterations(int iterations)
SetStoppingRuleIterations() sets the number of iterations to run during training. If the training is by node or by level, this is the number of iterations at each node/level.

Parameters:
iterations - - number of iterations to run

SetRepeat

public void SetRepeat(int repeat)
SetRepeat() repeats the training for the given number of times (default = 1).

Parameters:
repeat -

GetNumberOfIterations

public int GetNumberOfIterations()
GetNumberOfIterations() returns the number of iterations set.

Returns:
number of iterations set.

SetTrainingSetMemory

public void SetTrainingSetMemory(int numObs,
                                 double[][] inputMatrix,
                                 double[][] expectedMatrix,
                                 double[][] predictedMatrix)
SetInputTypeMemory() sets the training set input.

Parameters:
numObs - - number of Observations in the input/outputs
inputMatrix - - matrix containing input values. First index is the observation (0 to numObs-1). Second index is the input values (1 to number of input nodes).
expectedMatrix - - matrix containing expected values. First index is the observation (0 to numObs-1). Second index is the output values (1 to number of output nodes).
predictedMatrix - - temporary matrix to place predicted values. First index is the observation (0 to numObs-1). Second index is the output values (1 to number of output nodes).

SetInputScale

public void SetInputScale()
SetInputScale() sets the scaling of the input to a [0,1] value based on the minimum/maximum values in the training set.


SetOutputScale

public void SetOutputScale()
SetOutputScale() sets the scaling of the output to a [0,1] value based on the minimum/maximum values in the training set.


SetRegressionForLastLevel

public void SetRegressionForLastLevel(boolean bUseRgr)
SetRegressionForLastLevel() sets whether or not to use linear regression for the arc weights coming into the output nodes.

Parameters:
bUseRgr - -true/false

MonitorStatus

public void MonitorStatus()
Monitor Status is used to monitor the progress of the training. GetIteration() can be called to get the current iteration. GetRepeat() can be called to get the current repeat. GetBestObjectiveValue() can be called to get the best objective so far.


GetRepeat

public int GetRepeat()
GetRepeat() gets the current repeat.

Returns:
repeat number from 1 to number of repeats.

GetIteration

public int GetIteration()
                 throws COptQuestException
Deprecated. - use COptQuestOptimization.GetNumberOfCompletedIterations() GetIteration() gets the current iteration.

Returns:
iteration number from 1 to number of iteration.
Throws:
COptQuestException

GetNumberOfCompletedIterations

public int GetNumberOfCompletedIterations()

GetBestObjectiveValue

public double GetBestObjectiveValue()
                             throws COptQuestException
GetBestObjectiveValue() gets the best objective so far.

Returns:
best objective so far.
Throws:
COptQuestException

SetUpperBound

public void SetUpperBound(double upperBound)
SetUpperBound() sets the upper bound of the weights.

Parameters:
upperBound - - upper bound of the weights.

SetLowerBound

public void SetLowerBound(double lowerBound)
SetLowerBound() sets the lower bound of the weights.

Parameters:
lowerBound - - lower bound of the weights.

SetMeanErrorPower

public void SetMeanErrorPower(double val)
SetMeanErrorPower() sets the power to which the absolute difference is raised when calculating the objective for the training.

Parameters:
val - - power

SetStoppingRuleError

public void SetStoppingRuleError(double val)
SetStoppingRuleError() sets the error for which the training stops before the number of iterations is complete().

Parameters:
val - - error to stop upon reaching