bbn
Class NodeManager

java.lang.Object
  |
  +--bbn.NodeManager

public class NodeManager
extends java.lang.Object

Title: NodeManager.java Description: Core Bayesian Network class Copyright: Copyright (c) 2001 Company: KSU / KDD


Field Summary
protected  java.io.BufferedReader bufferedReader
           
 
Constructor Summary
NodeManager(BBN newNetwork)
          NodeManager constructs and initializes the Node Manager.
 
Method Summary
 double getAttributeValue(int nodeIndex, int attributeIndex)
           
 java.util.Vector getEvidenceBits()
           
 java.util.Vector getEvidenceNodeNames()
           
 java.util.Vector getEvidenceNodes()
          getEvidenceNodes returns a vector of Node objects containing all of the nodes that are evidence nodes.
 double getEvidenceSetProbability()
          getStateSetProbability returns the probability of an instantiation by using the chain rule.
 java.util.Vector getEvidenceValues()
          getEvidenceValues returns the instantiation of nodes in the evidence file
 BBN getNetwork()
           
 java.util.Vector getNodeNames()
           
 java.util.Vector getNodePercenteges()
           
 double getProbabilityOfNodeGivenParents(Node node)
          getProbabilityOfNodeGivenParents returns the probability of a certain node given the state of its parents.
 double getProbabilityOfNodeGivenParents(Node node, boolean ignoreEvidence)
           
 java.util.Vector getQueryNodeNames()
          getQueryNodeNames return a vector of Strings containing all of the names of nodes that are query nodes.
 java.util.Vector getQueryNodes()
          getQueryNodes returns a vector of Node objects containing all of the nodes that are query nodes.
 double getStateSetProbability()
          getStateSetProbability returns the probability of an instantiation by using the chain rule.
 int getValue(int index)
          getValue returns the requested node's current state.
 int getValue(Node node)
          getValue returns the requested node's current state.
 int getValue(java.lang.String nodeName)
          getValue returns the requested node's current state.
 boolean hasMoreLines()
          hasMoreLines determines if there is another state set to read.
 boolean isEvidence(int index)
          isEvidence returns true if the requested node index is an evidence.
 boolean isEvidence(Node node)
          isEvidence returns true if the requested node is an evidence.
 boolean isEvidence(java.lang.String nodeName)
          isEvidence returns true if the requested node name is an evidence.
 void loadEvidenceAtLine(int i)
          loadEvidenceAtLine loads the instantiation from the evidence file at the given line
 boolean openEvidenceFile(java.lang.String fileName)
          openEvidenceFile opens an evidence file, reads the structure of the file, and initializes the node manager layout.
 boolean readNextValues()
          readNextValues reads the next state set from the file.
 java.lang.String report()
           
 java.lang.String reportProbabilities()
           
 java.lang.String reportSimpleValues()
           
 java.util.Vector reportSimpleVector()
           
 void resetValues()
           
 void setAttributeValue(int nodeIndex, int attributeIndex, java.lang.Double value)
           
 void setEvidenceBitvector(java.util.Vector bits)
           
 void setNetwork(BBN network)
           
 void setValue(int node, int newState)
           
 void setValue(Node node, int newState)
           
 void setValues(java.util.Vector newStates)
          Sets node states to the given values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bufferedReader

protected java.io.BufferedReader bufferedReader
Constructor Detail

NodeManager

public NodeManager(BBN newNetwork)
NodeManager constructs and initializes the Node Manager.
Parameters:
newNetwork - - the host bayesian network for which the manager works.
Method Detail

openEvidenceFile

public boolean openEvidenceFile(java.lang.String fileName)
openEvidenceFile opens an evidence file, reads the structure of the file, and initializes the node manager layout. Node ordering in the evidence file need not match the order of the bayesian network, because the manager will do the matching. Throws BBNE_IOError if the file couldn't be opened or if the file does not match the standard evidence file layout.
Parameters:
fileName - - the name of the evidence file to open
Returns:
boolean - whether or not the open call succeeded.

getEvidenceValues

public java.util.Vector getEvidenceValues()
getEvidenceValues returns the instantiation of nodes in the evidence file
Returns:
Vector - the instantiation of nodes

getNodeNames

public java.util.Vector getNodeNames()

getEvidenceBits

public java.util.Vector getEvidenceBits()

getEvidenceNodeNames

public java.util.Vector getEvidenceNodeNames()

setNetwork

