BNJ-Tutorial-20031118
31 Pages
English

BNJ-Tutorial-20031118

-

Downloading requires you to have access to the YouScribe library
Learn all about the services we offer

Description

BNJ 2.03aIntermediate Developer TutorialRoby Joehanes(revised by William H. Hsu)Kansas State UniversityKDD Laboratoryhttp://www.kddresearch.orghttp://bndev.sourceforge.netContentsn Introductionn Core Classesn Inference Classesn Data Classesn Learning Classesn Converter Classesn Genetic Algorithm Classeshttp://bndev.sourceforge.net1BNJ 2.0: What’s Newn Total revamp from 1.0n Aimed towards stability, flexibility, maintainability, and speedn New functionality addedn Status: alpha¤API not finalized yet¤More mature on learning side than inferencehttp://bndev.sourceforge.netCore Architecturen Divided into several parts:¤ Core classes – edu.ksu.cis.bnj.bbn packageFor expressing graphs, nodes, edges, cpts (CPFs), PDFs (cpt’s entries).¤ Inference – edu.ksu.cis.bnj.bbn.inference packageExact and inexact inference¤ Learning – edu.ksu.cis.bnj.bbn.learningStructure learning¤ PRM – edu.ksu.cis.bnj.bbn.prmAll classes necessary for probabilistic relational models¤ Data – edu.ksu.cis.kdd.dataRepresenting data for learning methodshttp://bndev.sourceforge.net2Auxiliary Architecturen Converter – edu.ksu.cis.bnj.bbn.converterLoading, saving, converting network filesn Data converter – edu.ksu.cis.kdd.data.converterLoading, saving, converting data filesn GUI – edu.ksu.cis.bnj.guiGraphical user interface componentsn Genetic algorithm – edu.ksu.cis.kdd.gaMainly used for GAWK (GA Wrapper for K2)n Bayes classifier – edu.ksu.cis.kdd ...

Subjects

Informations

