Generation of database

class pyagrum.BNDatabaseGenerator(bn)

BNDatabaseGenerator is used to easily generate databases from a pyagrum.BayesNet.

Parameters:

bn (pyagrum.BayesNet) – the Bayesian network used to generate data.

Scientific notes

BNDatabaseGenerator draws independent samples of a Bayesian network by probabilistic logic sampling [1]: the variables are drawn in a topological order, each from its CPT given the values already drawn for its parents (see pyagrum.MonteCarloSampling). With evidence, a sample that contradicts it is rejected, so that the database is a sample of the posterior; drawSamples then counts the accepted rows, and stops with an error after sampling.maxConsecutiveRejections consecutive rejections. The value returned is the log-likelihood (base 2) of the database in the network. The value written for a discretized variable is, by default, drawn uniformly in the interval of its label (or its middle, or the label itself).

Methods

bn()

Get the Bayesian network used to generate the samples

drawSamples()

Generate and stock a database generated by sampling the Bayesian network.

log2likelihood()

Get the log2likelihood of the generated database

samplesAt()

Get the value of the database in (row,col)

samplesLabelAt()

Get the label of the database in (row,col)

samplesNbCols()

return the number of columns in the samples

samplesNbRows()

return the number of rows in the samples

setAntiTopologicalVarOrder()

Select an anti-topological order for the variables in the database.

setDiscretizedLabelModeInterval()

Set the discretized label mode to INTERVAL : sampling a pyagrum.DiscretizedVariable will give a deterministic value : the string representation of the interval.

setDiscretizedLabelModeMedian()

Set the discretized label mode to MEDIAN : sampling a pyagrum.DiscretizedVariable will give a deterministic value : the median of the uniform distribution on that interval.

setDiscretizedLabelModeRandom()

Set the discretized label mode to RANDOM (default mode) : sampling a pyagrum.DiscretizedVariable will give a random value from the uniform distribution on that interval.

setRandomVarOrder()

Select an random order for the variables in the database.

setTopologicalVarOrder()

Select a topological order for the variables in the database.

setVarOrder()

Set a specific order with a list of names

setVarOrderFromCSV()

Set the same order than in a csv file

toCSV()

generates csv representing the generated database.

to_pandas()

export the samples as a pandas.DataFrame.

varOrder()

The current order of the variables (as a tuple of node ids).

varOrderNames()

The current order of the variables (as a tuple of names).