weka.classifiers.functions.neural
Class NeuralConnection

java.lang.Object
  extended byweka.classifiers.functions.neural.NeuralConnection
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MultilayerPerceptron.NeuralEnd, NeuralNode

public abstract class NeuralConnection
extends java.lang.Object
implements java.io.Serializable

Abstract unit in a NeuralNetwork.

Version:
$Revision: 1.4 $
Author:
Malcolm Ware (mfw4@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
static int CONNECTED
          This flag is set once the unit has a connection.
static int INPUT
          This unit is an input unit.
protected  java.lang.String m_id
          The string that uniquely (provided naming is done properly) identifies this unit.
protected  NeuralConnection[] m_inputList
          The list of inputs to this unit.
protected  int[] m_inputNums
          The numbering for the connections at the other end of the input lines.
protected  int m_numInputs
          The number of inputs.
protected  int m_numOutputs
          The number of outputs.
protected  NeuralConnection[] m_outputList
          The list of outputs from this unit.
protected  int[] m_outputNums
          The numbering for the connections at the other end of the out lines.
protected  int m_type
          The type of unit this is.
protected  double m_unitError
          The error value for this unit, NaN if not calculated.
protected  double m_unitValue
          The output value for this unit, NaN if not calculated.
protected  boolean m_weightsUpdated
          True if the weights have already been updated.
protected  double m_x
          The x coord of this unit purely for displaying purposes.
protected  double m_y
          The y coord of this unit purely for displaying purposes.
static int OUTPUT
          This unit is an output unit.
static int PURE_INPUT
          This unit is a pure input unit.
static int PURE_OUTPUT
          This unit is a pure output unit.
static int UNCONNECTED
          This unit is not connected to any others.
 
Constructor Summary
NeuralConnection(java.lang.String id)
          Constructs The unit with the basic connection information prepared for use.
 
Method Summary
protected  void allocateInputs()
          This will allocate more space for input connection information if the arrays for this have been filled up.
protected  void allocateOutputs()
          Allocates more space for output connection information if the arrays have been filled up.
protected  void changeInputNum(int n, int v)
          Changes the connection value information for one of the connections.
protected  void changeOutputNum(int n, int v)
          Changes the connection value information for one of the connections.
static boolean connect(NeuralConnection s, NeuralConnection t)
          Connects two units together.
protected  boolean connectInput(NeuralConnection i, int n)
          This will connect the specified unit to be an input to this unit.
protected  boolean connectOutput(NeuralConnection o, int n)
          This will connect the specified unit to be an output to this unit.
static boolean disconnect(NeuralConnection s, NeuralConnection t)
          Disconnects two units.
protected  boolean disconnectInput(NeuralConnection i, int n)
          This will disconnect the input with the specific connection number From this node (only on this end however).
protected  boolean disconnectOutput(NeuralConnection o, int n)
          This will disconnect the output with the specific connection number From this node (only on this end however).
 void drawHighlight(java.awt.Graphics g, int w, int h)
          Call this function to draw the node highlighted.
 void drawInputLines(java.awt.Graphics g, int w, int h)
          Call this function to draw the nodes input connections.
 void drawNode(java.awt.Graphics g, int w, int h)
          Call this function to draw the node.
 void drawOutputLines(java.awt.Graphics g, int w, int h)
          Call this function to draw the nodes output connections.
abstract  double errorValue(boolean calculate)
          Call this to get the error value of this unit.
 java.lang.String getId()
           
 int[] getInputNums()
          Use this to get easy access to the input numbers.
 NeuralConnection[] getInputs()
          Use this to get easy access to the inputs.
 int getNumInputs()
           
 int getNumOutputs()
           
 int[] getOutputNums()
          Use this to get easy access to the output numbers.
 NeuralConnection[] getOutputs()
          Use this to get easy access to the outputs.
 int getType()
           
 double getX()
           
 double getY()
           
 boolean onUnit(java.awt.Graphics g, int x, int y, int w, int h)
          Call this function to determine if the point at x,y is on the unit.
abstract  double outputValue(boolean calculate)
          Call this to get the output value of this unit.
 void removeAllInputs()
          This function will remove all the inputs to this unit.
 void removeAllOutputs()
          This function will remove all outputs to this unit.
abstract  void reset()
          Call this to reset the unit for another run.
 void setType(int t)
           
 void setX(double x)
           
 void setY(double y)
           
 void updateWeights(double l, double m)
          Call this function to update the weight values at this unit.
 double weightValue(int n)
          Call this to get the weight value on a particular connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNCONNECTED

public static final int UNCONNECTED
This unit is not connected to any others.

See Also:
Constant Field Values

PURE_INPUT

public static final int PURE_INPUT
This unit is a pure input unit.

See Also:
Constant Field Values

PURE_OUTPUT

public static final int PURE_OUTPUT
This unit is a pure output unit.

See Also:
Constant Field Values

INPUT

public static final int INPUT
This unit is an input unit.

See Also:
Constant Field Values

OUTPUT

public static final int OUTPUT
This unit is an output unit.

See Also:
Constant Field Values

CONNECTED

public static final int CONNECTED
This flag is set once the unit has a connection.

See Also:
Constant Field Values

m_inputList

protected NeuralConnection[] m_inputList
The list of inputs to this unit.


m_outputList

protected NeuralConnection[] m_outputList
The list of outputs from this unit.


m_inputNums

protected int[] m_inputNums
The numbering for the connections at the other end of the input lines.


m_outputNums

protected int[] m_outputNums
The numbering for the connections at the other end of the out lines.


m_numInputs

protected int m_numInputs
The number of inputs.


m_numOutputs

protected int m_numOutputs
The number of outputs.


m_unitValue

protected double m_unitValue
The output value for this unit, NaN if not calculated.


m_unitError

protected double m_unitError
The error value for this unit, NaN if not calculated.


m_weightsUpdated

protected boolean m_weightsUpdated
True if the weights have already been updated.


m_id

protected java.lang.String m_id
The string that uniquely (provided naming is done properly) identifies this unit.


m_type

protected int m_type
The type of unit this is.


m_x

protected double m_x
The x coord of this unit purely for displaying purposes.


m_y

protected double m_y
The y coord of this unit purely for displaying purposes.

Constructor Detail

NeuralConnection

public NeuralConnection(java.lang.String id)
Constructs The unit with the basic connection information prepared for use.

Method Detail

getId

public java.lang.String getId()
Returns:
The identity string of this unit.

getType

public int getType()
Returns:
The type of this unit.

setType

public void setType(int t)
Parameters:
t - The new type of this unit.

reset

public abstract void reset()
Call this to reset the unit for another run. It is expected by that this unit will call the reset functions of all input units to it. It is also expected that this will not be done if the unit has already been reset (or atleast appears to be).


outputValue

public abstract double outputValue(boolean calculate)
Call this to get the output value of this unit.

Parameters:
calculate - True if the value should be calculated if it hasn't been already.
Returns:
The output value, or NaN, if the value has not been calculated.

errorValue

public abstract double errorValue(boolean calculate)
Call this to get the error value of this unit.

Parameters:
calculate - True if the value should be calculated if it hasn't been already.
Returns:
The error value, or NaN, if the value has not been calculated.

weightValue

public double weightValue(int n)
Call this to get the weight value on a particular connection.

Parameters:
n - The connection number to get the weight for, -1 if The threshold weight should be returned.
Returns:
This function will default to return 1. If overridden, it should return the value for the specified connection or if -1 then it should return the threshold value. If no value exists for the specified connection, NaN will be returned.

updateWeights

public void updateWeights(double l,
                          double m)
Call this function to update the weight values at this unit. After the weights have been updated at this unit, All the input connections will then be called from this to have their weights updated.

Parameters:
l - The learning Rate to use.
m - The momentum to use.

getInputs

public NeuralConnection[] getInputs()
Use this to get easy access to the inputs. It is not advised to change the entries in this list (use the connecting and disconnecting functions to do that)

Returns:
The inputs list.

getOutputs

public NeuralConnection[] getOutputs()
Use this to get easy access to the outputs. It is not advised to change the entries in this list (use the connecting and disconnecting functions to do that)

Returns:
The outputs list.

getInputNums

public int[] getInputNums()
Use this to get easy access to the input numbers. It is not advised to change the entries in this list (use the connecting and disconnecting functions to do that)

Returns:
The input nums list.

getOutputNums

public int[] getOutputNums()
Use this to get easy access to the output numbers. It is not advised to change the entries in this list (use the connecting and disconnecting functions to do that)

Returns:
The outputs list.

getX

public double getX()
Returns:
the x coord.

getY

public double getY()
Returns:
the y coord.

setX

public void setX(double x)
Parameters:
x - The new value for it's x pos.

setY

public void setY(double y)
Parameters:
y - The new value for it's y pos.

onUnit

public boolean onUnit(java.awt.Graphics g,
                      int x,
                      int y,
                      int w,
                      int h)
Call this function to determine if the point at x,y is on the unit.

Parameters:
g - The graphics context for font size info.
x - The x coord.
y - The y coord.
w - The width of the display.
h - The height of the display.
Returns:
True if the point is on the unit, false otherwise.

drawNode

public void drawNode(java.awt.Graphics g,
                     int w,
                     int h)
Call this function to draw the node.

Parameters:
g - The graphics context.
w - The width of the drawing area.
h - The height of the drawing area.

drawHighlight

public void drawHighlight(java.awt.Graphics g,
                          int w,
                          int h)
Call this function to draw the node highlighted.

Parameters:
g - The graphics context.
w - The width of the drawing area.
h - The height of the drawing area.

drawInputLines

public void drawInputLines(java.awt.Graphics g,
                           int w,
                           int h)
Call this function to draw the nodes input connections.

Parameters:
g - The graphics context.
w - The width of the drawing area.
h - The height of the drawing area.

drawOutputLines

public void drawOutputLines(java.awt.Graphics g,
                            int w,
                            int h)
Call this function to draw the nodes output connections.

Parameters:
g - The graphics context.
w - The width of the drawing area.
h - The height of the drawing area.

connectInput

protected boolean connectInput(NeuralConnection i,
                               int n)
This will connect the specified unit to be an input to this unit.

Parameters:
i - The unit.
n - It's connection number for this connection.
Returns:
True if the connection was made, false otherwise.

allocateInputs

protected void allocateInputs()
This will allocate more space for input connection information if the arrays for this have been filled up.


connectOutput

protected boolean connectOutput(NeuralConnection o,
                                int n)
This will connect the specified unit to be an output to this unit.

Parameters:
o - The unit.
n - It's connection number for this connection.
Returns:
True if the connection was made, false otherwise.

allocateOutputs

protected void allocateOutputs()
Allocates more space for output connection information if the arrays have been filled up.


disconnectInput

protected boolean disconnectInput(NeuralConnection i,
                                  int n)
This will disconnect the input with the specific connection number From this node (only on this end however).

Parameters:
i - The unit to disconnect.
n - The connection number at the other end, -1 if all the connections to this unit should be severed.
Returns:
True if the connection was removed, false if the connection was not found.

removeAllInputs

public void removeAllInputs()
This function will remove all the inputs to this unit. In doing so it will also terminate the connections at the other end.


changeInputNum

protected void changeInputNum(int n,
                              int v)
Changes the connection value information for one of the connections.

Parameters:
n - The connection number to change.
v - The value to change it to.

disconnectOutput

protected boolean disconnectOutput(NeuralConnection o,
                                   int n)
This will disconnect the output with the specific connection number From this node (only on this end however).

Parameters:
o - The unit to disconnect.
n - The connection number at the other end, -1 if all the connections to this unit should be severed.
Returns:
True if the connection was removed, false if the connection was not found.

removeAllOutputs

public void removeAllOutputs()
This function will remove all outputs to this unit. In doing so it will also terminate the connections at the other end.


changeOutputNum

protected void changeOutputNum(int n,
                               int v)
Changes the connection value information for one of the connections.

Parameters:
n - The connection number to change.
v - The value to change it to.

getNumInputs

public int getNumInputs()
Returns:
The number of input connections.

getNumOutputs

public int getNumOutputs()
Returns:
The number of output connections.

connect

public static boolean connect(NeuralConnection s,
                              NeuralConnection t)
Connects two units together.

Parameters:
s - The source unit.
t - The target unit.
Returns:
True if the units were connected, false otherwise.

disconnect

public static boolean disconnect(NeuralConnection s,
                                 NeuralConnection t)
Disconnects two units.

Parameters:
s - The source unit.
t - The target unit.
Returns:
True if the units were disconnected, false if they weren't (probably due to there being no connection).