Venice 0.751beta

nz.org.venice.analyser.ann
Class ArtificialNeuralNetwork

java.lang.Object
  extended bynz.org.venice.analyser.ann.ArtificialNeuralNetwork
All Implemented Interfaces:
java.util.EventListener, org.joone.engine.NeuralNetListener

public class ArtificialNeuralNetwork
extends java.lang.Object
implements org.joone.engine.NeuralNetListener

Author:
Alberto Nacher

Field Summary
static double HIGH_BOOL
           
static double LOW_BOOL
           
static int OUTPUT_BUY
           
static int OUTPUT_NEURONS
           
static int OUTPUT_SELL
           
 
Constructor Summary
ArtificialNeuralNetwork(javax.swing.JDesktopPane desktop)
          Create a new instance of ArtificialNeuralNetwork class.
 
Method Summary
 void cicleTerminated(org.joone.engine.NeuralNetEvent e)
           
 void errorChanged(org.joone.engine.NeuralNetEvent e)
           
 boolean isANNNull()
          Return true if nnet neural network is null or if it has no valid input/output layers.
 boolean isInputOK(int inputRows)
          Check if the actual neural network has the same of input neurons as given.
 boolean isOutputOK()
          Check if the actual neural network has a number of output neurons as desired.
 boolean isSaved()
          Get the network status (saved/not saved).
 void loadNeuralNet(java.lang.String fileName)
          Load the neural network from a snet/xml file into the nnet object.
 void netStarted(org.joone.engine.NeuralNetEvent e)
           
 void netStopped(org.joone.engine.NeuralNetEvent e)
           
 void netStoppedError(org.joone.engine.NeuralNetEvent e, java.lang.String error)
           
 boolean[] run(double[] inputDoubles)
          Run the current nnet neural network.
 void runTraining(double[][] inputArray, double[][] outputDesiredArray, double newLearningRate, double newMomentum, int newPreLearning, int newTotCicles, int newTrainingPatterns)
          Trains the current nnet neural network.
 void saveNeuralNet(java.lang.String fileName)
          Save the nnet neural network in a snet/xml file.
 void setANNInput(int inputRows)
          Recalculate the inputs so that they fit with input expressions.
 void setANNNull()
          Set the ANN to null.
 void setANNOutput()
          Recalculate the outputs so that they fit with number of buy/sell signals.
 void setBuyThreshold(double buyThreshold)
          Set the buy threshold.
 void setDefaultANN(int inputRows)
          Set a default artificial neural network with the following characteristics: - input layer defined as LinearLayer (see Joone documentation for details) - hidden layer defined as SigmoidLayer (see Joone documentation for details) - output layer defined as SigmoidLayer (see Joone documentation for details).
 void setProgressBar(ProgressDialog progress)
          Set the progress bar, so that we can manage it when cycle terminated event is raised.
 void setSellThreshold(double sellThreshold)
          Set the sell threshold.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTPUT_BUY

public static final int OUTPUT_BUY
See Also:
Constant Field Values

OUTPUT_SELL

public static final int OUTPUT_SELL
See Also:
Constant Field Values

OUTPUT_NEURONS

public static final int OUTPUT_NEURONS
See Also:
Constant Field Values

HIGH_BOOL

public static final double HIGH_BOOL
See Also:
Constant Field Values

LOW_BOOL

public static final double LOW_BOOL
See Also:
Constant Field Values
Constructor Detail

ArtificialNeuralNetwork

public ArtificialNeuralNetwork(javax.swing.JDesktopPane desktop)
Create a new instance of ArtificialNeuralNetwork class.

Parameters:
desktop - the desktop
Method Detail

run

public boolean[] run(double[] inputDoubles)
Run the current nnet neural network.

Parameters:
inputDoubles - an array of input values of the artificial neural network
Returns:
an array with output values, returnValue[OUTPUT_BUY] is the buy signal returned, returnValue[OUTPUT_SELL] is the sell signal returned.

runTraining

public void runTraining(double[][] inputArray,
                        double[][] outputDesiredArray,
                        double newLearningRate,
                        double newMomentum,
                        int newPreLearning,
                        int newTotCicles,
                        int newTrainingPatterns)
Trains the current nnet neural network.

Parameters:
inputArray - an array of input values of the artificial neural network
outputDesiredArray - an array of desired output values of the artificial neural network

