Comparison of Bayesian networks

To compare Bayesian networks, one can compare their structure
(see pyagrum.lib.bn_vs_bn.GraphicalBNComparator).
However BNs can also be compared as probability distributions.
class pyagrum.ExactBNdistance(*args)
Section titled “class pyagrum.ExactBNdistance(*args)”Class representing exacte computation of divergence and distance between BNs
ExactBNdistance(P,Q) -> ExactBNdistance : Parameters: : - P (pyagrum.BayesNet) a Bayesian network - Q (pyagrum.BayesNet) another Bayesian network to compare with the first one
ExactBNdistance(ebnd) -> ExactBNdistance : Parameters: : - ebnd (pyagrum.ExactBNdistance) the exact BNdistance to copy
- Raises: pyagrum.OperationNotAllowed – If the 2BNs have not the same domain size of compatible node sets
compute()
Section titled “compute()”- Returns: a dictionnary containing the different values after the computation.
- Return type:
dict[str,object]
class pyagrum.GibbsBNdistance(*args)
Section titled “class pyagrum.GibbsBNdistance(*args)”Class representing a Gibbs-Approximated computation of divergence and distance between BNs
GibbsBNdistance(P,Q) -> GibbsBNdistance : Parameters: : - P (pyagrum.BayesNet) – a Bayesian network - Q (pyagrum.BayesNet) – another Bayesian network to compare with the first one
GibbsBNdistance(gbnd) -> GibbsBNdistance : Parameters: : - gbnd (pyagrum.GibbsBNdistance) – the Gibbs BNdistance to copy
- Raises: pyagrum.OperationNotAllowed – If the 2BNs have not the same domain size of compatible node sets
burnIn()
Section titled “burnIn()”- Returns: size of burn in on number of iteration
- Return type:
int
compute()
Section titled “compute()”- Returns: a dictionnary containing the different values after the computation.
- Return type:
dict[str,object]
continueApproximationScheme(error)
Section titled “continueApproximationScheme(error)”Continue the approximation scheme.
- Parameters:
error (
float) - Return type:
bool
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type:
float
disableEpsilon()
Section titled “disableEpsilon()”Disable epsilon as a stopping criterion.
- Return type:
None
disableMaxIter()
Section titled “disableMaxIter()”Disable max iterations as a stopping criterion.
- Return type:
None
disableMaxTime()
Section titled “disableMaxTime()”Disable max time as a stopping criterion.
- Return type:
None
disableMinEpsilonRate()
Section titled “disableMinEpsilonRate()”Disable a min epsilon rate as a stopping criterion.
- Return type:
None
enableEpsilon()
Section titled “enableEpsilon()”Enable epsilon as a stopping criterion.
- Return type:
None
enableMaxIter()
Section titled “enableMaxIter()”Enable max iterations as a stopping criterion.
- Return type:
None
enableMaxTime()
Section titled “enableMaxTime()”Enable max time as a stopping criterion.
- Return type:
None
enableMinEpsilonRate()
Section titled “enableMinEpsilonRate()”Enable a min epsilon rate as a stopping criterion.
- Return type:
None
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type:
float
history()
Section titled “history()”- Returns: the scheme history
- Return type:
tuple[float,...] - Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
initApproximationScheme()
Section titled “initApproximationScheme()”Initiate the approximation scheme.
- Return type:
None
isDrawnAtRandom()
Section titled “isDrawnAtRandom()”- Returns: True if variables are drawn at random
- Return type:
bool
isEnabledEpsilon()
Section titled “isEnabledEpsilon()”- Returns: True if epsilon is used as a stopping criterion.
- Return type:
bool
isEnabledMaxIter()
Section titled “isEnabledMaxIter()”- Returns: True if max iterations is used as a stopping criterion
- Return type:
bool
isEnabledMaxTime()
Section titled “isEnabledMaxTime()”- Returns: True if max time is used as a stopping criterion
- Return type:
bool
isEnabledMinEpsilonRate()
Section titled “isEnabledMinEpsilonRate()”- Returns: True if epsilon rate is used as a stopping criterion
- Return type:
bool
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type:
int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type:
float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type:
str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type:
float
nbrDrawnVar()
Section titled “nbrDrawnVar()”- Returns: the number of variable drawn at each iteration
- Return type:
int
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type:
int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type:
int - Raises: pyagrum.OutOfBounds – If p<1
remainingBurnIn()
Section titled “remainingBurnIn()”- Returns: the number of remaining burn in
- Return type:
int
setBurnIn(b)
Section titled “setBurnIn(b)”- Parameters:
b (
int) – size of burn in on number of iteration - Return type:
None
setDrawnAtRandom(_atRandom)
Section titled “setDrawnAtRandom(_atRandom)”- Parameters:
_atRandom (
bool) – indicates if variables should be drawn at random - Return type:
None
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters:
eps (
float) – the epsilon we want to use - Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters:
max (
int) – the maximum number of iteration - Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters:
rate (
float) – the minimal epsilon rate - Return type:
None
setNbrDrawnVar(_nbr)
Section titled “setNbrDrawnVar(_nbr)”- Parameters:
_nbr (
int) – the number of variables to be drawn at each iteration - Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters:
p (
int) – number of samples between 2 stopping - Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters:
v (
bool) – verbosity - Return type:
None
startOfPeriod()
Section titled “startOfPeriod()”- Returns: True if it is a start of a period
- Return type:
bool
stateApproximationScheme()
Section titled “stateApproximationScheme()”- Returns: the state of the approximation scheme
- Return type:
int
stopApproximationScheme()
Section titled “stopApproximationScheme()”Stop the approximation scheme.
- Return type:
None
updateApproximationScheme(incr=1)
Section titled “updateApproximationScheme(incr=1)”Update the approximation scheme.
- Parameters:
incr (
int) - Return type:
None
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type:
bool
class pyagrum.MCBNDistance(*args)
Section titled “class pyagrum.MCBNDistance(*args)”Class representing a Monte-Carlo-approximated computation of divergence and distance between BNs
Unlike GibbsBNdistance, each sample is drawn independently (forward sampling in topological order), so there is no Markov chain and no burn-in to configure.
MCBNDistance(P,Q) -> MCBNDistance : Parameters: : - P (pyagrum.BayesNet) – a Bayesian network - Q (pyagrum.BayesNet) – another Bayesian network to compare with the first one
MCBNDistance(mcbnd) -> MCBNDistance : Parameters: : - mcbnd (pyagrum.MCBNDistance) – the Monte Carlo BNdistance to copy
- Raises: pyagrum.OperationNotAllowed – If the 2BNs have not the same domain size of compatible node sets
compute()
Section titled “compute()”- Returns: a dictionnary containing the different values after the computation.
- Return type:
dict[str,object]
continueApproximationScheme(error)
Section titled “continueApproximationScheme(error)”Continue the approximation scheme.
- Parameters:
error (
float) - Return type:
bool
currentTime()
Section titled “currentTime()”- Returns: get the current running time in second (float)
- Return type:
float
disableEpsilon()
Section titled “disableEpsilon()”Disable epsilon as a stopping criterion.
- Return type:
None
disableMaxIter()
Section titled “disableMaxIter()”Disable max iterations as a stopping criterion.
- Return type:
None
disableMaxTime()
Section titled “disableMaxTime()”Disable max time as a stopping criterion.
- Return type:
None
disableMinEpsilonRate()
Section titled “disableMinEpsilonRate()”Disable a min epsilon rate as a stopping criterion.
- Return type:
None
enableEpsilon()
Section titled “enableEpsilon()”Enable epsilon as a stopping criterion.
- Return type:
None
enableMaxIter()
Section titled “enableMaxIter()”Enable max iterations as a stopping criterion.
- Return type:
None
enableMaxTime()
Section titled “enableMaxTime()”Enable max time as a stopping criterion.
- Return type:
None
enableMinEpsilonRate()
Section titled “enableMinEpsilonRate()”Enable a min epsilon rate as a stopping criterion.
- Return type:
None
epsilon()
Section titled “epsilon()”- Returns: the value of epsilon
- Return type:
float
history()
Section titled “history()”- Returns: the scheme history
- Return type:
tuple[float,...] - Raises: pyagrum.OperationNotAllowed – If the scheme did not performed or if verbosity is set to false
initApproximationScheme()
Section titled “initApproximationScheme()”Initiate the approximation scheme.
- Return type:
None
isEnabledEpsilon()
Section titled “isEnabledEpsilon()”- Returns: True if epsilon is used as a stopping criterion.
- Return type:
bool
isEnabledMaxIter()
Section titled “isEnabledMaxIter()”- Returns: True if max iterations is used as a stopping criterion
- Return type:
bool
isEnabledMaxTime()
Section titled “isEnabledMaxTime()”- Returns: True if max time is used as a stopping criterion
- Return type:
bool
isEnabledMinEpsilonRate()
Section titled “isEnabledMinEpsilonRate()”- Returns: True if epsilon rate is used as a stopping criterion
- Return type:
bool
maxIter()
Section titled “maxIter()”- Returns: the criterion on number of iterations
- Return type:
int
maxTime()
Section titled “maxTime()”- Returns: the timeout(in seconds)
- Return type:
float
messageApproximationScheme()
Section titled “messageApproximationScheme()”- Returns: the approximation scheme message
- Return type:
str
minEpsilonRate()
Section titled “minEpsilonRate()”- Returns: the value of the minimal epsilon rate
- Return type:
float
nbrIterations()
Section titled “nbrIterations()”- Returns: the number of iterations
- Return type:
int
periodSize()
Section titled “periodSize()”- Returns: the number of samples between 2 stopping
- Return type:
int - Raises: pyagrum.OutOfBounds – If p<1
remainingBurnIn()
Section titled “remainingBurnIn()”- Returns: the number of remaining burn in
- Return type:
int
setEpsilon(eps)
Section titled “setEpsilon(eps)”- Parameters:
eps (
float) – the epsilon we want to use - Raises: pyagrum.OutOfBounds – If eps<0
- Return type:
None
setMaxIter(max)
Section titled “setMaxIter(max)”- Parameters:
max (
int) – the maximum number of iteration - Raises: pyagrum.OutOfBounds – If max <= 1
- Return type:
None
setMaxTime(timeout)
Section titled “setMaxTime(timeout)”- Parameters:
- tiemout (float) – stopping criterion on timeout (in seconds)
- timeout (
float)
- Raises: pyagrum.OutOfBounds – If timeout<=0.0
- Return type:
None
setMinEpsilonRate(rate)
Section titled “setMinEpsilonRate(rate)”- Parameters:
rate (
float) – the minimal epsilon rate - Return type:
None
setPeriodSize(p)
Section titled “setPeriodSize(p)”- Parameters:
p (
int) – number of samples between 2 stopping - Raises: pyagrum.OutOfBounds – If p<1
- Return type:
None
setVerbosity(v)
Section titled “setVerbosity(v)”- Parameters:
v (
bool) – verbosity - Return type:
None
startOfPeriod()
Section titled “startOfPeriod()”- Returns: True if it is a start of a period
- Return type:
bool
stateApproximationScheme()
Section titled “stateApproximationScheme()”- Returns: the state of the approximation scheme
- Return type:
int
stopApproximationScheme()
Section titled “stopApproximationScheme()”Stop the approximation scheme.
- Return type:
None
updateApproximationScheme(incr=1)
Section titled “updateApproximationScheme(incr=1)”Update the approximation scheme.
- Parameters:
incr (
int) - Return type:
None
verbosity()
Section titled “verbosity()”- Returns: True if the verbosity is enabled
- Return type:
bool
In general, pyagrum.MCBNDistance converges better (faster, with a smaller variance)
than pyagrum.GibbsBNdistance for a given number of iterations. This is expected:
computing a distance between two BNs does not involve any observation (hard evidence) to
account for during sampling, so there is no need for the Markov chain machinery (mixing,
burn-in) that Gibbs sampling relies on to handle evidence. Drawing independent samples
directly from P is both simpler and, here, more efficient.
SEE ALSO
Section titled “SEE ALSO”other pyagrum.lib modules
: pyagrum.lib.bn_vs_bn.GraphicalBNComparator for structural comparison of two Bayesian networks.
Structural comparison metrics
: pyagrum.StructuralMetrics, the (lower-level) C++ class computing precision,
recall, F-score, SHD and SID, used internally by pyagrum.lib.bn_vs_bn.GraphicalBNComparator.