loadMRF
- pyagrum.loadMRF(filename, listeners=None, verbose=False)
load a MRF from a file with optional listeners and arguments
- Parameters:
filename (
str) – the name of the input filelisteners (
list[Object]) – list of functions to executeverbose (
bool) – whether to print or not warning messages
- Returns:
a MRF from a file using one of the
pyagrum.availableMRFExtssuffixes.- Return type:
- Raises:
pyagrum.GumIOError – If the file is not found (
FileNotFoundErrorfor a.pklfile).pyagrum.FatalError – If the content of the file is not valid.
pyagrum.InvalidArgument – If the extension is unknown, or if a listener is not callable.
Notes
Listeners could be added in order to monitor its loading.
pkl suffix is used to load a pickled MRF. In this case, options are ignored.
jgum/bgum suffixes use the native aGrUM JSON/binary format and also ignore listeners.
Example
import pyagrum as gum
gum.saveMRF(gum.fastMRF("A--B;B--C"), "model.uai")
mrf = gum.loadMRF("model.uai")
mrf.size()
# 3
len(mrf.factors())
# 2
# a listener is called with the progress of the loading (in %), then with 200 once the MRF is loaded
progress = []
mrf = gum.loadMRF("model.uai", listeners=[progress.append])
progress[:3], progress[-2:]
# ([1, 2, 3], [100, 200])