Published by
Reads 1 331
Language English
Contents
BNJ 2.03a Intermediate Developer Tutorial
Roby Joehanes (revised by William H. Hsu) Kansas State University KDD Laboratory http://www.kddresearch.org http://bndev.sourceforge.net
nIntroduction nCore Classes nInference Classes nData Classes nLearning Classes nConverter Classes nGenetic Algorithm Classes
http:// bndev.sourceforge.net
1
BNJ 2.0: What’s New
nTotal revamp from 1.0 nAimed towards stability, flexibility, maintainability, and speed nNew functionality added nStatus: alpha ¨API not finalized yet ¨More mature on learning side than inference
http:// bndev.sourceforge.net
Core Architecture
nDivided into several parts: ¨Core classes –edu.ksu.cis.bn bbnpac For expressing graphs, nodes,je.(sPCc tp sF,)ges,gekda PDFs (cpt’s entries). ¨Inference –edu.ksu.cis.bnj.bbn.inferencepackage Exact and inexact inference ¨arLe– Sticnugrnarnin.lej.bbs.bn.uic.uskdegn t ure learning ¨PRM –edksu.m.jbb.nrp.uic.snb All classes necessary for probabilistic relational models ¨Data –a.datsic.ddk.udeusk. Representing data for learning methods http:// bndev.sourceforge.net
2
Auxiliary Architecture
nConverter –edu.ksu.cis.bnj.bbn.converter Loading, saving, converting network files nData converter –evnoc.atretru.ksu.cis.kdd.dade Loading, saving, converting data files nGUI –edu.ksu.cis.bnj.gui Graphical user interface components nGenetic algorithm –edu.ksu.cis.kdd.ga Mainly used for GAWK (GA Wrapper for K2) nBayes classifier –edu.ksu.cis.kdd.classifier Now slightly updated – Machine Learning (Fall, 2001) class project, Joehanes nOther utilities
Contents
http:// bndev.sourceforge.net
nIntroduction nCore Classes nInference Classes nData Classes nLearning Classes nConverter Classes nGenetic Algorithm Classes
http:// bndev.sourceforge.net
3
Core Classes [1]
nMainly inherited from OpenJGraph nBBNGraph: Bayes Net Graph nBBNNode: Bayes Net Node nBBNCPT: Conditional Probability Table ¨Called CPF[unction] because support for continuous values planned ¨ not yet implementedFull CPFs nBBNPDF: CPT entries ¨PDF = Probabilistic Distribution Function; again, for continuous values
http:// bndev.sourceforge.net
Core Classes [2]
nBBNValue: Abstract class for discrete (eValuceretNDisBB) and continuous values (NBoCBusuoinnteluVa)àwill be phased out in upcoming release nntBNBoCsnat: Derived class ofBBNPDFfor representing constants (superfluous, will be phased out) nceenidEvaPsrreàClass to parse evidence values. (should not be called externally)
http:// bndev.sourceforge.net
4
BBNGraph [1]
nTo create a Bayes net graph: BBNGraph g = new BBNGraph(); nTo : BB NloGarda pahBagy e=s nBeBtN)”;filead(h.loGrap nTgo. ssaavvee(agfrialpeh:” );– or – g.save(“file”, “format”); e.g.,g.save(“mynet.net”, ”net”); nTo load evidence: g.loadEvidence(evidencefile”);
http:// bndev.sourceforge.net
BBNGraph [2]
nTo save evidence: g.saveEvidence(“evidencefile”); nTo print graph contents for debugging: System.out.println(g.toString()); nTo add or remove a node: g.addNode(bbnNode); g.removeNode(bbnNode);// related edges will also be deleted nTo add or remove an edge: g.addEdge(node1, node2); g.removeEdge(node1, node2); nTo topologically sort a graph: List nodeList = g.topologicalSort(); http:// bndev.sourceforge.net
5
BBNNode [1] nTo create a node: BBNNode node = new BBNNode(); node.setName(“name”); // must then add node to graph nTo set node values: BBNDiscreteValue v = new BBNDiscreteValue(); v.add(“v1”); v.add(“v2”);// … and so on node.setValues(v); nTo get node values: BBNValue v = node.getValues(); t evidence nnToodseet.osregteEvidenceV:alue(val);// val must be in the BBNValue Object val = node.getEvidenceValue(); http:// bndev.sourceforge.net
BBNNode [2]
nturn node into Decision / Utility node:To node.setType(BBNNode.DECISION); node.setType(BBNNode.UTILITY); nTo inquire about a node: node.isDecision(); node.isUtility(); node.isEvidence(); nTo access CPT: BBNCPF cpf = node.getCPF(); // Note: Don’t use query from the node directly // as it will be phased out soon
http:// bndev.sourceforge.net
6
BBNCPF (This will be phased out)
nCPFs should not be created individually unless you know what you are doing (e.g. creating ICPTs for SIS or AIS) nTo create a CPF object yourself, use: List l new LinkedList(); = l.add(“node1”); l.add(“node2”); // etc, add the node names involved for the CPT (in string) BBNCPF cpf = new BBNCPF(l);  // Note: This will be obsolete soon. http:// bndev.sourceforge.net
Querying BBNCPF [1]
nTo query CPF: construct hash table nExample ¨Letaandbbe the parents of nodec ¨Let all nodes be Boolean ¨To query content of CPT entry for (a= true,b= true,c= false): Hashtable t = new Hashtable(); t.put(“a”, “true”); t.put(“b”, “true”); t.put(“c”, “false”); double value = c.query(t); nNote: BBNCPF to become obsolete (v2.2b, v2.3)
http:// bndev.sourceforge.net
7
Querying BBNCPF [2]
nThe code: Hashtable t = new Hashtable(); t.put(“a”, “true”); t.put(“c”, false”); double value = c.query(t); will result in: value = c.query(t U “b = true”) + c.query(t U “b false”); = nSo, if we omitbfrom the hash table, we are effectively marginalizing onbfromc’s table.
http:// bndev.sourceforge.net
Reason for CPF Overhaul
nQ: Why do we need to revamp CPFs? A: CPFs are the performance hog in BNJ. They admit an exp^exp(N) space requirement and will thus cause thrashing when computing large networks. nOriginally used because space was thought to be less of an issue than speed nRevamp is underway nBart Peintner has also provided a solution http:// bndev.sourceforge.net
8
Contents
nIntroduction nCore Classes nInference Classes nData Classes nLearning Classes nConverter Classes nGenetic Algorithm Classes
http:// bndev.sourceforge.net
Inference Classes
nInfceeren: Abstract class that all inference modules should inherit from nceenernftIacEx: Abstract class for all exact inference nefeInncreametorixApp: Abstract class for approximate inference nMCMC: For MCMC based approximate inference (sae.limpoxpratimcnerpa.e.udeefnign)
http:// bndev.sourceforge.net
9
Invoking Available Inference Classes nExample (Lauritzen-Spiegelhalter,i.e.,junction tree): BBNGraph g = BBNGraph.load(“netfile”); g.loadEvidence(“evidenceFile”); // if needed LS ls = new LS(g); InferenceResult result = ls.getMarginals(); nVariable result: printable hash table System.out.println(result.toString()); nOther inference classes are invoked in the same way. nNote: actual inference happens ingetMarginals() nMay want to set some options before it http:// bndev.sourceforge.net
Getting the Most Probable Explanaton (MPE) nBNJ inference provides default method for getting MPE ¨Hashtable getMPE() ¨Returns a hash table of (node nameàmpe value) nBNJ does not provide a customized MPE routine for each inference, so it is very slow (i.e., does it naively). nMAP: not done yet http:// bndev.sourceforge.net
10
Available Inference Algorithms
nLS / Junction tree nElimBel(Bucket elimination) nPearl Tree propagation (currently buggy) nForward Sampling nLogic Sampling nLikelihood Weighting nSelf-Importance Sampling nAdaptive Important Sampling n (buggy)Cutset and Bounded Cutset nChavez MCMC (buggy) nPearl MCMC (buggy)
http:// bndev.sourceforge.net
Customizing Inference Classes
nIdeal case: plug-in system ¨User can build own inference modules ¨“Just works” with BNJ nMain infrastructure relies on Java Reflection API extended on fileed.rLsaolCsaiFeljava nUser must inherit from ¨ExactInferencefor exact inference methods ¨ApproximateInferencefor inexact ones nMust inherit at leastgraMteg)(slaniethodm
http:// bndev.sourceforge.net
11