Safe Haskell | None |
---|---|

Language | Haskell2010 |

Module for building Bayesian Networks

- type BNMonad g f a = NetworkMonad g () f a
- runBN :: BNMonad DirectedSG f a -> (a, SBN f)
- evalBN :: BNMonad DirectedSG f a -> a
- execBN :: BNMonad DirectedSG f a -> SBN f
- class Distribution d where
- createFactor :: Factor f => [DV] -> d -> Maybe f

- variable :: (Enum a, Bounded a, NamedGraph g) => String -> a -> NetworkMonad g e f (TDV a)
- unamedVariable :: (Enum a, Bounded a, NamedGraph g) => a -> NetworkMonad g e f (TDV a)
- variableWithSize :: NamedGraph g => String -> Int -> NetworkMonad g e f DV
- tdv :: DV -> TDV s
- t :: t
- cpt :: (DirectedGraph g, BayesianDiscreteVariable v, BayesianDiscreteVariable vb) => v -> [vb] -> BNMonad g f v
- proba :: (DirectedGraph g, BayesianDiscreteVariable v) => v -> BNMonad g f v
- (~~) :: (DirectedGraph g, Factor f, Distribution d, BayesianDiscreteVariable v) => BNMonad g f v -> d -> BNMonad g f ()
- softEvidence :: (NamedGraph g, DirectedGraph g, Factor f) => TDV Bool -> BNMonad g f (TDV Bool)
- se :: Factor f => TDV s -> TDV s -> Double -> Maybe f
- logical :: (Factor f, DirectedGraph g) => TDV Bool -> LE -> BNMonad g f ()
- (.==.) :: Testable d v => d -> v -> LE
- (.!.) :: LE -> LE
- (.|.) :: LE -> LE -> LE
- (.&.) :: LE -> LE -> LE
- noisyOR :: (DirectedGraph g, Factor f, NamedGraph g) => [(TDV Bool, Double)] -> BNMonad g f (TDV Bool)

# Bayesian Monad used to ease creation of Bayesian Networks

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

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

Create a factor from variables and a distributions for those variables

Real a => Distribution [a] Source |

## Variable creation

:: (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)

:: (Enum a, Bounded a, NamedGraph g) | |

=> a | Variable bounds |

-> NetworkMonad g e f (TDV a) |

Create a new unamed variable

:: NamedGraph g | |

=> String | Variable name |

-> Int | Variable size |

-> NetworkMonad g e f DV |

Define a Bayesian variable (name and bounds)

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

:: (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

:: (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

:: 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

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

Create a variable instantiation using values from an enumeration