gum.config
:the configuration object for pyAgrum¶import pyAgrum as gum
print("="*35)
print(gum.config)
print("="*35)
=================================== [core] default_maxnumberofthreads = 24 [notebook] potential_visible_digits = 4 potential_with_colors = True potential_color_0 = #FF7F64 potential_color_1 = #7FFF64 potential_with_fraction = False potential_fraction_limit = 50 potential_fraction_round_error = 1e-6 potential_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_use_percent = True histogram_mode = compact potential_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 default_arc_color = #4A4A4A default_node_bgcolor = #404040 default_node_fgcolor = white evidence_bgcolor = sandybrown evidence_fgcolor = black default_node_cmap = Pastel1 default_arc_cmap = BuGn default_edge_cmap = BuGn default_graph_size = 5 default_graph_inference_size = 8 default_markovnetwork_view = factorgraph junctiontree_graph_size = 10 junctiontree_with_names = True junctiontree_separator_bgcolor = palegreen junctiontree_separator_fgcolor = black junctiontree_separator_fontsize = 8 junctiontree_clique_bgcolor = burlywood junctiontree_clique_fgcolor = black junctiontree_clique_fontsize = 10 junctiontree_map_cliquescale = 0.3 junctiontree_map_sepscale = 0.1 junctiontree_map_edgelen = 1 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 [BN] allow_modification_when_saving = False [factorgraph] default_node_bgcolor = coral default_node_fgcolor = black default_factor_bgcolor = burlywood edge_length = 0.7 edge_length_inference = 0.9 [dynamicBN] default_graph_size = 6 [influenceDiagram] default_graph_size = 6 default_chance_bgcolor = #808080 default_chance_fgcolor = white default_utility_bgcolor = #50508A default_utility_fgcolor = white default_decision_bgcolor = #9A5050 default_decision_fgcolor = white chance_shape = ellipse utility_shape = hexagon decision_shape = box decision_arc_style = tapered, bold, dotted utility_arc_style = dashed default_id_size = 6 default_id_inference_size = 6 utility_visible_digits = 2 utility_show_stdev = True utility_show_loss = False [credalnet] default_node_bgcolor = #404040 default_node_fgcolor = white histo_max_color = #BBFFAA [causal] show_latent_names = False latex_do_prefix = \hookrightarrow\mkern-6.5mu latex_do_suffix = default_graph_size = 2.5 default_node_bgcolor = #404040 default_node_fgcolor = white default_latent_bgcolor = #A08080 default_latent_fgcolor = black [ROC] draw_color = #008800 fill_color = #AAEEAA ===================================
gum.config
as singleton¶As far as it can be done with Python, gum.config
is a singleton
cfg2=gum.PyAgrumConfiguration()
print(id(cfg2))
print(id(gum.config))
139849244517920 139849244517920
pyagrum.ini
¶The configuration is a mix between the defaults (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.
section
and key
are case insensitive.
config
constantly keeps track of the differences between defaults and actual values :¶gum.config['dynamicBN','default_graph_size']=10
print("Configuration only for the current session")
print('-'*40)
gum.config.diff()
Configuration only for the current session ---------------------------------------- [dynamicBN] default_graph_size = 10
# if there is a local modification, __repr__ shows only the diff other wise it show all properties
gum.config
[dynamicBN] default_graph_size = 10
# __str__ shows all the properties
print(gum.config)
[core] default_maxnumberofthreads = 24 [notebook] potential_visible_digits = 4 potential_with_colors = True potential_color_0 = #FF7F64 potential_color_1 = #7FFF64 potential_with_fraction = False potential_fraction_limit = 50 potential_fraction_round_error = 1e-6 potential_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_use_percent = True histogram_mode = compact potential_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 default_arc_color = #4A4A4A default_node_bgcolor = #404040 default_node_fgcolor = white evidence_bgcolor = sandybrown evidence_fgcolor = black default_node_cmap = Pastel1 default_arc_cmap = BuGn default_edge_cmap = BuGn default_graph_size = 5 default_graph_inference_size = 8 default_markovnetwork_view = factorgraph junctiontree_graph_size = 10 junctiontree_with_names = True junctiontree_separator_bgcolor = palegreen junctiontree_separator_fgcolor = black junctiontree_separator_fontsize = 8 junctiontree_clique_bgcolor = burlywood junctiontree_clique_fgcolor = black junctiontree_clique_fontsize = 10 junctiontree_map_cliquescale = 0.3 junctiontree_map_sepscale = 0.1 junctiontree_map_edgelen = 1 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 [BN] allow_modification_when_saving = False [factorgraph] default_node_bgcolor = coral default_node_fgcolor = black default_factor_bgcolor = burlywood edge_length = 0.7 edge_length_inference = 0.9 [dynamicBN] default_graph_size = 10 [influenceDiagram] default_graph_size = 6 default_chance_bgcolor = #808080 default_chance_fgcolor = white default_utility_bgcolor = #50508A default_utility_fgcolor = white default_decision_bgcolor = #9A5050 default_decision_fgcolor = white chance_shape = ellipse utility_shape = hexagon decision_shape = box decision_arc_style = tapered, bold, dotted utility_arc_style = dashed default_id_size = 6 default_id_inference_size = 6 utility_visible_digits = 2 utility_show_stdev = True utility_show_loss = False [credalnet] default_node_bgcolor = #404040 default_node_fgcolor = white histo_max_color = #BBFFAA [causal] show_latent_names = False latex_do_prefix = \hookrightarrow\mkern-6.5mu latex_do_suffix = default_graph_size = 2.5 default_node_bgcolor = #404040 default_node_fgcolor = white default_latent_bgcolor = #A08080 default_latent_fgcolor = black [ROC] draw_color = #008800 fill_color = #AAEEAA
print(gum.config["notebook","evidence_bgcolor"])
print(gum.config.get("notebook","evidence_bgcolor"))
sandybrown sandybrown
gum.config["notebook","evidence_bgcolor"]="papayawhip"
gum.config["causal","default_graph_size"]=1.9
gum.config # once again, only the diff with defaults
[notebook] evidence_bgcolor = papayawhip [dynamicBN] default_graph_size = 10 [causal] default_graph_size = 1.9
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"]=1
except SyntaxError as e:
print("Syntax error : {}".format(e.msg))
Syntax error : You can not add section 'AAA' in pyAgrum configuration
try:
gum.config["causal","OOO"]=1
except SyntaxError as e:
print("Syntax error : {}".format(e.msg))
Syntax error : You can not add option 'causal,OOO' in pyAgrum configuration
All the properties are stored as string !
gum.config["notebook","default_graph_size"]
'5'
gum.config["notebook","default_graph_size"]=10
gum.config["notebook","default_graph_size"]
'10'
gum.config['dynamicBN','default_graph_size']
'10'
gum.config.asInt['dynamicBN','default_graph_size']
10
print(type(gum.config['dynamicBN','default_graph_size']))
print(type(gum.config.asInt['dynamicBN','default_graph_size']))
<class 'str'> <class 'int'>
if gum.config["causal","show_latent_names"]=="False":
print("not very convenient test")
if not gum.config.asBool["causal","show_latent_names"]:
print("better test")
not very convenient test better test
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 defaults
gum.config # no diff => shows all the properties
# no customized property [core] default_maxnumberofthreads = 24 [notebook] potential_visible_digits = 4 potential_with_colors = True potential_color_0 = #FF7F64 potential_color_1 = #7FFF64 potential_with_fraction = False potential_fraction_limit = 50 potential_fraction_round_error = 1e-6 potential_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_use_percent = True histogram_mode = compact potential_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 default_arc_color = #4A4A4A default_node_bgcolor = #404040 default_node_fgcolor = white evidence_bgcolor = sandybrown evidence_fgcolor = black default_node_cmap = Pastel1 default_arc_cmap = BuGn default_edge_cmap = BuGn default_graph_size = 5 default_graph_inference_size = 8 default_markovnetwork_view = factorgraph junctiontree_graph_size = 10 junctiontree_with_names = True junctiontree_separator_bgcolor = palegreen junctiontree_separator_fgcolor = black junctiontree_separator_fontsize = 8 junctiontree_clique_bgcolor = burlywood junctiontree_clique_fgcolor = black junctiontree_clique_fontsize = 10 junctiontree_map_cliquescale = 0.3 junctiontree_map_sepscale = 0.1 junctiontree_map_edgelen = 1 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 [BN] allow_modification_when_saving = False [factorgraph] default_node_bgcolor = coral default_node_fgcolor = black default_factor_bgcolor = burlywood edge_length = 0.7 edge_length_inference = 0.9 [dynamicBN] default_graph_size = 6 [influenceDiagram] default_graph_size = 6 default_chance_bgcolor = #808080 default_chance_fgcolor = white default_utility_bgcolor = #50508A default_utility_fgcolor = white default_decision_bgcolor = #9A5050 default_decision_fgcolor = white chance_shape = ellipse utility_shape = hexagon decision_shape = box decision_arc_style = tapered, bold, dotted utility_arc_style = dashed default_id_size = 6 default_id_inference_size = 6 utility_visible_digits = 2 utility_show_stdev = True utility_show_loss = False [credalnet] default_node_bgcolor = #404040 default_node_fgcolor = white histo_max_color = #BBFFAA [causal] show_latent_names = False latex_do_prefix = \hookrightarrow\mkern-6.5mu latex_do_suffix = default_graph_size = 2.5 default_node_bgcolor = #404040 default_node_fgcolor = white default_latent_bgcolor = #A08080 default_latent_fgcolor = black [ROC] draw_color = #008800 fill_color = #AAEEAA
try:
gum.config.load() # reload pyagrum.ini
except FileNotFoundError:
pass # no pyagrum.ini in the folder
gum.config
# no customized property [core] default_maxnumberofthreads = 24 [notebook] potential_visible_digits = 4 potential_with_colors = True potential_color_0 = #FF7F64 potential_color_1 = #7FFF64 potential_with_fraction = False potential_fraction_limit = 50 potential_fraction_round_error = 1e-6 potential_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_use_percent = True histogram_mode = compact potential_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 default_arc_color = #4A4A4A default_node_bgcolor = #404040 default_node_fgcolor = white evidence_bgcolor = sandybrown evidence_fgcolor = black default_node_cmap = Pastel1 default_arc_cmap = BuGn default_edge_cmap = BuGn default_graph_size = 5 default_graph_inference_size = 8 default_markovnetwork_view = factorgraph junctiontree_graph_size = 10 junctiontree_with_names = True junctiontree_separator_bgcolor = palegreen junctiontree_separator_fgcolor = black junctiontree_separator_fontsize = 8 junctiontree_clique_bgcolor = burlywood junctiontree_clique_fgcolor = black junctiontree_clique_fontsize = 10 junctiontree_map_cliquescale = 0.3 junctiontree_map_sepscale = 0.1 junctiontree_map_edgelen = 1 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 [BN] allow_modification_when_saving = False [factorgraph] default_node_bgcolor = coral default_node_fgcolor = black default_factor_bgcolor = burlywood edge_length = 0.7 edge_length_inference = 0.9 [dynamicBN] default_graph_size = 6 [influenceDiagram] default_graph_size = 6 default_chance_bgcolor = #808080 default_chance_fgcolor = white default_utility_bgcolor = #50508A default_utility_fgcolor = white default_decision_bgcolor = #9A5050 default_decision_fgcolor = white chance_shape = ellipse utility_shape = hexagon decision_shape = box decision_arc_style = tapered, bold, dotted utility_arc_style = dashed default_id_size = 6 default_id_inference_size = 6 utility_visible_digits = 2 utility_show_stdev = True utility_show_loss = False [credalnet] default_node_bgcolor = #404040 default_node_fgcolor = white histo_max_color = #BBFFAA [causal] show_latent_names = False latex_do_prefix = \hookrightarrow\mkern-6.5mu latex_do_suffix = default_graph_size = 2.5 default_node_bgcolor = #404040 default_node_fgcolor = white default_latent_bgcolor = #A08080 default_latent_fgcolor = black [ROC] draw_color = #008800 fill_color = #AAEEAA
import pyAgrum.lib.notebook as gnb
bn=gum.fastBN("D->C<-A->B[4];A->E")
bn.cpt("B")
|
|
|
| |
---|---|---|---|---|
0.0666 | 0.2950 | 0.3610 | 0.2774 | |
0.3515 | 0.2417 | 0.3603 | 0.0466 |
gum.config["notebook","potential_visible_digits"]=1
bn.cpt("B")
|
|
|
| |
---|---|---|---|---|
0.1 | 0.3 | 0.4 | 0.3 | |
0.4 | 0.2 | 0.4 | 0.0 |
gum.config['notebook', 'potential_color_0']="#AA00AA"
gum.config['notebook', 'potential_color_1']="#00FFAA"
bn.cpt("B")
|
|
|
| |
---|---|---|---|---|
0.1 | 0.3 | 0.4 | 0.3 | |
0.4 | 0.2 | 0.4 | 0.0 |
gum.config["notebook","potential_visible_digits"]=4
gnb.flow.add(bn.cpt("B"),"Ugly float")
gum.config["notebook","potential_visible_digits"]=1
gnb.flow.add(bn.cpt("B"),"Ugly 1digit-float")
gum.config['notebook', 'potential_with_fraction']=True
gum.config['notebook', 'potential_fraction_with_latex']=False
gum.config['notebook', 'potential_fraction_limit']=2000
gnb.flow.add(bn.cpt("B"),"Simple fraction")
gum.config['notebook', 'potential_fraction_with_latex']=True
gnb.flow.add(bn.cpt("B"),"Sophisticated fraction with LaTeX")
gnb.flow.display()
|
|
|
| |
---|---|---|---|---|
0.0666 | 0.2950 | 0.3610 | 0.2774 | |
0.3515 | 0.2417 | 0.3603 | 0.0466 |
|
|
|
| |
---|---|---|---|---|
0.1 | 0.3 | 0.4 | 0.3 | |
0.4 | 0.2 | 0.4 | 0.0 |
|
|
|
| |
---|---|---|---|---|
87/1307 | 375/1271 | 448/1241 | 481/1734 | |
433/1232 | 399/1651 | 682/1893 | 80/1717 |
|
|
|
| |
---|---|---|---|---|
$$\frac{87}{1307}$$ | $$\frac{375}{1271}$$ | $$\frac{448}{1241}$$ | $$\frac{481}{1734}$$ | |
$$\frac{433}{1232}$$ | $$\frac{399}{1651}$$ | $$\frac{682}{1893}$$ | $$\frac{80}{1717}$$ |
gnb.sideBySide(bn,gnb.getInference(bn,evs={"A":1},targets={"B"}))
gum.config["notebook","evidence_bgcolor"]="green"
gum.config["notebook","default_node_bgcolor"]="yellow"
gum.config["notebook","default_node_fgcolor"]="red"
gnb.sideBySide(bn,gnb.getInference(bn,evs={"A":1},targets={"B"}))
gum.config["notebook","default_graph_size"]=1
gnb.sideBySide(bn,gnb.getInference(bn,evs={"A":1},targets={"B"}))
gum.config["notebook","default_graph_inference_size"]="1"
gnb.sideBySide(bn,gnb.getInference(bn,evs={"A":1},targets={"B"}))
#find anything containing arc
gum.config.grep("arc")
[notebook] default_arc_color = #4A4A4A default_arc_cmap = BuGn [influenceDiagram] decision_arc_style = tapered, bold, dotted utility_arc_style = dashed
#find anything containing default
gum.config.grep("default")
[core] default_maxnumberofthreads = 24 [notebook] default_arc_color = #4A4A4A default_node_bgcolor = yellow default_node_fgcolor = red default_node_cmap = Pastel1 default_arc_cmap = BuGn default_edge_cmap = BuGn default_graph_size = 1 default_graph_inference_size = 1 default_markovnetwork_view = factorgraph [factorgraph] default_node_bgcolor = coral default_node_fgcolor = black default_factor_bgcolor = burlywood [dynamicBN] default_graph_size = 6 [influenceDiagram] default_graph_size = 6 default_chance_bgcolor = #808080 default_chance_fgcolor = white default_utility_bgcolor = #50508A default_utility_fgcolor = white default_decision_bgcolor = #9A5050 default_decision_fgcolor = white default_id_size = 6 default_id_inference_size = 6 [credalnet] default_node_bgcolor = #404040 default_node_fgcolor = white [causal] default_graph_size = 2.5 default_node_bgcolor = #404040 default_node_fgcolor = white default_latent_bgcolor = #A08080 default_latent_fgcolor = black
# if a section contains the search, all its properties are shown
gum.config.grep("caus")
[causal] show_latent_names = False latex_do_prefix = \hookrightarrow\mkern-6.5mu latex_do_suffix = default_graph_size = 2.5 default_node_bgcolor = #404040 default_node_fgcolor = white default_latent_bgcolor = #A08080 default_latent_fgcolor = black
pyagrum.ini
¶gum.config.reset() # back to defaults
gum.config['notebook','default_arc_color'] = "#AAAAAA"
gum.config['notebook','evidence_bgcolor'] = "green"
gum.config.save() # store curent changes
gum.config.reset() # back to defaults
gum.config.save() # store defaults back
from configparser import ConfigParser
c=ConfigParser()
gum.config['notebook','default_arc_color'] = "#AAAAAA"
gum.config['notebook','evidence_bgcolor'] = "green"
c.read_string(gum.config.__repr__())
print(c.sections())
['notebook']