edu.duke.cs.banjo.bayesnet
Class EdgesAsMatrix

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

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

Contains the basic adjacency matrix implementation.

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 1, 2004
(v2.0) Use of the more efficient parent set implementations. Note that the original parent sets from version 1.0.x will be deprecated in an upcoming maintenance release.

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

Field Summary
 int[][][] matrix
           
protected  int maxMarkovLag
           
protected  int minMarkovLag
           
protected  int varCount
           
 
Constructor Summary
EdgesAsMatrix(int _varCount, int _minMarkovLag, int _maxMarkovLag)
           
 
Method Summary
 void assignMatrix(EdgesAsMatrix _edgeMatrix)
           
 void assignMatrix(EdgesI _edges)
           
 void assignMatrix(int[][][] _matrix)
           
 java.lang.Object clone()
           
 int[][] getCurrentParentIDlist(int _nodeID, int _lag)
           
 int getEntry(int _varIndex, int _parentVarIndex, int _lag)
           
 int[][][] getMatrix()
           
protected  int getParentCount(int _nodeID)
           
 boolean hasIdenticalEntries(EdgesAsMatrix _otherMatrix)
           
 boolean hasIdenticalEntries(EdgesI _otherMatrix)
           
 void setEntry(int _varIndex, int _parentVarIndex, int _lag, 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
Constructor Detail

EdgesAsMatrix

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

getMatrix

public int[][][] getMatrix()

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 _edges)
                  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(EdgesAsMatrix _edgeMatrix)
                  throws java.lang.Exception
Throws:
java.lang.Exception

getEntry

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

setEntry

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

hasIdenticalEntries

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

hasIdenticalEntries

public boolean hasIdenticalEntries(EdgesAsMatrix _otherMatrix)

getCurrentParentIDlist

public int[][] getCurrentParentIDlist(int _nodeID,
                                      int _lag)

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).