`gum.config` :the configuration object for pyAgrum
![]() | ![]() |
import pyagrum as gum
print("=" * 35)print(gum.config)print("=" * 35)===================================[core] maxnumberofthreads = -1 jgumindent = -1 allowmodificationwhensaving = False epsiloncoarse = 1e-2 epsilonstandard = 1e-6 epsilonfine = 1e-10[approximation] epsilon = 0.05 minepsilonrate = 0.01 maxiter = 10000 maxtime = 1.0 burnin = 0 periodsize = 1 verbosity = False[sampling] maxiter = 10000000 epsilon = 0.01 maxtime = 6000.0 periodsize = 100 minepsilonrate = 1e-5 verbosity = False[gibbs] epsilon = 0.20189651799465538 minepsilonrate = 0.006737946999085467 burnin = 300 percentdrawnsample = 50 drawnatrandom = True[lbp] maxiter = 100 epsilon = 1e-8 minepsilonrate = 1e-10 periodsize = 1 verbosity = False[loopySampling] virtuallbpsize = 5000[gibbsKL] maxiter = 10000000 epsilon = 1e-10 minepsilonrate = 1e-10 periodsize = 200 verbosity = False burnin = 2000 maxtime = 6000.0 percentdrawnsample = 10 drawnatrandom = True[mcKL] maxiter = 10000000 epsilon = 1e-10 minepsilonrate = 1e-10 periodsize = 200 verbosity = False maxtime = 6000.0[learning] bnlearnerpreferredalgo = MIIC alpha = 0.05 priorweight = 1.0 emnoise = 0.1 tabulistsize = 100 tabunbdecrease = 2[tensor] maxrowsconsole = 6 columnwidthconsole = 9[notebook] arccolor = #4A4A4A nodebgcolor = #404040 nodefgcolor = adaptive graphsize = 5 graphrankdir = TB graphlayout = dot markovrandomfieldview = factorgraph junctiontreegraphsize = 10 junctiontreewithnames = True junctiontreeseparatorbgcolor = palegreen junctiontreeseparatorfgcolor = adaptive junctiontreeseparatorfontsize = 8 junctiontreecliquebgcolor = burlywood junctiontreecliquefgcolor = adaptive junctiontreecliquefontsize = 10 junctiontreemapcliquescale = 0.3 junctiontreemapsepscale = 0.1 junctiontreemapedgelen = 1 junctiontreemapsize = 10 tensor_visible_digits = 4 tensor_with_colors = True tensor_color_0 = #FF7F64 tensor_color_1 = #7FFF64 tensor_with_fraction = False tensor_fraction_limit = 50 tensor_fraction_round_error = 1e-6 tensor_fraction_with_latex = True histogram_horizontal_visible_digits = 2 histogram_vertical_visible_digits = 2 histogram_horizontal_threshold = 8 histogram_line_threshold = 40 histogram_color = darkseagreen histogram_edge_color = darkgreen histogram_use_percent = True histogram_discretized_visualisation = histogram histogram_discretized_scale = 1.0 export_pdf_margin_x = 50 export_pdf_margin_y = 37 histogram_mode = compact histogram_epsilon = 1e-8 tensor_parent_values = merge figure_facecolor = #E0E0E0 flow_background_color = transparent flow_border_color = transparent flow_border_width = 0 graph_format = svg show_inference_time = True evidence_bgcolor = sandybrown evidence_fgcolor = black node_cmap = Pastel1 arc_cmap = BuGn edge_cmap = BuGn graph_inference_size = 8 graphdiff_missing_style = dashed graphdiff_missing_color = red graphdiff_overflow_style = dashed graphdiff_overflow_color = purple graphdiff_reversed_style = solid graphdiff_reversed_color = purple graphdiff_correct_style = solid graphdiff_correct_color = grey[factorgraph] nodebgcolor = coral nodefgcolor = adaptive factorbgcolor = burlywood edgelength = 0.7 graphlayout = neato edge_length_inference = 0.9[dynamicBN] graphsize = 6 timeslicebgcolor = #DDDDDD replicatedslicebgcolor = lightcyan atemporalbgcolor = lightyellow[influenceDiagram] graphsize = 6 chancebgcolor = #808080 chancefgcolor = adaptive utilitybgcolor = #50508A utilityfgcolor = adaptive decisionbgcolor = #9A5050 decisionfgcolor = adaptive chanceshape = ellipse utilityshape = hexagon decisionshape = box decisionarcstyle = tapered, bold, dotted utilityarcstyle = dashed id_inference_size = 6 utility_visible_digits = 2 utility_show_stdev = True utility_show_loss = False[credalnet] nodebgcolor = #404040 nodefgcolor = adaptive histo_max_color = #BBFFAA[causal] showlatentnames = False graphsize = 2.5 nodebgcolor = #404040 nodefgcolor = adaptive latentbgcolor = #A08080 latentfgcolor = adaptive latex_do_prefix = \text{do}( latex_do_suffix = )[ROC] draw_color = #008800 fill_color = #AAEEAA[ctbn] show_latent_names = False graph_size = 2.5 node_bgcolor = #404040 node_fgcolor = white latent_bgcolor = #A08080 latent_fgcolor = black[bnmixture] graph_size = 5 line_size = 1.0 head_size = 0.25 arrow_type = normal arc_cmap = Greens arc_color = #4A4A4A arc_style = solid node_bgcolor = #404040 node_fgcolor = white layout = fdp overlap = 0 bar_capsize = 1.5 bar_height = 0.8 boot_histo_scale = 2.0 histo_scale = 1.0 correct_arc_style = solid correct_arc_color = green incorrect_arc_style = dashed incorrect_arc_color = green left_quantile = 0.2 right_quantile = 0.8===================================pyagrum.ini
Section titled “pyagrum.ini”gum.config is the configuration singleton of the aGrUM C++ library (gum::Configuration), which holds all the logic (types, checks, hooks, loading and saving). The configuration is a mix between the defaults (those of aGrUM followed by those of pyAgrum, embedded in the library, which exactly define the possible section and property) and a file pyagrum.ini (if present in the current folder) that contains only the changed properties : this file never creates a section or a property.
section and key are case insensitive.
Each property is declared in the defaults by a metadata line ### type :: one-line documentation where the type is int, float, bool, str, an enumeration of the allowed values (svg|png) or a deprecation (deprecated -> section.key).
config constantly keeps track of the differences between defaults and actual values :
Section titled “config constantly keeps track of the differences between defaults and actual values :”gum.config["dynamicBN", "graphSize"] = 10
print("Configuration only for the current session")print("-" * 40)gum.config.diff()Configuration only for the current session----------------------------------------[dynamicBN] graphsize = 10## if there is a local modification, __repr__ shows only the diff other wise it show all propertiesgum.config[dynamicBN] graphsize = 10## __str__ shows all the propertiesprint(gum.config)[core] maxnumberofthreads = -1 jgumindent = -1 allowmodificationwhensaving = False epsiloncoarse = 1e-2 epsilonstandard = 1e-6 epsilonfine = 1e-10[approximation] epsilon = 0.05 minepsilonrate = 0.01 maxiter = 10000 maxtime = 1.0 burnin = 0 periodsize = 1 verbosity = False[sampling] maxiter = 10000000 epsilon = 0.01 maxtime = 6000.0 periodsize = 100 minepsilonrate = 1e-5 verbosity = False[gibbs] epsilon = 0.20189651799465538 minepsilonrate = 0.006737946999085467 burnin = 300 percentdrawnsample = 50 drawnatrandom = True[lbp] maxiter = 100 epsilon = 1e-8 minepsilonrate = 1e-10 periodsize = 1 verbosity = False[loopySampling] virtuallbpsize = 5000[gibbsKL] maxiter = 10000000 epsilon = 1e-10 minepsilonrate = 1e-10 periodsize = 200 verbosity = False burnin = 2000 maxtime = 6000.0 percentdrawnsample = 10 drawnatrandom = True[mcKL] maxiter = 10000000 epsilon = 1e-10 minepsilonrate = 1e-10 periodsize = 200 verbosity = False maxtime = 6000.0[learning] bnlearnerpreferredalgo = MIIC alpha = 0.05 priorweight = 1.0 emnoise = 0.1 tabulistsize = 100 tabunbdecrease = 2[tensor] maxrowsconsole = 6 columnwidthconsole = 9[notebook] arccolor = #4A4A4A nodebgcolor = #404040 nodefgcolor = adaptive graphsize = 5 graphrankdir = TB graphlayout = dot markovrandomfieldview = factorgraph junctiontreegraphsize = 10 junctiontreewithnames = True junctiontreeseparatorbgcolor = palegreen junctiontreeseparatorfgcolor = adaptive junctiontreeseparatorfontsize = 8 junctiontreecliquebgcolor = burlywood junctiontreecliquefgcolor = adaptive junctiontreecliquefontsize = 10 junctiontreemapcliquescale = 0.3 junctiontreemapsepscale = 0.1 junctiontreemapedgelen = 1 junctiontreemapsize = 10 tensor_visible_digits = 4 tensor_with_colors = True tensor_color_0 = #FF7F64 tensor_color_1 = #7FFF64 tensor_with_fraction = False tensor_fraction_limit = 50 tensor_fraction_round_error = 1e-6 tensor_fraction_with_latex = True histogram_horizontal_visible_digits = 2 histogram_vertical_visible_digits = 2 histogram_horizontal_threshold = 8 histogram_line_threshold = 40 histogram_color = darkseagreen histogram_edge_color = darkgreen histogram_use_percent = True histogram_discretized_visualisation = histogram histogram_discretized_scale = 1.0 export_pdf_margin_x = 50 export_pdf_margin_y = 37 histogram_mode = compact histogram_epsilon = 1e-8 tensor_parent_values = merge figure_facecolor = #E0E0E0 flow_background_color = transparent flow_border_color = transparent flow_border_width = 0 graph_format = svg show_inference_time = True evidence_bgcolor = sandybrown evidence_fgcolor = black node_cmap = Pastel1 arc_cmap = BuGn edge_cmap = BuGn graph_inference_size = 8 graphdiff_missing_style = dashed graphdiff_missing_color = red graphdiff_overflow_style = dashed graphdiff_overflow_color = purple graphdiff_reversed_style = solid graphdiff_reversed_color = purple graphdiff_correct_style = solid graphdiff_correct_color = grey[factorgraph] nodebgcolor = coral nodefgcolor = adaptive factorbgcolor = burlywood edgelength = 0.7 graphlayout = neato edge_length_inference = 0.9[dynamicBN] graphsize = 10 timeslicebgcolor = #DDDDDD replicatedslicebgcolor = lightcyan atemporalbgcolor = lightyellow[influenceDiagram] graphsize = 6 chancebgcolor = #808080 chancefgcolor = adaptive utilitybgcolor = #50508A utilityfgcolor = adaptive decisionbgcolor = #9A5050 decisionfgcolor = adaptive chanceshape = ellipse utilityshape = hexagon decisionshape = box decisionarcstyle = tapered, bold, dotted utilityarcstyle = dashed id_inference_size = 6 utility_visible_digits = 2 utility_show_stdev = True utility_show_loss = False[credalnet] nodebgcolor = #404040 nodefgcolor = adaptive histo_max_color = #BBFFAA[causal] showlatentnames = False graphsize = 2.5 nodebgcolor = #404040 nodefgcolor = adaptive latentbgcolor = #A08080 latentfgcolor = adaptive latex_do_prefix = \text{do}( latex_do_suffix = )[ROC] draw_color = #008800 fill_color = #AAEEAA[ctbn] show_latent_names = False graph_size = 2.5 node_bgcolor = #404040 node_fgcolor = white latent_bgcolor = #A08080 latent_fgcolor = black[bnmixture] graph_size = 5 line_size = 1.0 head_size = 0.25 arrow_type = normal arc_cmap = Greens arc_color = #4A4A4A arc_style = solid node_bgcolor = #404040 node_fgcolor = white layout = fdp overlap = 0 bar_capsize = 1.5 bar_height = 0.8 boot_histo_scale = 2.0 histo_scale = 1.0 correct_arc_style = solid correct_arc_color = green incorrect_arc_style = dashed incorrect_arc_color = green left_quantile = 0.2 right_quantile = 0.8Accessors
Section titled “Accessors”Getter
Section titled “Getter”print(gum.config["notebook", "evidence_bgcolor"])print(gum.config.get("notebook", "evidence_bgcolor"))sandybrownsandybrownSetter
Section titled “Setter”gum.config["notebook", "evidence_bgcolor"] = "papayawhip"gum.config["causal", "graphSize"] = 1.9gum.config # once again, only the diff with defaults[notebook] evidence_bgcolor = papayawhip[dynamicBN] graphsize = 10[causal] graphsize = 1.9constant structure, mutable content
Section titled “constant structure, mutable content”The structure section.key is fixed by default and readonly : one can only change the value of an existing property
try: gum.config["AAA", "OOO"] = 1except SyntaxError as e: print(f"Syntax error : {e.msg}")Syntax error : Section 'AAA' unknown in configuration.try: gum.config["causal", "OOO"] = 1except SyntaxError as e: print(f"Syntax error : {e.msg}")Syntax error : Key 'causal.OOO' unknown in configuration.Typed properties
Section titled “Typed properties”Each property has a declared type: int, float, bool, str or an enumeration of the allowed values. The setter refuses a value that does not respect this type and canonicalizes the accepted values: a boolean can be written True/False, 0/1, off/on or no/yes (case-insensitive) but is always stored as True or False, an enumerated value is stored with its declared casing.
try: gum.config["notebook", "tensor_visible_digits"] = "abc"except ValueError as e: print(f"Value error : {e}")Value error : [pyAgrum] Invalid argument: 'abc' must be an int for 'notebook.tensor_visible_digits'.try: gum.config["notebook", "graph_format"] = "jpg"except ValueError as e: print(f"Value error : {e}")Value error : [pyAgrum] Invalid argument: 'jpg' must be one of svg|png for 'notebook.graph_format'.## enumerated values are case-insensitive and canonicalizedgum.config["notebook", "graph_format"] = "PNG"print(gum.config["notebook", "graph_format"])gum.config["notebook", "graph_format"] = "svg"png## boolean values accept several spellings (case-insensitive) and are canonicalized to True/Falsetry: gum.config["notebook", "tensor_with_colors"] = "maybe"except ValueError as e: print(f"Value error : {e}")
gum.config["notebook", "tensor_with_colors"] = "off"print(gum.config["notebook", "tensor_with_colors"])gum.config["notebook", "tensor_with_colors"] = "YES"print(gum.config["notebook", "tensor_with_colors"])gum.config["notebook", "tensor_with_colors"] = TrueValue error : [pyAgrum] Invalid argument: 'maybe' must be a boolean (False/True, 0/1, Off/On, No/Yes) for 'notebook.tensor_with_colors'.FalseTrueDocumentation of the properties
Section titled “Documentation of the properties”The declared type and a one-line documentation are available for every property with gum.config.doc :
print(gum.config.doc("notebook", "tensor_visible_digits"))print(gum.config.doc("notebook", "graph_format"))print(gum.config.doc("notebook", "tensor_parent_values"))int[0,] :: number of visible digits when displaying a tensor in a notebooksvg|png :: format used to render graphs in a notebookmerge|revmerge|nomerge :: how to display the parent values in a tensorDeprecated properties
Section titled “Deprecated properties”A property can be marked as deprecated in the defaults, with a replacement key (### deprecated -> section.key :: message). In that case :
- reading or writing the old key emits a
DeprecationWarningand transparently uses the replacement key, - the old key never appears in
diff(),save()orprint(gum.config), - if a
pyagrum.inistill uses the old key,gum.config.load()accepts it (with a warning) and applies it to the new key, andgum.config.save()then writespyagrum.iniwith the new key : user files are migrated when saved.
For instance, the properties whose name started with default_ in aGrUM 3.2.1 (such as gum.config["notebook", "default_node_bgcolor"]) have been renamed without this prefix, and the keys that are also used by the C++ graph drawing are now in lowerCamelCase (gum.config["notebook", "nodeBgColor"] instead of node_bgcolor) : the old names are deprecated properties and are still accepted.
properties as string
Section titled “properties as string”All the properties are stored as string !
gum.config["notebook", "graphSize"]'5'gum.config["notebook", "graphSize"] = 10gum.config["notebook", "graphSize"]'10'… but can be typed using typed
Section titled “… but can be typed using typed”Since every property has a declared type, gum.config.typed returns the value converted to this type (enumerations stay strings). The historical accessors asInt, asFloat, asBool are deprecated since 3.1.0: they emit a DeprecationWarning and delegate to typed.
gum.config["dynamicBN", "graphSize"]'10'gum.config.typed["dynamicBN", "graphSize"]'10'print(type(gum.config["dynamicBN", "graphSize"]))print(type(gum.config.typed["dynamicBN", "graphSize"]))<class ‘str’> <class ‘str’>
if gum.config["causal", "showLatentNames"] == "False": print("not very convenient test")if not gum.config.typed["causal", "showLatentNames"]: print("better test")not very convenient testbetter testReset, reload, save
Section titled “Reset, reload, save”The configuration can be saved in the current folder (gum.config.save()).
The configuration can be restored from the default (reset) or the current saved state (reload).
gum.config.reset() # back to defaultsgum.config # no diff => shows all the properties# no customized property[core] maxnumberofthreads = -1 jgumindent = -1 allowmodificationwhensaving = False epsiloncoarse = 1e-2 epsilonstandard = 1e-6 epsilonfine = 1e-10[approximation] epsilon = 0.05 minepsilonrate = 0.01 maxiter = 10000 maxtime = 1.0 burnin = 0 periodsize = 1 verbosity = False[sampling] maxiter = 10000000 epsilon = 0.01 maxtime = 6000.0 periodsize = 100 minepsilonrate = 1e-5 verbosity = False[gibbs] epsilon = 0.20189651799465538 minepsilonrate = 0.006737946999085467 burnin = 300 percentdrawnsample = 50 drawnatrandom = True[lbp] maxiter = 100 epsilon = 1e-8 minepsilonrate = 1e-10 periodsize = 1 verbosity = False[loopySampling] virtuallbpsize = 5000[gibbsKL] maxiter = 10000000 epsilon = 1e-10 minepsilonrate = 1e-10 periodsize = 200 verbosity = False burnin = 2000 maxtime = 6000.0 percentdrawnsample = 10 drawnatrandom = True[mcKL] maxiter = 10000000 epsilon = 1e-10 minepsilonrate = 1e-10 periodsize = 200 verbosity = False maxtime = 6000.0[learning] bnlearnerpreferredalgo = MIIC alpha = 0.05 priorweight = 1.0 emnoise = 0.1 tabulistsize = 100 tabunbdecrease = 2[tensor] maxrowsconsole = 6 columnwidthconsole = 9[notebook] arccolor = #4A4A4A nodebgcolor = #404040 nodefgcolor = adaptive graphsize = 5 graphrankdir = TB graphlayout = dot markovrandomfieldview = factorgraph junctiontreegraphsize = 10 junctiontreewithnames = True junctiontreeseparatorbgcolor = palegreen junctiontreeseparatorfgcolor = adaptive junctiontreeseparatorfontsize = 8 junctiontreecliquebgcolor = burlywood junctiontreecliquefgcolor = adaptive junctiontreecliquefontsize = 10 junctiontreemapcliquescale = 0.3 junctiontreemapsepscale = 0.1 junctiontreemapedgelen = 1 junctiontreemapsize = 10 tensor_visible_digits = 4 tensor_with_colors = True tensor_color_0 = #FF7F64 tensor_color_1 = #7FFF64 tensor_with_fraction = False tensor_fraction_limit = 50 tensor_fraction_round_error = 1e-6 tensor_fraction_with_latex = True histogram_horizontal_visible_digits = 2 histogram_vertical_visible_digits = 2 histogram_horizontal_threshold = 8 histogram_line_threshold = 40 histogram_color = darkseagreen histogram_edge_color = darkgreen histogram_use_percent = True histogram_discretized_visualisation = histogram histogram_discretized_scale = 1.0 export_pdf_margin_x = 50 export_pdf_margin_y = 37 histogram_mode = compact histogram_epsilon = 1e-8 tensor_parent_values = merge figure_facecolor = #E0E0E0 flow_background_color = transparent flow_border_color = transparent flow_border_width = 0 graph_format = svg show_inference_time = True evidence_bgcolor = sandybrown evidence_fgcolor = black node_cmap = Pastel1 arc_cmap = BuGn edge_cmap = BuGn graph_inference_size = 8 graphdiff_missing_style = dashed graphdiff_missing_color = red graphdiff_overflow_style = dashed graphdiff_overflow_color = purple graphdiff_reversed_style = solid graphdiff_reversed_color = purple graphdiff_correct_style = solid graphdiff_correct_color = grey[factorgraph] nodebgcolor = coral nodefgcolor = adaptive factorbgcolor = burlywood edgelength = 0.7 graphlayout = neato edge_length_inference = 0.9[dynamicBN] graphsize = 6 timeslicebgcolor = #DDDDDD replicatedslicebgcolor = lightcyan atemporalbgcolor = lightyellow[influenceDiagram] graphsize = 6 chancebgcolor = #808080 chancefgcolor = adaptive utilitybgcolor = #50508A utilityfgcolor = adaptive decisionbgcolor = #9A5050 decisionfgcolor = adaptive chanceshape = ellipse utilityshape = hexagon decisionshape = box decisionarcstyle = tapered, bold, dotted utilityarcstyle = dashed id_inference_size = 6 utility_visible_digits = 2 utility_show_stdev = True utility_show_loss = False[credalnet] nodebgcolor = #404040 nodefgcolor = adaptive histo_max_color = #BBFFAA[causal] showlatentnames = False graphsize = 2.5 nodebgcolor = #404040 nodefgcolor = adaptive latentbgcolor = #A08080 latentfgcolor = adaptive latex_do_prefix = \text{do}( latex_do_suffix = )[ROC] draw_color = #008800 fill_color = #AAEEAA[ctbn] show_latent_names = False graph_size = 2.5 node_bgcolor = #404040 node_fgcolor = white latent_bgcolor = #A08080 latent_fgcolor = black[bnmixture] graph_size = 5 line_size = 1.0 head_size = 0.25 arrow_type = normal arc_cmap = Greens arc_color = #4A4A4A arc_style = solid node_bgcolor = #404040 node_fgcolor = white layout = fdp overlap = 0 bar_capsize = 1.5 bar_height = 0.8 boot_histo_scale = 2.0 histo_scale = 1.0 correct_arc_style = solid correct_arc_color = green incorrect_arc_style = dashed incorrect_arc_color = green left_quantile = 0.2 right_quantile = 0.8try: gum.config.load() # reload pyagrum.iniexcept FileNotFoundError: pass # no pyagrum.ini in the foldergum.config# no customized property[core] maxnumberofthreads = -1 jgumindent = -1 allowmodificationwhensaving = False epsiloncoarse = 1e-2 epsilonstandard = 1e-6 epsilonfine = 1e-10[approximation] epsilon = 0.05 minepsilonrate = 0.01 maxiter = 10000 maxtime = 1.0 burnin = 0 periodsize = 1 verbosity = False[sampling] maxiter = 10000000 epsilon = 0.01 maxtime = 6000.0 periodsize = 100 minepsilonrate = 1e-5 verbosity = False[gibbs] epsilon = 0.20189651799465538 minepsilonrate = 0.006737946999085467 burnin = 300 percentdrawnsample = 50 drawnatrandom = True[lbp] maxiter = 100 epsilon = 1e-8 minepsilonrate = 1e-10 periodsize = 1 verbosity = False[loopySampling] virtuallbpsize = 5000[gibbsKL] maxiter = 10000000 epsilon = 1e-10 minepsilonrate = 1e-10 periodsize = 200 verbosity = False burnin = 2000 maxtime = 6000.0 percentdrawnsample = 10 drawnatrandom = True[mcKL] maxiter = 10000000 epsilon = 1e-10 minepsilonrate = 1e-10 periodsize = 200 verbosity = False maxtime = 6000.0[learning] bnlearnerpreferredalgo = MIIC alpha = 0.05 priorweight = 1.0 emnoise = 0.1 tabulistsize = 100 tabunbdecrease = 2[tensor] maxrowsconsole = 6 columnwidthconsole = 9[notebook] arccolor = #4A4A4A nodebgcolor = #404040 nodefgcolor = adaptive graphsize = 5 graphrankdir = TB graphlayout = dot markovrandomfieldview = factorgraph junctiontreegraphsize = 10 junctiontreewithnames = True junctiontreeseparatorbgcolor = palegreen junctiontreeseparatorfgcolor = adaptive junctiontreeseparatorfontsize = 8 junctiontreecliquebgcolor = burlywood junctiontreecliquefgcolor = adaptive junctiontreecliquefontsize = 10 junctiontreemapcliquescale = 0.3 junctiontreemapsepscale = 0.1 junctiontreemapedgelen = 1 junctiontreemapsize = 10 tensor_visible_digits = 4 tensor_with_colors = True tensor_color_0 = #FF7F64 tensor_color_1 = #7FFF64 tensor_with_fraction = False tensor_fraction_limit = 50 tensor_fraction_round_error = 1e-6 tensor_fraction_with_latex = True histogram_horizontal_visible_digits = 2 histogram_vertical_visible_digits = 2 histogram_horizontal_threshold = 8 histogram_line_threshold = 40 histogram_color = darkseagreen histogram_edge_color = darkgreen histogram_use_percent = True histogram_discretized_visualisation = histogram histogram_discretized_scale = 1.0 export_pdf_margin_x = 50 export_pdf_margin_y = 37 histogram_mode = compact histogram_epsilon = 1e-8 tensor_parent_values = merge figure_facecolor = #E0E0E0 flow_background_color = transparent flow_border_color = transparent flow_border_width = 0 graph_format = svg show_inference_time = True evidence_bgcolor = sandybrown evidence_fgcolor = black node_cmap = Pastel1 arc_cmap = BuGn edge_cmap = BuGn graph_inference_size = 8 graphdiff_missing_style = dashed graphdiff_missing_color = red graphdiff_overflow_style = dashed graphdiff_overflow_color = purple graphdiff_reversed_style = solid graphdiff_reversed_color = purple graphdiff_correct_style = solid graphdiff_correct_color = grey[factorgraph] nodebgcolor = coral nodefgcolor = adaptive factorbgcolor = burlywood edgelength = 0.7 graphlayout = neato edge_length_inference = 0.9[dynamicBN] graphsize = 6 timeslicebgcolor = #DDDDDD replicatedslicebgcolor = lightcyan atemporalbgcolor = lightyellow[influenceDiagram] graphsize = 6 chancebgcolor = #808080 chancefgcolor = adaptive utilitybgcolor = #50508A utilityfgcolor = adaptive decisionbgcolor = #9A5050 decisionfgcolor = adaptive chanceshape = ellipse utilityshape = hexagon decisionshape = box decisionarcstyle = tapered, bold, dotted utilityarcstyle = dashed id_inference_size = 6 utility_visible_digits = 2 utility_show_stdev = True utility_show_loss = False[credalnet] nodebgcolor = #404040 nodefgcolor = adaptive histo_max_color = #BBFFAA[causal] showlatentnames = False graphsize = 2.5 nodebgcolor = #404040 nodefgcolor = adaptive latentbgcolor = #A08080 latentfgcolor = adaptive latex_do_prefix = \text{do}( latex_do_suffix = )[ROC] draw_color = #008800 fill_color = #AAEEAA[ctbn] show_latent_names = False graph_size = 2.5 node_bgcolor = #404040 node_fgcolor = white latent_bgcolor = #A08080 latent_fgcolor = black[bnmixture] graph_size = 5 line_size = 1.0 head_size = 0.25 arrow_type = normal arc_cmap = Greens arc_color = #4A4A4A arc_style = solid node_bgcolor = #404040 node_fgcolor = white layout = fdp overlap = 0 bar_capsize = 1.5 bar_height = 0.8 boot_histo_scale = 2.0 histo_scale = 1.0 correct_arc_style = solid correct_arc_color = green incorrect_arc_style = dashed incorrect_arc_color = green left_quantile = 0.2 right_quantile = 0.8The current state can also be stacked (push) and restored later (pop) : handy to change a property for a short time. pop on an empty stack raises an IndexError.
If pyagrum.ini contains a malformed line, gum.config.load() raises a SyntaxError and nothing is changed (the file is read completely before any property is modified).
gum.config.push()gum.config["notebook", "graphSize"] = 3print("inside :", gum.config["notebook", "graphSize"])gum.config.pop()print("after pop :", gum.config["notebook", "graphSize"])inside : 3after pop : 5Using configuration
Section titled “Using configuration”import pyagrum.lib.notebook as gnb
bn = gum.fastBN("D->C<-A->B[4];A->E")bn.cpt("B")|
|
|
|
| |
|---|---|---|---|---|
| 0.3161 | 0.1589 | 0.0975 | 0.4275 | |
| 0.0305 | 0.6564 | 0.0808 | 0.2323 | |
gum.config["notebook", "tensor_visible_digits"] = 1bn.cpt("B")|
|
|
|
| |
|---|---|---|---|---|
| 0.3 | 0.2 | 0.1 | 0.4 | |
| 0.0 | 0.7 | 0.1 | 0.2 | |
gum.config["notebook", "tensor_color_0"] = "#AA00AA"gum.config["notebook", "tensor_color_1"] = "#00FFAA"bn.cpt("B")|
|
|
|
| |
|---|---|---|---|---|
| 0.3 | 0.2 | 0.1 | 0.4 | |
| 0.0 | 0.7 | 0.1 | 0.2 | |
gum.config["notebook", "tensor_visible_digits"] = 4gnb.flow.add(bn.cpt("B"), "Ugly float")
gum.config["notebook", "tensor_visible_digits"] = 1gnb.flow.add(bn.cpt("B"), "Ugly 1digit-float")
gum.config["notebook", "tensor_with_fraction"] = Truegum.config["notebook", "tensor_fraction_with_latex"] = Falsegum.config["notebook", "tensor_fraction_limit"] = 2000gnb.flow.add(bn.cpt("B"), "Simple fraction")
gum.config["notebook", "tensor_fraction_with_latex"] = Truegnb.flow.add(bn.cpt("B"), "Sophisticated fraction with LaTeX")gnb.flow.display()|
|
|
|
| |
|---|---|---|---|---|
| 0.3161 | 0.1589 | 0.0975 | 0.4275 | |
| 0.0305 | 0.6564 | 0.0808 | 0.2323 | |
|
|
|
|
| |
|---|---|---|---|---|
| 0.3 | 0.2 | 0.1 | 0.4 | |
| 0.0 | 0.7 | 0.1 | 0.2 | |
|
|
|
|
| |
|---|---|---|---|---|
| 616/1949 | 0.2 | 23/236 | 770/1801 | |
| 31/1016 | 617/940 | 34/421 | 329/1416 | |
|
|
|
|
| |
|---|---|---|---|---|
|
| 0.2 |
|
| |
|
|
|
|
| |
gnb.sideBySide(bn, gnb.getInference(bn, evs={"A": 1}, targets={"B"}))gum.config["notebook", "evidence_bgcolor"] = "green"gum.config["notebook", "nodeBgColor"] = "yellow"gum.config["notebook", "nodeFgColor"] = "red"gnb.sideBySide(bn, gnb.getInference(bn, evs={"A": 1}, targets={"B"}))gum.config["notebook", "graphSize"] = 1gnb.sideBySide(bn, gnb.getInference(bn, evs={"A": 1}, targets={"B"}))gum.config["notebook", "graph_inference_size"] = "5!"gnb.showInference(bn, evs={"A": 1}, targets={"B"})Finding a specific property
Section titled “Finding a specific property”## find anything containing arcgum.config.grep("arc")[notebook] arccolor = #4A4A4A arc_cmap = BuGn[influenceDiagram] decisionarcstyle = tapered, bold, dotted utilityarcstyle = dashed[bnmixture] arc_cmap = Greens arc_color = #4A4A4A arc_style = solid correct_arc_style = solid correct_arc_color = green incorrect_arc_style = dashed incorrect_arc_color = green## find anything containing defaultgum.config.grep("default")## if a section contains the search, all its properties are showngum.config.grep("caus")[causal] showlatentnames = False graphsize = 2.5 nodebgcolor = #404040 nodefgcolor = adaptive latentbgcolor = #A08080 latentfgcolor = adaptive latex_do_prefix = \text{do}( latex_do_suffix = )Saving current configuration in pyagrum.ini
Section titled “Saving current configuration in pyagrum.ini”gum.config.reset() # back to defaultsgum.config["notebook", "arcColor"] = "#AAAAAA"gum.config["notebook", "evidence_bgcolor"] = "green"gum.config.save() # store curent changesgum.config.reset() # back to defaultsgum.config.save() # store defaults backFrom gum.config to ConfigParser
Section titled “From gum.config to ConfigParser”from configparser import ConfigParser
c = ConfigParser()
gum.config["notebook", "arcColor"] = "#AAAAAA"gum.config["notebook", "evidence_bgcolor"] = "green"c.read_string(gum.config.__repr__())print(c.sections())['notebook']A function without argument can be registered with gum.config.add_hook. It is called after each change of the configuration (set, reset, pop and load), after the hooks of the aGrUM library itself (for instance the one which applies the number of threads). The hooks are stored by the C++ configuration: they are also called when the configuration is changed from C++.
A hook cannot be removed : it is kept until the end of the session. An exception raised by a hook is propagated to the code which changed the configuration.
def on_change(): print("the configuration has changed")
gum.config.add_hook(on_change)
gum.config["notebook", "arcColor"] = "#BBBBBB" # the hook is calledthe configuration has changedA single change can skip the hooks (no_hook=True), and the hooks can be run by hand :
gum.config.set("notebook", "arcColor", "#CCCCCC", no_hook=True) # nothing is printedgum.config.run_hooks()the configuration has changed
