For a project, I need to create synthetic categorical data containing specific dependencies between the attributes. This can be done by sampling from a pre-defined Bayesian Network. After some exploration on the internet, I found that Pomegranate
is a good package for Bayesian Networks, however - as far as I'm concerned - it seems unpossible to sample from such a pre-defined Bayesian Network. As an example, model.sample()
raises a NotImplementedError
(despite this solution says so).
Does anyone know if there exists a library which provides a good interface for the construction and sampling of/from a Bayesian network?
Bayesian networks may be constructed either manually with knowledge of the underlying domain, or automatically from a large dataset by appropriate software. Keywords: Bayesian network, Causality, Complexity, Directed acyclic graph, Evidence, Factor, Graphical model, Node.
A Bayesian Network captures the joint probabilities of the events represented by the model. A Bayesian belief network describes the joint probability distribution for a set of variables.
Consider this concept in case of the three basic connections (serial, diverging, and converging) that are possible in Bayesian networks (see Figure 1): ...
A Bayesian network is a probability model defined over an acyclic directed graph. It is factored by using one conditional probability distribution for each variable in the model, whose distribution is given conditional on its parents in the graph.
Using pyAgrum, you just have to :
#import pyAgrum
import pyAgrum as gum
# create a BN
bn=gum.fastBN("A->B[3]<-C{yes|No}->D")
# specify some CPTs (randomly filled by fastBN)
bn.cpt("A").fillWith([0.3,0.7])
# and then generate a database
gum.generateCSV(bn,"sample.csv",1000,with_labels=True,random_order=False)
# which returns the LL(database)
the code in a notebook
See http://webia.lip6.fr/~phw/aGrUM/docs/last/notebooks/ for more notebooks using pyAgrum
Disclaimer: I am one of the authors of pyAgrum :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With