hbayes-0.5.2: Bayesian Networks

Safe HaskellNone
LanguageHaskell2010

Bayes.BayesianNetwork

Contents

Description

Module for building Bayesian Networks

Synopsis

Bayesian Monad used to ease creation of Bayesian Networks

type BNMonad g f a = NetworkMonad g () f a Source

The Bayesian monad

runBN :: BNMonad DirectedSG f a -> (a, SBN f) Source

Create a network using the simple graph implementation The initialized nodes are replaced by the value. Returns the monad values and the built graph.

evalBN :: BNMonad DirectedSG f a -> a Source

Create a bayesian network but only returns the monad value. Mainly used for testing.

execBN :: BNMonad DirectedSG f a -> SBN f Source

Create a network but only returns the monad value. Mainly used for testing.

class Distribution d where Source

A distribution which can be used to create a factor

Methods

createFactor :: Factor f => [DV] -> d -> Maybe f Source

Create a factor from variables and a distributions for those variables

Instances

Variable creation

variable Source

Arguments

:: (Enum a, Bounded a, NamedGraph g) 
=> String

Variable name

-> a

Variable bounds

-> NetworkMonad g e f (TDV a) 

Define a Bayesian variable (name and bounds)

unamedVariable Source

Arguments

:: (Enum a, Bounded a, NamedGraph g) 
=> a

Variable bounds

-> NetworkMonad g e f (TDV a) 

Create a new unamed variable

variableWithSize Source

Arguments

:: NamedGraph g 
=> String

Variable name

-> Int

Variable size

-> NetworkMonad g e f DV 

Define a Bayesian variable (name and bounds)

tdv :: DV -> TDV s Source

Typed discrete variable

t :: t Source

Synonym for undefined because it is clearer to use t to set the Enum bounds of a variable

Creation of conditional probability tables

cpt :: (DirectedGraph g, BayesianDiscreteVariable v, BayesianDiscreteVariable vb) => v -> [vb] -> BNMonad g f v Source

Define a conditional probability between different variables Variables are ordered like FFF FFT FTF FTT TFF TFT TTF TTT and same for other enumeration keeping enumeration order Note that the reverse is important. We add the parents in such a way that ingoing will give a list of parents in the right order. This order must correspond to the order of values in the initialization.

proba :: (DirectedGraph g, BayesianDiscreteVariable v) => v -> BNMonad g f v Source

Define proba for a variable Values are ordered like FFF FFT FTF FTT TFF TFT TTF TTT and same for other enumeration keeping enumeration order

(~~) Source

Arguments

:: (DirectedGraph g, Factor f, Distribution d, BayesianDiscreteVariable v) 
=> BNMonad g f v

Discrete variable in the graph

-> d

List of values

-> BNMonad g f () 

Initialize the values of a factor

softEvidence Source

Arguments

:: (NamedGraph g, DirectedGraph g, Factor f) 
=> TDV Bool

Variable on which we want to define Soft evidence

-> BNMonad g f (TDV Bool)

Return a soft evidence node (for the factor encoding the soft evidence values) and an hard evidence node to activate the soft evidence observation

Create an auxiliairy node to force soft evidence

se Source

Arguments

:: Factor f 
=> TDV s

Soft evidence node

-> TDV s

Node on which the soft evidence is imposed

-> Double

Soft evidence (probability of right detection)

-> Maybe f 

Soft evidence factor

Creation of truth tables

logical :: (Factor f, DirectedGraph g) => TDV Bool -> LE -> BNMonad g f () Source

(.==.) :: Testable d v => d -> v -> LE infixl 8 Source

Create a variable instantiation using values from an enumeration

(.!.) :: LE -> LE Source

(.|.) :: LE -> LE -> LE infixl 5 Source

(.&.) :: LE -> LE -> LE infixl 6 Source

Noisy OR

noisyOR Source

Arguments

:: (DirectedGraph g, Factor f, NamedGraph g) 
=> [(TDV Bool, Double)]

Variables and probability of no influence

-> BNMonad g f (TDV Bool) 

Noisy OR. The Noisy-OR with leak can be implemented by using the standard Noisy-OR and a leak variable.