saveBN
- pyagrum.saveBN(bn, filename, allowModificationWhenSaving=None)
save a BN into a file using the format corresponding to one of the
pyagrum.availableBNExtssuffixes.- Parameters:
bn (
pyagrum.BayesNet) – the BN to savefilename (
str) – the name of the output fileallowModificationWhenSaving (
bool) – whether syntax errors in the BN should throw a FatalError or can be corrected. If None,pyagrum.config["core","allowModificationWhenSaving"]is used.
- Raises:
pyagrum.InvalidArgument – If the extension is unknown, or if a
.o3prmfile is saved withoutimport pyagrum.prm.- Return type:
None
Notes
pkl suffix is used to save a BN using pickle. In this case, options are ignored.
jgum/bgum suffixes use the native aGrUM JSON/binary format and also ignore
allowModificationWhenSaving.Warning
In the
.jgum,.bgum,.bifxmland.pklfiles, a variable whose name needs quotes (seepyagrum.quoteFastName) is written with a quoted name ('X-ray'[3]): pyAgrum 3.3.2 or older reads it with the quotes in the name.A variable which the fast syntax does not read back exactly (the labels
{10|9}of apyagrum.LabelizedVariable, a description…) is written as a JSON object in the.jgum,.bgumand.pklfiles: the file is then of version 2.0 of the GUM format, which pyAgrum 3.4 or older cannot read.
Example
import pyagrum as gum
bn = gum.fastBN("A->B<-C")
gum.saveBN(bn, "model.bif") # the format is given by the extension
gum.loadBN("model.bif").sizeArcs()
# 2