edu.duke.cs.banjo.bayesnet
Class EdgesAsArray

java.lang.Object
  extended byedu.duke.cs.banjo.bayesnet.EdgesAsArray
All Implemented Interfaces:
java.lang.Cloneable, EdgesI
Direct Known Subclasses:
EdgesAsArrayWithCachedStatistics

public class EdgesAsArray
extends java.lang.Object
implements java.lang.Cloneable, EdgesI

Contains the basic adjacency matrix implementation, using a 1-dimensional array.

Details:
- Important: For performance reasons, several classes (e.g., BayesNetStructure, Hash classes) use internal knowledge about this class; i.e., we are intentionally breaking the encapsulation of the internal data. We need to do this because it is extremely inefficient to iterate through loops with "getEntry" or "setEntry" calls. There are numerous instances of such loops throughout the core objects of the applications.

Change History:
Created on Jun 12, 2006

Author:
Jurgen Sladeczek (hjs)
For the latest info, please visit www.cs.duke.edu.

Field Summary
protected  int currentLagOffset
           
protected  int currentVarOffset
           
protected  int dimLags
           
protected  int dimParents
           
protected  int dimVariables
           
 int[] matrix
           
protected  int maxMarkovLag
           
protected  int minMarkovLag
           
protected  int offsetLags
           
protected  int offsetParents
           
protected  int offsetVariables
           
protected  int varCount
           
 
Constructor Summary
EdgesAsArray(int _varCount, int _minMarkovLag, int _maxMarkovLag)
           
 
Method Summary
 void assignMatrix(EdgesAsArray _edgesAsArray)
           
 void assignMatrix(EdgesI _edgeMatrix)
           
 void assignMatrix(int[] _matrix)
           
 java.lang.Object clone()
           
 int[][] getCurrentParentIDlist(int nodeID, int lag)
           
 int getEntry(int _varIndex, int _parentVarIndex, int _parentLag)
           
 int[] getMatrix()
           
protected  int getParentCount(int _nodeID)
           
 boolean hasIdenticalEntries(EdgesAsArray _otherMatrix)
           
 boolean hasIdenticalEntries(EdgesI _otherMatrix)
           
 boolean hasIdenticalEntries(int[] _matrix)
           
 void setEntry(int _varIndex, int _parentVarIndex, int _parentLag, int _newValue)
           
 void setMatrix(int[] _matrix)
           
 java.lang.String toString()
           
 java.lang.String toStringAsAdjacencyMatrix()
           
 java.lang.String toStringAsTest()
           
 java.lang.String toStringWithIDs()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

matrix

public int[] matrix

varCount

protected final int varCount

maxMarkovLag

protected final int maxMarkovLag

minMarkovLag

protected final int minMarkovLag

dimVariables

protected final int dimVariables

dimParents

protected final int dimParents

dimLags

protected final int dimLags

offsetVariables

protected final int offsetVariables

offsetParents

protected final int offsetParents

offsetLags

protected final int offsetLags

currentVarOffset

protected int currentVarOffset

currentLagOffset

protected int currentLagOffset
Constructor Detail

EdgesAsArray

public EdgesAsArray(int _varCount,
                    int _minMarkovLag,
                    int _maxMarkovLag)
Method Detail

getMatrix

public int[] getMatrix()
Returns:
Returns the matrix (reference).

setMatrix

public void setMatrix(int[] _matrix)
Parameters:
_matrix - The matrix to set (reference assignment only).

assignMatrix

public void assignMatrix(int[] _matrix)
Parameters:
_matrix - The matrix to set (assignment of matrix values; no reference assignment).

assignMatrix

public void assignMatrix(EdgesI _edgeMatrix)
                  throws java.lang.Exception
Specified by:
assignMatrix in interface EdgesI
Returns:
Returns the matrix. Note: this breaks with clean object-oriented design, but it allows us to squeeze a lot of performance from the code. Use this method only where absolutely necessary, since it ties your code to a matrix- based implementation.
Throws:
java.lang.Exception

assignMatrix

public void assignMatrix(EdgesAsArray _edgesAsArray)
                  throws java.lang.Exception
Throws:
java.lang.Exception

getEntry

public int getEntry(int _varIndex,
                    int _parentVarIndex,
                    int _parentLag)
Specified by:
getEntry in interface EdgesI

setEntry

public void setEntry(int _varIndex,
                     int _parentVarIndex,
                     int _parentLag,
                     int _newValue)
              throws java.lang.Exception
Specified by:
setEntry in interface EdgesI
Throws:
java.lang.Exception

hasIdenticalEntries

public boolean hasIdenticalEntries(int[] _matrix)

hasIdenticalEntries

public boolean hasIdenticalEntries(EdgesI _otherMatrix)
Specified by:
hasIdenticalEntries in interface EdgesI

hasIdenticalEntries

public boolean hasIdenticalEntries(EdgesAsArray _otherMatrix)

getCurrentParentIDlist

public int[][] getCurrentParentIDlist(int nodeID,
                                      int lag)
                               throws java.lang.Exception
Throws:
java.lang.Exception

getParentCount

protected int getParentCount(int _nodeID)

clone

public java.lang.Object clone()
Specified by:
clone in interface EdgesI

toStringAsAdjacencyMatrix

public java.lang.String toStringAsAdjacencyMatrix()
Returns:
A custom string representation for a set of edges.

toStringWithIDs

public java.lang.String toStringWithIDs()
Returns:
A special string representation for a set of edges that includes the IDs for the variables.

toStringAsTest

public java.lang.String toStringAsTest()
Returns:
Another special string representation for a set of edges: This one prints all entries of the matrix.

toString

public java.lang.String toString()
Returns:
A special string representation for a set of edges in a simplified (proprietary) format (the same one that we use for input and output of networks).