NeuralNetwork
jhpro.nnet

Class NeuralNetwork

    • Nested Class Summary

      Nested Classes 
      Modifier and TypeClass and Description
      static class NeuralNetwork.Backup
      Class Backup is an opaque class that encapsulates a snapshot of a NeuralNetwork internal memory (its weights).
      static interface NeuralNetwork.Monitor
      Interface Monitor allows to plug a monitor to a Neural Network instance, and inform the monitor about the progress of the training activity.
    • Constructor Summary

      Constructors 
      Constructor and Description
      NeuralNetwork(int inputSize, int hiddenSize, int outputSize, double amplitude, String[] inputLabels, String[] outputLabels)
      Create a neural network, with specified number of cells in each layer, and default values.
      NeuralNetwork(int inputSize, int hiddenSize, int outputSize, double amplitude, String[] inputLabels, String[] outputLabels, double learningRate, double momentum, double maxError, int epochs)
      Create a neural network, with specified number of cells in each layer, and specific parameters
    • Constructor Detail

      • NeuralNetwork

        public NeuralNetwork(int inputSize,             int hiddenSize,             int outputSize,             double amplitude,             String[] inputLabels,             String[] outputLabels)
        Create a neural network, with specified number of cells in each layer, and default values.
        Parameters:
        inputSize - number of cells in input layer
        hiddenSize - number of cells in hidden layer
        outputSize - number of cells in output layer
        amplitude - amplitude (<=1.0) for initial random values
        inputLabels - array of labels for input cells, or null
        outputLabels - array of labels for output cells, or null
      • NeuralNetwork

        public NeuralNetwork(int inputSize,             int hiddenSize,             int outputSize,             double amplitude,             String[] inputLabels,             String[] outputLabels,             double learningRate,             double momentum,             double maxError,             int epochs)
        Create a neural network, with specified number of cells in each layer, and specific parameters
        Parameters:
        inputSize - number of cells in input layer
        hiddenSize - number of cells in hidden layer
        outputSize - number of cells in output layer
        amplitude - amplitude ( <= 1.0) for initial random values
        inputLabels - array o f labels for input cells, or null
        outputLabels - array of labels for output cells, or null
        learningRate - learning rate factor
        momentum - momentum from last adjustment
        maxError - threshold to stop training
        epochs - number of epochs in training
    • Method Detail

      • unmarshal

        public static NeuralNetwork unmarshal(InputStream in)                               throws JAXBException
        Unmarshal the provided XML stream to allocate the corresponding NeuralNetwork.
        Parameters:
        in - the input stream that contains the network definition in XML format. The stream is not closed by this method
        Returns:
        the allocated network.
        Throws:
        JAXBException - raised when unmarshalling goes wrong
      • backup

        public NeuralNetwork.Backup backup()
        Return a backup of the internal memory of this network. Generally used right after network creation to save the initial conditions.
        Returns:
        an opaque copy of the network memory
      • dump

        public void dump()
        Dumps the network
      • getHiddenSize

        public int getHiddenSize()
        Report the number of cells in the hidden layer
        Returns:
        the size of the hidden layer
      • getInputLabels

        public String[] getInputLabels()
        Report the input labels, if any.
        Returns:
        the inputLabels, perhaps null
      • getInputSize

        public int getInputSize()
        Report the number of cells in the input layer
        Returns:
        the size of input layer
      • getOutputLabels

        public String[] getOutputLabels()
        Report the output labels, if any.
        Returns:
        the outputLabels, perhaps null
      • getOutputSize

        public int getOutputSize()
        Report the size of the output layer
        Returns:
        the number of cells in the output layer
      • marshal

        public void marshal(OutputStream os)             throws JAXBException
        Marshal the NeuralNetwork to its XML file
        Parameters:
        os - the XML output stream, which is not closed by this method
        Throws:
        JAXBException - raised when marshalling goes wrong
      • restore

        public void restore(NeuralNetwork.Backup backup)
        Restore the internal memory of a Network, from a previous Backup. This does not reset the current parameters such as learning rate, momentum, maxError or epochs.
        Parameters:
        backup - a backup previously made
      • run

        public double[] run(double[] inputs,           double[] hiddens,           double[] outputs)
        Run the neural network on an array of input values, and return the computed output values. This method writes into the hiddens buffer.
        Parameters:
        inputs - the provided input values
        hiddens - provided buffer for hidden values, or null
        outputs - preallocated array for the computed output values, or null if not already allocated
        Returns:
        the computed output values
      • setEpochs

        public void setEpochs(int epochs)
        Set the number of iterations for training the network with a given input.
        Parameters:
        epochs - number of iterations
      • setLearningRate

        public void setLearningRate(double learningRate)
        Set the learning rate.
        Parameters:
        learningRate - the learning rate to use for each iteration (typically in the 0.0 .. 1.0 range)
      • setMaxError

        public void setMaxError(double maxError)
        Set the maximum error level.
        Parameters:
        maxError - maximum error
      • setMomentum

        public void setMomentum(double momentum)
        Set the momentum value.
        Parameters:
        momentum - the fraction of previous move to be reported on the next correction
      • stop

        public void stop()
        A means to externally stop the current training.
      • train

        public double train(double[][] inputs,           double[][] desiredOutputs,           NeuralNetwork.Monitor monitor)
        Train the neural network on a collection of input patterns, so that it delivers the expected outputs within maxError. This method is not optimized for absolute speed, but rather for being able to keep the best weights values.
        Parameters:
        inputs - the provided patterns of values for input cells
        desiredOutputs - the corresponding desired values for output cells
        monitor - a monitor interface to be kept informed (or null)
        Returns:
        mse, the final mean square error

SCaVis 2.1 © jWork.ORG