Skip to content

weitkaemper/bn-logtalk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bn-logtalk

Logtalk implementation of Boolean Bayesian networks. This is just a very brief introduction to the repository; see the docs folder for a more complete API documentation in HTML and markdown, and the diagrams folder for a comprehensive entity diagram.

Bayesian networks

Bayesian networks are represented as objects implementing the bnp protocol, which demands an underlying graph with predicates node/1 and edge/2 as well as, for every node, a domain of possible values (domain/2) and a conditional probability table (cpt/). See bn_sprinkler for a self-contained example and bn_dengue for an object that extends a separate object graph_sprinkler with the underlying graph.

Inference

Marginal and conditional inference are supported by objects implementing the protocol probmodelp. Marginal inference is given as pquery/2, where the first (input) argument is a partial specification (list of node-value pairs), and the output argument is its probability. The predicate pquery/3 additionally has a second input argument describing the evidence.

This repository currently provides two inference algorithms. One is a lazy implementation of variable elimination computed by the parametric object ve(BN,Ord), where BN is a Bayesian network and Ord an ordering of the variables in BN used as the elimination ordering after removing the query variables. The second is a message-passing implementation of factor elimination, computed by the parametric object fe(Etree), where Etree is an elimination tree (described by the elim_treep protocol).

Putting it all together, we can query probability of a dengue outbreak using variable elimination as

ve(bn_dengue,[frost,water,mosquito,dengue,malaria])::pquery([dengue-true],P).

and using message passing (belief propagation) as

fe(elim_tree(bn_dengue,dengue))::pquery([dengue-true],P).

Interventions

Outside interventions are modelled by the parametric object do(BN,Spec), where BN is the Bayesian network and Spec specifies the intervention as a list of node-value pairs. This is again a Bayesian network object, so inference can be performed as normal.

Learning

Parameter estimation is supported using a basic implementation of the expectation-maximisation algorithm in conjunction with variable elimination. It is implemented by the object em_ve(BN,Ord,Data,N), where BN is a Bayesian network containing the fixed underlying graph and the starting parameters, Ord is the variable ordering to be used for iteratively running variable elimination, Data is the training data as a list of (possibly partial) specifications and N the number of iterations to be performed. It implements the Bayesian network protocol bnp, as the result of applying the expectation-maximisation algorithm is itself a fully specified Bayesian network.

About

Bayesian networks in Logtalk

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors