# Generate dataset from Bayesian network

Given a Bayesian network consisting of n random variables. What is the algorithm to generate the dataset from the given structure and associated conditional probability table for each random variable xi.

• bnlearn can do this for a small class of BN's. For more exotic distributions, you will need to generate random samples from the given distribution given the graph structure and paramters. – user2957945 Jun 13 '18 at 11:40
• Yes, I am interested in how to generate those random samples given the graph structure and parameters – letsBeePolite Jun 13 '18 at 19:37
• Generate the random distributions on the nodes without parents according to their distribution and parameters. Then update the children, according to the associations and the random generations of their parents. eg. say you have the graph A -> C <- B, and the parameters A ~ normal(0,1) ; B ~ normal(0,1) ; C ~ normal(1 + 2*A + B, 2^2) one way you can code this in R with sample size n=1000 . Generate parents nodes distributions A = rnorm(n, 0, 1) ; B = rnorm(n, 0, 1) , then the child C = rnorm(n, 1 + 2*A + B, 2^2) ; dat = data.frame(A, B, C) . – user2957945 Jun 13 '18 at 19:59