setProgressBar

public void setProgressBar(ProgressDialog progress)
Set the progress bar, so that we can manage it when cycle terminated event is raised.

Parameters:
progress - the progress bar shown to the user during training.

setANNNull

public void setANNNull()
Set the ANN to null.


isANNNull

public boolean isANNNull()
Return true if nnet neural network is null or if it has no valid input/output layers.

Returns:
true as described above, otherwise false.

setBuyThreshold

public void setBuyThreshold(double buyThreshold)
Set the buy threshold. The buy output signal fires only if the value is higher than this threshold .

Parameters:
buyThreshold - the buy threshold.

setSellThreshold

public void setSellThreshold(double sellThreshold)
Set the sell threshold. The sell output signal fires only if the value is higher than this threshold .

Parameters:
sellThreshold - the sell threshold.

isSaved

public boolean isSaved()
Get the network status (saved/not saved).

Returns:
network status (true = is saved, false = is not saved)

loadNeuralNet

public void loadNeuralNet(java.lang.String fileName)
                   throws FileExtensionException,
                          java.io.FileNotFoundException,
                          java.io.IOException,
                          java.lang.NullPointerException,
                          java.lang.SecurityException
Load the neural network from a snet/xml file into the nnet object. the file must contain a serialized version of a neural network.

Parameters:
fileName - the file name where nnet will be saved
Throws:
FileExtensionException
java.io.FileNotFoundException
java.io.IOException
java.lang.NullPointerException
java.lang.SecurityException

saveNeuralNet

public void saveNeuralNet(java.lang.String fileName)
                   throws FileExtensionException,
                          java.io.FileNotFoundException,
                          java.io.IOException,
                          java.lang.NullPointerException,
                          java.lang.SecurityException
Save the nnet neural network in a snet/xml file. nnet serialization takes place.

Parameters:
fileName - the file name where nnet will be saved
Throws:
FileExtensionException
java.io.FileNotFoundException
java.io.IOException
java.lang.NullPointerException
java.lang.SecurityException

setDefaultANN

public void setDefaultANN(int inputRows)
Set a default artificial neural network with the following characteristics: - input layer defined as LinearLayer (see Joone documentation for details) - hidden layer defined as SigmoidLayer (see Joone documentation for details) - output layer defined as SigmoidLayer (see Joone documentation for details). The input layer has a number of neurons equal to the input parameter inputRows, which is the number of input defined in the ANN Page user interface. The hidden layer has a number of neurons equal to the max between three times the input and five times the output. The reason for that is having a enough balanced ANN. The output has a number of neurons equal to two. One output is a signal to buy, the other is a signal to sell.

Parameters:
inputRows - the input of the neural network

setANNInput

public void setANNInput(int inputRows)
Recalculate the inputs so that they fit with input expressions.

Parameters:
inputRows - the inputs of the neural network to be set

setANNOutput

public void setANNOutput()
Recalculate the outputs so that they fit with number of buy/sell signals. Now we have only 2 output signal (one for buy signal and another for sell signal).


isInputOK

public boolean isInputOK(int inputRows)
Check if the actual neural network has the same of input neurons as given.

Parameters:
inputRows - number of input rows of ANN to be checked
Returns:
if the actual number of input neurons is equal to inputRows, it returns true.

isOutputOK

public boolean isOutputOK()
Check if the actual neural network has a number of output neurons as desired.

Returns:
if the actual number of output neurons is equal to what desired, it returns true.

cicleTerminated

public void cicleTerminated(org.joone.engine.NeuralNetEvent e)
Specified by:
cicleTerminated in interface org.joone.engine.NeuralNetListener

errorChanged

public void errorChanged(org.joone.engine.NeuralNetEvent e)
Specified by:
errorChanged in interface org.joone.engine.NeuralNetListener

netStarted

public void netStarted(org.joone.engine.NeuralNetEvent e)
Specified by:
netStarted in interface org.joone.engine.NeuralNetListener

netStopped

public void netStopped(org.joone.engine.NeuralNetEvent e)
Specified by:
netStopped in interface org.joone.engine.NeuralNetListener

netStoppedError

public void netStoppedError(org.joone.engine.NeuralNetEvent e,
                            java.lang.String error)
Specified by:
netStoppedError in interface org.joone.engine.NeuralNetListener

Venice 0.751beta