public void setNetwork(BBN network)

setEvidenceBitvector

public void setEvidenceBitvector(java.util.Vector bits)
Parameters:
bits - - a vector of Integer objects - 0 or 1.

getNetwork

public BBN getNetwork()

loadEvidenceAtLine

public void loadEvidenceAtLine(int i)
loadEvidenceAtLine loads the instantiation from the evidence file at the given line
Parameters:
i - - the line in the evidence file to load

hasMoreLines

public boolean hasMoreLines()
hasMoreLines determines if there is another state set to read.
Returns:
boolean - whether or not there is another line.

resetValues

public void resetValues()

readNextValues

public boolean readNextValues()
readNextValues reads the next state set from the file.

isEvidence

public boolean isEvidence(Node node)
isEvidence returns true if the requested node is an evidence. Throws BBNE_NodeNotFound if the requested node is not in the network.
Parameters:
node - - the node being queried
Returns:
boolean - whether the requested node is an evidence node.

isEvidence

public boolean isEvidence(int index)
isEvidence returns true if the requested node index is an evidence. Throws BBNE_OutOfBounds if the requested index is out of bounds.
Parameters:
index - - the index being queried
Returns:
boolean - whether the requested node index is an evidence node.

isEvidence

public boolean isEvidence(java.lang.String nodeName)
isEvidence returns true if the requested node name is an evidence. Throws BBNE_NodeNotFound if the requested node is not in the network.
Parameters:
nodeName - - the node being queried
Returns:
boolean - whether the requested node is an evidence node.

getValue

public int getValue(int index)
getValue returns the requested node's current state. Throws BBNE_OutOfBounds if the requested index is out of bounds.
Parameters:
index - - the node index being queried
Returns:
int - the node's current state

getValue

public int getValue(java.lang.String nodeName)
getValue returns the requested node's current state. Throws BBNE_NodeNotFound if the requested node is not in the network.
Parameters:
nodeName - - the node being queried
Returns:
int - the node's current state

getValue

public int getValue(Node node)
getValue returns the requested node's current state. Throws BBNE_NodeNotFound if the requested node is not in the network.
Parameters:
nodeName - - the node being queried
Returns:
int - the node's current state

setValue

public void setValue(Node node,
                     int newState)

setValue

public void setValue(int node,
                     int newState)

setValues

public void setValues(java.util.Vector newStates)
Sets node states to the given values.
Parameters:
newStates - - the new states being set.

getQueryNodeNames

public java.util.Vector getQueryNodeNames()
getQueryNodeNames return a vector of Strings containing all of the names of nodes that are query nodes.
Returns:
Vector - the vector of query Node names.

getQueryNodes

public java.util.Vector getQueryNodes()
getQueryNodes returns a vector of Node objects containing all of the nodes that are query nodes.
Returns:
Vector - the vector of query Node objects.

getEvidenceNodes

public java.util.Vector getEvidenceNodes()
getEvidenceNodes returns a vector of Node objects containing all of the nodes that are evidence nodes.
Returns:
Vector - the vector of evidence Node objects.

getProbabilityOfNodeGivenParents

public double getProbabilityOfNodeGivenParents(Node node)
getProbabilityOfNodeGivenParents returns the probability of a certain node given the state of its parents. This is a potentially recursive call. Evidence nodes return 1.0 and do not check their parents.
Parameters:
node - - the node being queried.
Returns:
double - the probability of the node's state given its parents' states.

getProbabilityOfNodeGivenParents

public double getProbabilityOfNodeGivenParents(Node node,
                                               boolean ignoreEvidence)

getStateSetProbability

public double getStateSetProbability()
getStateSetProbability returns the probability of an instantiation by using the chain rule.
Returns:
double - the final probability

getEvidenceSetProbability

public double getEvidenceSetProbability()
getStateSetProbability returns the probability of an instantiation by using the chain rule.
Returns:
double - the final probability

report

public java.lang.String report()

reportProbabilities

public java.lang.String reportProbabilities()

reportSimpleValues

public java.lang.String reportSimpleValues()

reportSimpleVector

public java.util.Vector reportSimpleVector()

setAttributeValue

public void setAttributeValue(int nodeIndex,
                              int attributeIndex,
                              java.lang.Double value)

getAttributeValue

public double getAttributeValue(int nodeIndex,
                                int attributeIndex)

getNodePercenteges

public java.util.Vector getNodePercenteges()