Safe Haskell | Safe-Infered |
---|

Sampling

Samplers for Bayesian network inferences

- data Sampler g a = forall b . Sampler !b !(GenIO -> IO (Sample g a)) !(GenIO -> SamplerGraph g a) !(SamplingScheme g b a)
- type Sample g a = BayesianNetwork g a
- runSampling :: (DirectedGraph g, FunctorWithVertex g) => Int -> Int -> Sampler g a -> IO [Sample g a]
- topologicalOrder :: DirectedGraph g => g a b -> [Vertex]
- discreteAncestralSampler :: (Factor f, FunctorWithVertex g, DirectedGraph g) => BayesianNetwork g f -> Sampler g DVI
- gibbsSampler :: (Factor f, FunctorWithVertex g, DirectedGraph g) => BayesianNetwork g f -> [DVI] -> Sampler g DVI
- gibbsMCMCSampler :: (Factor f, FunctorWithVertex g, DirectedGraph g) => BayesianNetwork g f -> [DVI] -> Sampler g DVI
- samplingHistograms :: (InstantiationValue i v, BayesianVariable i, FunctorWithVertex g, Graph g) => Int -> [Sample g i] -> Sample g [(Double, Double, Double)]
- histogram :: Int -> [Double] -> [(Double, Double, Double)]
- type ContinuousNetwork = SBN Distri
- type ContinuousSample = SBN CVI
- data Distri = D !CV !(DistributionF DirectedSG (Double, Double) CVI)
- continuousMCMCSampler :: ContinuousNetwork -> [CVI] -> Sampler DirectedSG CVI

# Types

Sampler defining the behavior of a sampling algorithms (init value, sample generation, how to select nodes in the grapg)

type Sample g a = BayesianNetwork g aSource

A sample (graph of instantiations)

# Sampling

:: (DirectedGraph g, FunctorWithVertex g) | |

=> Int | Number of used samples |

-> Int | Burnin samples before the used samples |

-> Sampler g a | Sampler |

-> IO [Sample g a] | List of generated samples |

Sample a bayesian network using a given sampling scheme

topologicalOrder :: DirectedGraph g => g a b -> [Vertex]Source

Return the vertices in topological order

# Sampling schemes

discreteAncestralSampler :: (Factor f, FunctorWithVertex g, DirectedGraph g) => BayesianNetwork g f -> Sampler g DVISource

Ancestral sampler which does not support evidence

:: (Factor f, FunctorWithVertex g, DirectedGraph g) | |

=> BayesianNetwork g f | Bayesian network |

-> [DVI] | Evidence |

-> Sampler g DVI | Sampler |

Gibbs sampling

:: (Factor f, FunctorWithVertex g, DirectedGraph g) | |

=> BayesianNetwork g f | Bayesian network |

-> [DVI] | Evidence |

-> Sampler g DVI | Sampler |

Gibbs sampling

# Sampling results

:: (InstantiationValue i v, BayesianVariable i, FunctorWithVertex g, Graph g) | |

=> Int | Number of bins |

-> [Sample g i] | Samples |

-> Sample g [(Double, Double, Double)] | Histogram with start bins and bin content |

Generate a graph of sampling histogram for each variable So, for a vertex v we have the posterior values p(v)

Compute the histogram of values

# For continuous distributions

type ContinuousNetwork = SBN DistriSource

type ContinuousSample = SBN CVISource

:: ContinuousNetwork | Bayesian network |

-> [CVI] | Evidence |

-> Sampler DirectedSG CVI | Sampler |

Gibbs sampling for continuous network