Configuration for pyAgrum
Configuration for pyAgrum is centralized in an object pyagrum.config, singleton of the (hidden) class PyAgrumConfiguration.
Each key is declared in the defaults with a metadata line ### type :: documentation where the type is int, float, bool, str, an enumeration of the allowed values (svg|png) or a deprecation (deprecated -> section.key). The setter refuses any value that does not respect the declared type and canonicalizes boolean values (any accepted spelling such as yes/on/1 is stored as True or False) as well as enumerated values (stored with their declared casing). config.typed[section, key] gives the value converted according to the declared type, and accessing a deprecated key emits a DeprecationWarning while transparently using its replacement.
See also the tutorial gum.config :the configuration object for pyAgrum.
- class pyagrum.config.PyAgrumConfiguration(*args, **kwargs)
PyAgrumConfiguration is a the pyAgrum configuration singleton. The configuration is build as a classical ConfigParser with read-only structure. Then a value is adressable using a double key:
[section,key].Each key is described in
defaults.iniby a metadata line### type :: documentationwhere type isint,float,bool,str, an enumerationv1|v2|...or a deprecationdeprecated -> section.key. Setting a value that does not respect the declared type raises aValueError. Accessing a deprecated key emits aDeprecationWarningand transparently uses the replacement key. While values are always stored as strings,config.typed[section, key]gives the value converted according to the declared type. Boolean and enumerated values are canonicalized when set: any accepted boolean spelling (yes/on/1/…) is stored asTrueorFalse, an enumerated value is stored with the casing declared indefaults.ini.See this notebook.
Examples
>>> import pyagrum >>> pyagrum.config["dynamicBN", "default_graph_size"] = 10 >>> pyagrum.config["dynamicBN", "default_graph_size"] "10"
- add_hook(fn)
- diff()
print the diff between actual configuration and the defaults. This is what is saved in the file
pyagrum.iniby the method PyAgrumConfiguration.save()
- doc(section, option)
Give the type and the one-line documentation declared for section.option in defaults.
Examples
>>> pyagrum.config.doc("notebook", "tensor_visible_digits") "int :: number of visible digits when displaying a tensor"
- Parameters:
section (str) – The section.
option (str) – The property.
- Returns:
The metadata as
type :: documentation(deprecated -> section.key :: documentationfor a deprecated key).- Return type:
str
- Raises:
SyntaxError – If the section name or the property name does not exist.
- get(section, option)
Give the value associated to section.option. Preferably use
__getitem__and__setitem__.Examples
>>> pyagrum.config["dynamicBN", "default_graph_size"] = 10 >>> pyagrum.config["dynamicBN", "default_graph_size"] "10"
- Parameters:
section (str) – The section.
option (str) – The property.
- Returns:
The value (as string).
- Return type:
str
- getTyped(section, option)
Give the value associated to section.option, converted according to the type declared in defaults:
intandfloatare converted,boolgives a Python bool, enumerations andstrstay strings. Preferably use thetypedaccessor:config.typed[section, option].Examples
>>> pyagrum.config.typed["notebook", "tensor_visible_digits"] 4 >>> pyagrum.config.typed["notebook", "tensor_with_colors"] True
- Parameters:
section (str) – The section.
option (str) – The property.
- Returns:
The value, converted according to the declared type.
- Return type:
int | float | bool | str
- grep(search)
grep in the configuration any section or property matching the argument. If a section matches the argument, the whole section is displayed.
- Parameters:
search (str) – The string to find.
- load()
load pyagrum.ini in the current directory, and change the properties if needed. If pyagrum.ini contains deprecated keys or invalid values, a warning is emitted and pyagrum.ini is rewritten (deprecated keys migrated to their replacement, invalid values removed).
- Raises:
FileNotFoundError – If there is no pyagrum.ini in the current directory.
- pop()
Pop the last config from the stack and set it as the current configuration
- push()
Push the current configuration in the stack
- reset()
back to defaults
- run_hooks()
- save()
Save the diff with the defaults in
pyagrum.iniin the current directory
- schema()
Iterate over the whole configuration schema (in the order of the defaults).
Examples
>>> for section, option, meta, default in pyagrum.config.schema(): ... print(f"{section}.{option} ({meta.kind}) = {default} : {meta.doc}")
- Yields:
Tuple[str, str, ConfigMetadata, Optional[str]] – section, option, the metadata of the key (type, allowed values, documentation, deprecation target) and its default value (None for a deprecated key).
- set(section, option, value, no_hook=False)
set a property in a section. Preferably use
__getitem__and__setitem__.Examples
>>> pyagrum.config["dynamicBN", "default_graph_size"] = 10 >>> pyagrum.config["dynamicBN", "default_graph_size"] "10"
- Parameters:
section (str) – The section name (has to exist in defaults).
option (str) – The option/property name (has to exist in defaults).
value (str) – The value (will be stored as string).
no_hook (bool, optional) – Should this call trigger the hooks?
- Raises:
SyntaxError – If the section name or the property name does not exist.
ValueError – If the value does not respect the type declared for this key in defaults.
Configuration reference
Section [core]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
default maximum number of threads used by aGrUM |
|
|
|
default indentation when exporting a model to JGum (-1 = compact) |
|
|
|
allow to fix syntax errors in a model instead of raising when exporting to external format (BIF, etc.) |
Section [notebook]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
number of visible digits when displaying a tensor |
|
|
|
use a background color gradient for the values in a tensor |
|
|
|
color for the minimal value of a tensor |
|
|
|
color for the maximal value of a tensor |
|
|
|
display the values of a tensor as fractions when possible |
|
|
|
maximal denominator for the fraction representation in a tensor |
|
|
|
maximal rounding error when looking for a fraction representation |
|
|
|
use LaTeX to render the fractions in a tensor |
|
|
|
number of visible digits in horizontal histograms |
|
|
|
number of visible digits in vertical histograms |
|
|
|
maximal domain size for a horizontal histogram (vertical above) |
|
|
|
domain size above which a histogram becomes a line plot |
|
|
|
color of the histogram bars |
|
|
|
color of the edges of the histogram bars |
|
|
|
display probabilities as percentages in histograms |
|
|
|
visualisation of the histogram for a discretized variable |
|
|
|
scale for the histogram of a discretized variable |
|
|
|
horizontal margin (in points) when exporting to pdf |
|
|
|
vertical margin (in points) when exporting to pdf |
|
|
|
mode for displaying histograms |
|
|
|
probabilities below this threshold are truncated in histograms |
|
|
|
how to display the parent values in a tensor |
|
|
|
face color of the matplotlib figures (see matplotlib) |
|
|
|
background color of an item in a flow |
|
|
|
border color of an item in a flow |
|
|
|
border width (in pixels) of an item in a flow |
|
|
|
format used to render graphs in a notebook |
|
|
|
display the inference time below an inference graph |
|
|
|
default color of the arcs |
|
|
|
default background color of the nodes |
|
|
|
default font color of the nodes |
|
|
|
background color of a node with evidence |
|
|
|
font color of a node with evidence |
|
|
|
matplotlib color map for the nodes |
|
|
|
matplotlib color map for the arcs |
|
|
|
matplotlib color map for the edges |
|
|
|
default size (in inches) of a graph (graphviz size, e.g. “5” or “12!” for exact size) |
|
|
|
default size (in inches) of a graph during inference (graphviz size, e.g. “8” or “12!”) |
|
|
|
direction of the graph layout (top-bottom or left-right) |
|
|
|
graphviz layout engine |
|
|
|
default view for a Markov random field |
|
|
|
size (in inches) of a junction tree (graphviz size, e.g. “10” or “12!”) |
|
|
|
show the variable names in the cliques of a junction tree |
|
|
|
background color of the separators of a junction tree |
|
|
|
font color of the separators of a junction tree |
|
|
|
font size of the separators of a junction tree |
|
|
|
background color of the cliques of a junction tree |
|
|
|
font color of the cliques of a junction tree |
|
|
|
font size of the cliques of a junction tree |
|
|
|
scale of the cliques in a junction tree map |
|
|
|
scale of the separators in a junction tree map |
|
|
|
length of the edges in a junction tree map |
|
|
|
size (in inches) of a junction tree map (graphviz size, e.g. “10” or “12!”) |
|
|
|
style of an arc missing in the compared graph |
|
|
|
color of an arc missing in the compared graph |
|
|
|
style of an arc absent from the reference graph |
|
|
|
color of an arc absent from the reference graph |
|
|
|
style of an arc reversed in the compared graph |
|
|
|
color of an arc reversed in the compared graph |
|
|
|
style of an arc identical in both graphs |
|
|
|
color of an arc identical in both graphs |
Section [factorgraph]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
default background color of the variable nodes |
|
|
|
default font color of the variable nodes |
|
|
|
default background color of the factor nodes |
|
|
|
length of the edges in a factor graph |
|
|
|
length of the edges in a factor graph during inference |
|
|
|
graphviz layout engine |
Section [dynamicBN]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
default size (in inches) of a dynamic BN (graphviz size, e.g. “6” or “12!”) |
Section [influenceDiagram]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
default size (in inches) of an influence diagram (graphviz size, e.g. “6” or “12!”) |
|
|
|
default background color of the chance nodes |
|
|
|
default font color of the chance nodes |
|
|
|
default background color of the utility nodes |
|
|
|
default font color of the utility nodes |
|
|
|
default background color of the decision nodes |
|
|
|
default font color of the decision nodes |
|
|
|
graphviz shape of the chance nodes |
|
|
|
graphviz shape of the utility nodes |
|
|
|
graphviz shape of the decision nodes |
|
|
|
graphviz style of the arcs pointing to a decision node |
|
|
|
graphviz style of the arcs pointing to a utility node |
|
|
|
default size (in inches) of an influence diagram (graphviz size, e.g. “6” or “12!”) |
|
|
|
default size (in inches) of an influence diagram during inference (graphviz size, e.g. “6” or “12!”) |
|
|
|
number of visible digits when displaying a utility |
|
|
|
show the standard deviation together with a utility |
|
|
|
show the loss (negative utility) instead of the utility |
Section [credalnet]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
default background color of the nodes |
|
|
|
default font color of the nodes |
|
|
|
color for the maximal value in a credal set histogram |
Section [causal]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
show the names of the latent variables |
|
|
|
LaTeX command inserted before an intervention (do) in a formula |
|
|
|
LaTeX command inserted after an intervention (do) in a formula |
|
|
|
default size (in inches) of a causal model (graphviz size, e.g. “2.5” or “12!”) |
|
|
|
default background color of the nodes |
|
|
|
default font color of the nodes |
|
|
|
default background color of the latent nodes |
|
|
|
default font color of the latent nodes |
Section [ROC]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
color of the ROC/PR curve |
|
|
|
color of the area under the ROC/PR curve |
Section [ctbn]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
show the names of the latent variables |
|
|
|
default size (in inches) of a CTBN (graphviz size, e.g. “2.5” or “12!”) |
|
|
|
default background color of the nodes |
|
|
|
default font color of the nodes |
|
|
|
default background color of the latent nodes |
|
|
|
default font color of the latent nodes |
Section [bnmixture]
Key |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
default size (in inches) of a BN mixture (graphviz size, e.g. “5” or “12!”) |
|
|
|
default width of the arcs |
|
|
|
default size of the arrow heads |
|
|
|
graphviz type of the arrow heads |
|
|
|
matplotlib color map for the arcs |
|
|
|
default color of the arcs |
|
|
|
graphviz style of the arcs |
|
|
|
default background color of the nodes |
|
|
|
default font color of the nodes |
|
|
|
graphviz layout engine |
|
|
|
overlap scaling for the graphviz layout |
|
|
|
size of the caps on the error bars |
|
|
|
height of the bars in the bar plots |
|
|
|
scale for the bootstrap histograms |
|
|
|
scale for the histograms |
|
|
|
graphviz style of an arc present in the reference BN |
|
|
|
color of an arc present in the reference BN |
|
|
|
graphviz style of an arc absent from the reference BN |
|
|
|
color of an arc absent from the reference BN |
|
|
|
lower quantile used when displaying the distribution of parameters |
|
|
|
upper quantile used when displaying the distribution of parameters |
Deprecated keys
(none)