Class NNeco

java.lang.Object
  |
  +--NNeco

public class NNeco
extends java.lang.Object

NNeco.java
Title : Learning Industry with ANN based GenFirms
Description : A simple back propagation feed forward neural network adapted for being driven by another user class. It has only one hidden layer.
Adapted with corrections from the Neural class by Mark Watson, 1997, Intelligent Java Applications, Morgan Kaufmann, SF:CA. My modifications are based on T. Masters, 1993, Practical Neural Recipes in C++, Academic Press, San Diego: CA. The later is a very nice reference on ANNs.
Copyright : Copyright (c) Murat Yildizoglu August 2001
Permission to use, copy, modify, and distribute this
software and its documentation for NON-COMMERCIAL purposes
and without fee is hereby granted provided that this
copyright notice appears in all copies.
*************************************************************

Version:
1.0 August 2001
Author:
Murat Yildizoglu

Field Summary
protected  double[] Hidden
           
protected  double[] hidden_errors
           
 double[] Inputs
           
protected  int NumHidden
           
protected  int NumInputs
           
protected  int NumOutputs
           
protected  int NumTraining
           
protected  double[] output_errors
           
 double[] Outputs
           
protected  double[][] W1
           
protected  double[][] W2
           
 
Constructor Summary
NNeco()
          The default constructor.
NNeco(int i, int h, int o)
          The constructor that should be used for creating a new network
 
Method Summary
 void forwardPass()
          Calculates outputs with actual weights and input vector.
 double[] getOutputs()
          This method returns the actual values of the outputs resulting from the last forward pass.
 double getTotalOutputError()
          Returns the total error in the last training sesssion
 double[] infer(double[] inputs)
          This is the method for obtaining predictions from the network.
 void randomizeWeights()
          Puts randomly chosen values to all weights
 void setInputs(double[] inputs)
          This method uses the provided one-dimensional array for setting the values of the inputs
protected  double Sigmoid(double x)
          The sigmoid function used for activation
protected  double SigmoidP(double x)
          The derivative of the sigmoid function.
 void Train(double[][] ins, double[][] outs, int numEpoch, int numCases, int winSize)
          Takes the data in a more standard two dimensional table and adapts it for using in the real train method.
 double Train(double[] ins, double[] outs, int num_cases)
          This method is called by the preceding Train method, it should not be directly called.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NumInputs

protected int NumInputs

NumHidden

protected int NumHidden

NumOutputs

protected int NumOutputs

NumTraining

protected int NumTraining

Inputs

public double[] Inputs

Hidden

protected double[] Hidden

Outputs

public double[] Outputs

W1

protected double[][] W1

W2

protected double[][] W2

output_errors

protected double[] output_errors

hidden_errors

protected double[] hidden_errors
Constructor Detail

NNeco

public NNeco()
The default constructor. Not very useful.

NNeco

public NNeco(int i,
             int h,
             int o)
The constructor that should be used for creating a new network
Parameters:
i - number of inputs
h - number of hidden nodes on the hidden layer
o - number of outputs
Method Detail

randomizeWeights

public void randomizeWeights()
Puts randomly chosen values to all weights

forwardPass

public void forwardPass()
Calculates outputs with actual weights and input vector. The inputs must be set with the Train or setInputs methods.

Train

public void Train(double[][] ins,
                  double[][] outs,
                  int numEpoch,
                  int numCases,
                  int winSize)
Takes the data in a more standard two dimensional table and adapts it for using in the real train method.
Parameters:
ins - two-dimensional table where each case is a line of input values
outs - two-dimensional table where each case is a line of output values
numEpoch - the number of runs in each epoch
numCases - the size of the epoch (number of training cases)
winSize - the number of observations to use from the end of the tables. 0 means all observations.

Train

public double Train(double[] ins,
                    double[] outs,
                    int num_cases)
This method is called by the preceding Train method, it should not be directly called.

infer

public double[] infer(double[] inputs)
This is the method for obtaining predictions from the network. It gives the provided values to the inputs, runs through the network (forward pass) and returns an array containing the values of all outputs.
Parameters:
inputs - a one-dimensional array that contains the vector of input values

getOutputs

public double[] getOutputs()
This method returns the actual values of the outputs resulting from the last forward pass.

getTotalOutputError

public double getTotalOutputError()
Returns the total error in the last training sesssion

setInputs

public void setInputs(double[] inputs)
This method uses the provided one-dimensional array for setting the values of the inputs
Parameters:
inputs - a one-dimensional array of iputs values.

Sigmoid

protected double Sigmoid(double x)
The sigmoid function used for activation
Parameters:
x -  

SigmoidP

protected double SigmoidP(double x)
The derivative of the sigmoid function. It is used during the bacward propagation of errors
Parameters:
x -