org.joone.structure
Class NodesAndWeights

java.lang.Object
  extended by org.joone.structure.NodesAndWeights

public class NodesAndWeights
extends java.lang.Object

This class takes a neural network and breaks it up into classified nodes (ie input, output or hidden nodes) and also in the process extracts the weight matrix wij with i being the node fired into and j being the node fired from. It also identifies if an input node has some kind of an initial state that can potentially be considered to be part of the optimisation exercise. This class is useful when presenting the network as a optimisation problem to some canned optimisation algorithm or as a first step towards implementing the RTRL or EKF learning algorithms. In part for performance reasons, many of the members are not wrapped as usual and are accessed directly.

Author:
mg

Nested Class Summary
 class NodesAndWeights.Node
          A node.
 class NodesAndWeights.Weight
          A weight.
 
Field Summary
 java.util.List<NodesAndWeights.Node> I
          The input nodes, a subset of Z, specifically the last few nodes in Z, that are connected to the input layer.
 int inputNodeCount
          The number of input nodes, which appear as the final nodes in the Z array
 int outputNodeCount
          The number of output nodes, which appear as the first nodes in the Z array
 java.util.List<NodesAndWeights.Node> S
          The nodes that have an initial state.
 java.util.List<NodesAndWeights.Node> T
          The output nodes, a subset of Z and used to speed up calculations
 java.util.List<NodesAndWeights.Node> U
          The nodes in U, a subset of Z, specifically the first few nodes in Z, but those that are not input nodes.
 java.util.List<NodesAndWeights.Weight> weights
          List of all weights, typically used when setting up an optimisation problem
protected  java.util.List<NodesAndWeights.Node> z
          The unclassified nodes, referred to as the z array
 java.util.List<NodesAndWeights.Node> Z
          The same as z, but this time classified and ordered so that nodes in U come first.
 
Constructor Summary
NodesAndWeights(NeuralNet network, double maximumWeightMagnitude, boolean reset)
          Create a new instance of NodesAndWeights, decomposing the given network into nodes, initial states and attached weights
 
Method Summary
protected  NodesAndWeights.Weight getFixedWeight(NodesAndWeights.Node input, NodesAndWeights.Node output)
          Determine the fixed weight between an input and a output node.
protected  NodesAndWeights.Weight getWeight(NodesAndWeights.Node input, NodesAndWeights.Node output)
          Determine the weight between an input and a output node.
protected  void init(NeuralNet network, double maximumWeightMagnitude, boolean reset)
          Initialise the underlying parameters and structures.
protected  boolean isFixedLinked(NodesAndWeights.Node input, NodesAndWeights.Node output)
          Determine if there exists a fixed link or weight between two nodes.
protected  boolean isLinked(NodesAndWeights.Node input, NodesAndWeights.Node output)
          Determine if there exists a link or weight between two nodes.
 void printWeights(java.io.PrintStream out)
          Helper function to print out the weight matrix
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

z

protected java.util.List<NodesAndWeights.Node> z
The unclassified nodes, referred to as the z array


Z

public java.util.List<NodesAndWeights.Node> Z
The same as z, but this time classified and ordered so that nodes in U come first. We are more interested in Z of course. We only use z to extract the nodes and then later on classify them and, based on the classification, sort them into Z.


T

public java.util.List<NodesAndWeights.Node> T
The output nodes, a subset of Z and used to speed up calculations


U

public java.util.List<NodesAndWeights.Node> U
The nodes in U, a subset of Z, specifically the first few nodes in Z, but those that are not input nodes.


I

public java.util.List<NodesAndWeights.Node> I
The input nodes, a subset of Z, specifically the last few nodes in Z, that are connected to the input layer.


S

public java.util.List<NodesAndWeights.Node> S
The nodes that have an initial state. If we want to also optimise the initial state, then we will be interested in this array of nodes.


weights

public java.util.List<NodesAndWeights.Weight> weights
List of all weights, typically used when setting up an optimisation problem


inputNodeCount

public int inputNodeCount
The number of input nodes, which appear as the final nodes in the Z array


outputNodeCount

public int outputNodeCount
The number of output nodes, which appear as the first nodes in the Z array

Constructor Detail

NodesAndWeights

public NodesAndWeights(NeuralNet network,
                       double maximumWeightMagnitude,
                       boolean reset)
Create a new instance of NodesAndWeights, decomposing the given network into nodes, initial states and attached weights

Parameters:
network - network to detangle
maximumWeightMagnitude - the maximum allowable weight magnitude or 0 for no maximum
reset - if true, will reset all input and context layer biases to zero. This is a cosmetic step, as these are often randomised but not used, but may have an impact on networks that use something other than a linear layer as input layer.
Method Detail

isLinked

protected boolean isLinked(NodesAndWeights.Node input,
                           NodesAndWeights.Node output)
Determine if there exists a link or weight between two nodes. Note that not all links qualify. Only links that we are allowed to change. Not sure if this will have an impact somewhere.

Returns:
true if the input node fires into the output node

getWeight

protected NodesAndWeights.Weight getWeight(NodesAndWeights.Node input,
                                           NodesAndWeights.Node output)
Determine the weight between an input and a output node.

Returns:
null if no link exists

isFixedLinked

protected boolean isFixedLinked(NodesAndWeights.Node input,
                                NodesAndWeights.Node output)
Determine if there exists a fixed link or weight between two nodes. Such links are for example from a direct synapse or from a normal synapse where weights have been fixed.

Returns:
true if the input node fires into the output node via a fixed weight

getFixedWeight

protected NodesAndWeights.Weight getFixedWeight(NodesAndWeights.Node input,
                                                NodesAndWeights.Node output)
Determine the fixed weight between an input and a output node.

Returns:
null if no link exists

init

protected void init(NeuralNet network,
                    double maximumWeightMagnitude,
                    boolean reset)
Initialise the underlying parameters and structures. This method create and traverse the nodes, classify them as being in U or S or not, and assign k (in z) and i (in U) numbers to them. After this it creates the sorted Z and stores all the nodes again in that array and also create the K indices into that array. Based on these it then create the weight matrix wij with i, j a K number. Weights are stored as part of the nodes themselves.


printWeights

public void printWeights(java.io.PrintStream out)
Helper function to print out the weight matrix



Submit Feedback to pmarrone@users.sourceforge.net