Description
The package bbn consists of core classes for representing the data structure of a Bayesian network. BBN.java and Node.java are used to represent a Bayesian network. NodeManager.java helps handle evidence for inference. Some useful utilities are also included in this package such as a data generator.
Examples
==============================BBNExample.java=====================================
import bbn.*;
import java.util.Vector;
public class BBNExample {
public static void main(String[] args){
System.out.println("load the network from file ... ");
BBN network = new BBN();
network.loadFromXML("asia.xml");
System.out.println("printing out information of each node... ");
for (int i = 0; i < network.size(); i++){
System.out.println("i="+i);
network.getNodeAt(i).print();
network.getNodeAt(i).printStateNames();
if(network.getNodeAt(i).getParents().size()>0){
for(int j=0;j "+network.getNodeAt(i).getParentName(j));
}
System.out.println("probabilities in CPT -->"+network.getNodeAt(i).getProbabilities());
System.out.println("--------");
}
}
}
=============================Result of BBNExample======================================= D:\bnj>javac BBNExample.java D:\bnj>java BBNExample load the network from file ... printing out information of each node... i=0 For node VisitAsia: Visit No_Visit probabilities in CPT --> [0.01, 0.99] -------- i=1 For node Tuberculosis: Present Absent parents --> VisitAsia probabilities in CPT --> [0.05, 0.01, 0.95, 0.99] -------- i=2 For node Smoking: Smoker NonSmoker probabilities in CPT --> [0.5, 0.5] -------- i=3 For node Cancer: Present Absent parents --> Smoking probabilities in CPT --> [0.1, 0.01, 0.9, 0.99] -------- i=4 For node TbOrCa: True False parents --> Tuberculosis parents --> Cancer probabilities in CPT --> [1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0] -------- i=5 For node XRay: Abnormal Normal parents --> TbOrCa probabilities in CPT --> [0.98, 0.05, 0.02, 0.95] -------- i=6 For node Bronchitis: Present Absent parents --> Smoking probabilities in CPT --> [0.6, 0.3, 0.4, 0.7] -------- i=7 For node Dyspnea: Present Absent parents --> TbOrCa parents --> Bronchitis probabilities in CPT --> [0.9, 0.7, 0.8, 0.1, 0.1, 0.3, 0.2, 0.9] -------- ================================================================
============================= Example of using DataGenerator ======================================== D:\bnj>java bbn/DataGenerator2 * * * DataGenerator2 * * * Usage: java DataGenerator2 input.xml output.xml number_of_samples (0 will generate an evidence file) D:\bnj>java bbn/DataGenerator2 asia.xml asia20.xml 20 * * * DataGenerator * * * Usage: java DataGenerator input.xml output.xml number_of_samples (0 will generate an evidence file) Success! D:\bnj> ============================= End of Example=====================================
=============================Example of using DataGenerator======================================== D:\bnj>java bbn/DataGenerator2 asia.xml asia_evidence.xml 0 * * * DataGenerator2 * * * Usage: java DataGenerator2 input.xml output.xml number_of_samples (0 will generate an evidence file) Success! D:\bnj> =============================Result evidence file : asia_evidence.xml=================== 0 0 0 0 0 0 0 0 VisitAsia|Smoking|Tuberculosis|Cancer|TbOrCa|XRay|Bronchitis|Dyspnea Visit NonSmoker Absent Present False Normal Present Present =============================end of evidence file=======================================