|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectBayesNet
public class BayesNet
A Bayesian network. Almost all translation procedures are done in this class.
Nested Class Summary | |
---|---|
private class |
BayesNet.VisitResult
Immutable class containing a result of a visit in sorting a bucket. |
private static class |
BayesNet.VStat
Enum for the flags in topological sorting. |
Field Summary | |
---|---|
private int[][] |
adjTab
Directed adjacency table that specifies the network structure of the BN. |
private static java.lang.String |
ATT_BIF_VERSION
|
private static java.lang.String |
ATT_VARIABLE_TYPE
|
private java.lang.String |
basename
Basename of the input file. |
private java.util.List<java.util.List<Cluster>> |
bucketList
List of buckets, where each buckets contains cluster nodes, CPT nodes and instanciation nodes. |
private int[] |
elimOrder
Elimination order. |
private int[] |
evidLevel
Evidence levels used for generating random evidences. |
private java.io.PrintStream |
evidPsm
Output stream for Prism evidences. |
private Format |
format
Format of the XML input. |
private boolean |
hasEvid
Flag indicating wheter the translator has some evidence file. |
private boolean |
hasExtElimOrder
Flag indicating whether we have an external file ( BASENAME.num )
which specifies the elimination order. |
private boolean |
hasTrCPT
Flag indicating whether the CPTs given in the input file are transposed. |
private Cluster[] |
headAry
List of cluster nodes that lead to be heads of the translated Prism clauses. |
private int[] |
invOrder
Inverse mapping of order[] (the total order). |
private static int |
MAX_NVAR_NAIVE
Max. |
private boolean |
modeEvid
Flag for generating random evidences. |
private boolean |
modeNormalize
Flag for normalizing CPT entries. |
private boolean |
modeRandom
Flag for assigning random parameters. |
private boolean |
modeVerbose
Flag for the verbose mode. |
private boolean |
modeZeroComp
Flag for zero-compression of CPTs. |
private static double |
NON_TINY_PROB
Threshold by which we judge the non-tininess of a float-point number. |
private static int |
NUM_EVID_LEVEL
Number of levels for random evidences. |
private int[] |
order
Total order of the variables in the BN. |
private int[] |
primCluster
Primary clusters for variables. |
private int[] |
primClusterWidth
The widths of primary clusters. |
private java.io.PrintStream |
psm
Output stream for the translated Prism program. |
private java.io.PrintStream[] |
randEvidPsm
Output streams for random Prism evidences. |
private static java.lang.String |
TAG_BIF
|
private static java.lang.String |
TAG_DEFINITION
|
private static java.lang.String |
TAG_EVIDENCE
|
private static java.lang.String |
TAG_FOR
|
private static java.lang.String |
TAG_GIVEN
|
private static java.lang.String |
TAG_NAME
|
private static java.lang.String |
TAG_NETWORK
|
private static java.lang.String |
TAG_OUTCOME
|
private static java.lang.String |
TAG_PROBABILITY
|
private static java.lang.String |
TAG_PROPERTY
|
private static java.lang.String |
TAG_TABLE
|
private static java.lang.String |
TAG_VALUE
|
private static java.lang.String |
TAG_VALUES
|
private static java.lang.String |
TAG_VARIABLE
|
private static java.lang.String |
TAG_VARIABLENAME
|
private static double |
TINY_PROB
Threshold by which we judge the tininess of a float-point number. |
private int[][] |
uAdjTab
Undirected adjacency table that specifies the network structure of the BN. |
private java.util.List<Variable> |
varList
List of the variables appearing in the BN. |
private java.util.Map<java.lang.String,java.lang.Integer> |
varMap
Hashtable for the variable names. |
private java.lang.String |
version
Version number of the translator. |
Constructor Summary | |
---|---|
BayesNet(BNSetting setting,
org.w3c.dom.Document document,
org.w3c.dom.Document documentEvid)
|
Method Summary | |
---|---|
private void |
addXBIFProbability(org.w3c.dom.Node n)
Finds CPTs and adds them to the DOM tree. |
private void |
addXBIFVariable(int id,
org.w3c.dom.Node n)
Finds the definitions of random variables and adds them to the DOM tree. |
private void |
addXMLBIFDefinition(org.w3c.dom.Node n)
Finds CPTs and adds them to the DOM tree. |
private void |
addXMLBIFEvidence(int id,
org.w3c.dom.Node n)
Finds evidences and adds them to the DOM tree. |
private void |
addXMLBIFVariable(int id,
org.w3c.dom.Node n)
Finds the definitions of random variables and adds them to the DOM tree. |
private void |
buildElimOrder()
Builds the minimum deficiency order (MDO) using adjacency tables and return it. |
void |
buildInitialBuckets()
Builds the initial buckets. |
void |
buildModes()
Determines the input/output modes of cluster nodes and CPT nodes. |
private boolean |
checkHasEvid()
Checks if there are evidences specified in the input. |
private void |
checkTableEntries(Variable v)
Checks if the CPT entries are normalized. |
private void |
checkTableSize(Variable v)
Checks the size of each CPT. |
void |
closeStreams()
Closes the output streams. |
int[][] |
getAdjacencyTable()
Builds the directed adjacency table and return it. |
private java.lang.String |
getCleanTextContent(org.w3c.dom.Node n)
Cleans up the text contents by replacing all space symbols by white spaces and perform triming. |
void |
getElimOrder()
Gets the elimination order. |
void |
getEvidLevel()
Computes the evidence levels for all variables in the BN. |
private void |
getExternalElimOrder()
Retrieves the elimination order from the file named BASENAME.num. |
private org.w3c.dom.Node |
getFirstNetworkNode(org.w3c.dom.Document document)
Gets the first DOM tree of the BN specification. |
void |
getInverseTotalOrder()
Builds the inverse mapping of order[] . |
private int[][] |
getModeDepTable(int bSize,
java.util.List<Cluster> bucket)
Gets the table on input/output dependencies. |
int |
getNumberOfVariables()
Returns the number of variables in the BN. |
void |
getPrimaryCluster()
Gets the primary clusters for all variables. |
void |
getTotalOrder()
Gets the total order of variables by topological sorting. |
int[][] |
getUndirectedAdjacencyTable()
Converts a directed adjacency table to the undirected one. |
Variable |
getVariable(int i)
Returns the i-th variable in the BN. |
private org.w3c.dom.Node |
getXBIFFirstNetworkNode(org.w3c.dom.Document document)
Gets the DOM tree of the XBIF specification of a BN. |
private org.w3c.dom.Node |
getXMLBIFFirstNetworkNode(org.w3c.dom.Document document)
Gets the DOM tree of the XMLBIF specification of a BN. |
void |
growBuckets()
Grows the buckets one by one. |
private boolean |
matchName(java.lang.String s,
java.lang.String name)
Matches two strings ignoring the case. |
private void |
parseXBIFNetwork(org.w3c.dom.Document document)
Traverses and collects information on the DOM of XBIF network file. |
private void |
parseXMLBIFEvidence(org.w3c.dom.Document document)
Traverses and collects information on the DOM of XMLBIF _evidence_ file. |
private void |
parseXMLBIFNetwork(org.w3c.dom.Document document)
Traverses and collects information on the DOM of XMLBIF _network_ file. |
private void |
postCheckNetwork()
Performs post checking and post processing of the network specification. |
void |
printAdjacencyTable()
Prints the directed adjacency table. |
void |
printBuckets()
Prints buckets (the base method). |
void |
printElimOrder()
Prints the elimination order. |
void |
printFinalBuckets()
Prints the buckets finally obtained by the bucket-tree method. |
void |
printInitialBuckets()
Prints the initial buckets. |
void |
printModedBuckets()
Prints the buckets added the input/output modes. |
void |
printPrismBuckets()
Writes the modeling part to the outoput. |
void |
printPrismCPT()
Writes the definition of the cpt predicate. |
void |
printPrismDecls()
Writes the declaration part to the outoput. |
void |
printPrismDistrib()
Writes the naive version of the modeling part. |
void |
printPrismModes()
Writes the mode declarations to the outoput. |
void |
printPrismNaiveBN()
Writes the naive version of the modeling part. |
void |
printPrismNames()
Writes the predicates that relate the names systematically given by the translator to the original ones given in the XML input. |
void |
printPrismRanges()
Writes definitions of range/2 into the output according to the value of modeZeroComp. |
private void |
printPrismRanges2()
Writes definitions of range/2 into the output without zero compression. |
private void |
printPrismRanges3()
Writes definitions of range/3 into the output with zero compression. |
void |
printPrismSampler()
Writes the routine for sampling. |
void |
printPrismSetSwitches()
Writes the routine for parameter settings. |
void |
printPrismVersion()
Writes the version number to the outoput. |
void |
printPsmEvid()
Writes the evidences. |
void |
printPsmRandomEvid()
Writes the random evidences. |
void |
printTotalOrder()
Writes the total order of the variables in the BN. |
void |
printUndirectedAdjacencyTable()
Prints the undirected adjacency table. |
void |
printVariables()
Writes the variables in the BN. |
void |
sortBuckets()
Orders the elements in each bucket according to the input/output modes. |
java.lang.String |
toString()
Returns a string representation. |
private void |
transposeCPT(Variable v)
Transposes the transposed CPT. |
private int |
visit(int l,
int i,
int k,
BayesNet.VStat[] visited)
Visits each variable in the BN based on the direct adjacency table. |
private BayesNet.VisitResult |
visitBucket(int bSize,
int i,
BayesNet.VisitResult r,
int[][] adj,
BayesNet.VStat[] visited,
java.util.List<java.lang.Integer> order)
Visit an element in a bucket recursively. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String TAG_BIF
private static final java.lang.String TAG_NETWORK
private static final java.lang.String TAG_NAME
private static final java.lang.String TAG_VARIABLE
private static final java.lang.String TAG_OUTCOME
private static final java.lang.String TAG_DEFINITION
private static final java.lang.String TAG_FOR
private static final java.lang.String TAG_GIVEN
private static final java.lang.String TAG_TABLE
private static final java.lang.String TAG_PROPERTY
private static final java.lang.String TAG_EVIDENCE
private static final java.lang.String TAG_VARIABLENAME
private static final java.lang.String TAG_VALUE
private static final java.lang.String TAG_VALUES
private static final java.lang.String TAG_PROBABILITY
private static final java.lang.String ATT_BIF_VERSION
private static final java.lang.String ATT_VARIABLE_TYPE
private static final int NUM_EVID_LEVEL
private static final double NON_TINY_PROB
private static final double TINY_PROB
private static final int MAX_NVAR_NAIVE
private java.lang.String basename
private java.lang.String version
private Format format
private boolean hasExtElimOrder
BASENAME.num
)
which specifies the elimination order.
private boolean hasTrCPT
private boolean modeZeroComp
private boolean modeRandom
private boolean modeEvid
private boolean modeNormalize
private boolean modeVerbose
private boolean hasEvid
private java.util.List<Variable> varList
private java.util.Map<java.lang.String,java.lang.Integer> varMap
private int[][] adjTab
private int[][] uAdjTab
private int[] elimOrder
i = elimOrder[q]
' indicates that the q-th element
in the elimination order is variable i
.
private java.util.List<java.util.List<Cluster>> bucketList
private Cluster[] headAry
private int[] order
private int[] invOrder
order[]
(the total order).
private int[] primCluster
private int[] primClusterWidth
private java.io.PrintStream psm
private java.io.PrintStream evidPsm
private java.io.PrintStream[] randEvidPsm
private int[] evidLevel
i
can be 1 ... NUM_EVID_LEVEL
.
If the evidence level of variable i
is k
, the evidences
for variable i will be given in k
files (i.e.
BASENAME_revid{NUM_EVID_LEVEL - k + 1}.psm
,
..., BASENAME_revid{NUM_EVID_LEVEL}.psm
).
Constructor Detail |
---|
public BayesNet(BNSetting setting, org.w3c.dom.Document document, org.w3c.dom.Document documentEvid) throws B2PException
setting
- Setting for the translator.document
- DOM tree of the XML specification of a BN.documentEvid
- DOM tree of the XML specification of evidences.
B2PException
Method Detail |
---|
private boolean checkHasEvid()
private void parseXMLBIFNetwork(org.w3c.dom.Document document) throws B2PException
B2PException
private void parseXMLBIFEvidence(org.w3c.dom.Document document) throws B2PException
B2PException
private void parseXBIFNetwork(org.w3c.dom.Document document) throws B2PException
B2PException
private void postCheckNetwork() throws B2PException
B2PException
private void checkTableSize(Variable v) throws B2PException
v
, and the outcomes of v
's parents are non-null.
B2PException
private void transposeCPT(Variable v)
private void checkTableEntries(Variable v) throws B2PException
B2PException
public void closeStreams()
private org.w3c.dom.Node getXMLBIFFirstNetworkNode(org.w3c.dom.Document document) throws B2PException
B2PException
private org.w3c.dom.Node getXBIFFirstNetworkNode(org.w3c.dom.Document document) throws B2PException
B2PException
private org.w3c.dom.Node getFirstNetworkNode(org.w3c.dom.Document document) throws B2PException
B2PException
private void addXMLBIFVariable(int id, org.w3c.dom.Node n) throws B2PException
B2PException
private void addXMLBIFDefinition(org.w3c.dom.Node n) throws B2PException
B2PException
private void addXMLBIFEvidence(int id, org.w3c.dom.Node n) throws B2PException
B2PException
private void addXBIFVariable(int id, org.w3c.dom.Node n) throws B2PException
B2PException
private void addXBIFProbability(org.w3c.dom.Node n) throws B2PException
B2PException
private boolean matchName(java.lang.String s, java.lang.String name)
private java.lang.String getCleanTextContent(org.w3c.dom.Node n)
public int getNumberOfVariables()
public Variable getVariable(int i)
public int[][] getAdjacencyTable()
public void printAdjacencyTable()
public void printUndirectedAdjacencyTable()
public int[][] getUndirectedAdjacencyTable()
public void getElimOrder() throws B2PException
B. D'Ambrosio (1999). Inference in Bayesian networks. AI Magazine, 20 (2), pp.21-36.
B2PException
private void getExternalElimOrder() throws B2PException
B2PException
private void buildElimOrder()
public void printElimOrder() throws B2PException
B2PException
public void buildInitialBuckets() throws B2PException
B2PException
public void growBuckets() throws B2PException
K. Kask, R. Dechter, J. Larrosa and A. Dechter (2005). Unifying tree decompositions for reasoning in graphical models. Artificial Intelligence, 166 (1-2), pp.165-193.
B2PException
public void buildModes() throws B2PException
B2PException
public void sortBuckets() throws B2PException
B2PException
private BayesNet.VisitResult visitBucket(int bSize, int i, BayesNet.VisitResult r, int[][] adj, BayesNet.VStat[] visited, java.util.List<java.lang.Integer> order)
private int[][] getModeDepTable(int bSize, java.util.List<Cluster> bucket) throws B2PException
B2PException
public void printInitialBuckets()
public void printFinalBuckets()
public void printModedBuckets()
public void printBuckets()
public void printPrismVersion()
public void printPrismModes()
public void printPrismDecls()
public void printPrismBuckets() throws B2PException
B2PException
public void printPrismRanges()
range/2
into the output according to the value of modeZeroComp.
Also writes definitions of range/3
If modeZeroComp
is true.
private void printPrismRanges2()
range/2
into the output without zero compression.
private void printPrismRanges3()
range/3
into the output with zero compression.
public void printPrismCPT()
cpt
predicate.
public void getTotalOrder()
private int visit(int l, int i, int k, BayesNet.VStat[] visited)
public void getInverseTotalOrder()
order[]
.
public void getPrimaryCluster()
public void printPrismNaiveBN()
MAX_NVAR_NAIVE
variables.
public void printPrismDistrib()
public void printPrismSetSwitches()
public void printPrismSampler()
public void printPrismNames()
public void printTotalOrder()
public void printVariables()
public void getEvidLevel()
public void printPsmEvid()
public void printPsmRandomEvid()
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |