BayesNet.saveGUMstring

BayesNet.saveGUMstring(indent=None)

Save the Bayesian network as a jgum string.

Parameters:

indent (int, optional) – JSON indentation: -1 for the most compact output, N>=0 to pretty-print with N spaces. Defaults to pyagrum.config["core","jgumIndent"].

Returns:

the jgum string

Return type:

str

Example

import pyagrum as gum

bn = gum.fastBN("A->B")
s = bn.saveGUMstring(indent=-1)  # a compact jgum (JSON) string
s.startswith("{")
# True
bn2 = gum.BayesNet()
bn2.loadGUMstring(s)
bn2.hasSameStructure(bn)
# True

# a variable which the fast syntax does not read back exactly is written as a JSON object
bn3 = gum.BayesNet()
bn3.add(gum.LabelizedVariable("L", "", ["10", "9"]))  # "L{10|9}" would be read as a RangeVariable 9..10
s = bn3.saveGUMstring(indent=-1)
'"labels":["10","9"]' in s
# True
bn4 = gum.BayesNet()
bn4.loadGUMstring(s)
bn4.variable("L").labels()
# ('10', '9')

Class

BayesNet