saveMRF
- pyagrum.saveMRF(mn, filename)
save a MRF into a file using the format corresponding to one of the
pyagrum.availableMRFExtssuffixes.- Parameters:
mn (
pyagrum.MarkovRandomField) – the MRF to savefilename (
str) – the name of the output file
- Raises:
pyagrum.InvalidArgument – If the extension is unknown.
- Return type:
None
Notes
pkl suffix is used to save a MRF using pickle.
jgum/bgum suffixes use the native aGrUM JSON/binary format.
Warning
In the
.jgum,.bgumand.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
mrf = gum.fastMRF("A--B--C")
gum.saveMRF(mrf, "model.uai")
gum.loadMRF("model.uai").factors()
# [{0, 1, 2}]