pyAgrum-nightly 2.3.0.9.dev202512061764412981__cp310-abi3-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. pyagrum/__init__.py +165 -0
  2. pyagrum/_pyagrum.so +0 -0
  3. pyagrum/bnmixture/BNMInference.py +268 -0
  4. pyagrum/bnmixture/BNMLearning.py +376 -0
  5. pyagrum/bnmixture/BNMixture.py +464 -0
  6. pyagrum/bnmixture/__init__.py +60 -0
  7. pyagrum/bnmixture/notebook.py +1058 -0
  8. pyagrum/causal/_CausalFormula.py +280 -0
  9. pyagrum/causal/_CausalModel.py +436 -0
  10. pyagrum/causal/__init__.py +81 -0
  11. pyagrum/causal/_causalImpact.py +356 -0
  12. pyagrum/causal/_dSeparation.py +598 -0
  13. pyagrum/causal/_doAST.py +761 -0
  14. pyagrum/causal/_doCalculus.py +361 -0
  15. pyagrum/causal/_doorCriteria.py +374 -0
  16. pyagrum/causal/_exceptions.py +95 -0
  17. pyagrum/causal/_types.py +61 -0
  18. pyagrum/causal/causalEffectEstimation/_CausalEffectEstimation.py +1175 -0
  19. pyagrum/causal/causalEffectEstimation/_IVEstimators.py +718 -0
  20. pyagrum/causal/causalEffectEstimation/_RCTEstimators.py +132 -0
  21. pyagrum/causal/causalEffectEstimation/__init__.py +46 -0
  22. pyagrum/causal/causalEffectEstimation/_backdoorEstimators.py +774 -0
  23. pyagrum/causal/causalEffectEstimation/_causalBNEstimator.py +324 -0
  24. pyagrum/causal/causalEffectEstimation/_frontdoorEstimators.py +396 -0
  25. pyagrum/causal/causalEffectEstimation/_learners.py +118 -0
  26. pyagrum/causal/causalEffectEstimation/_utils.py +466 -0
  27. pyagrum/causal/notebook.py +171 -0
  28. pyagrum/clg/CLG.py +658 -0
  29. pyagrum/clg/GaussianVariable.py +111 -0
  30. pyagrum/clg/SEM.py +312 -0
  31. pyagrum/clg/__init__.py +63 -0
  32. pyagrum/clg/canonicalForm.py +408 -0
  33. pyagrum/clg/constants.py +54 -0
  34. pyagrum/clg/forwardSampling.py +202 -0
  35. pyagrum/clg/learning.py +776 -0
  36. pyagrum/clg/notebook.py +480 -0
  37. pyagrum/clg/variableElimination.py +271 -0
  38. pyagrum/common.py +60 -0
  39. pyagrum/config.py +319 -0
  40. pyagrum/ctbn/CIM.py +513 -0
  41. pyagrum/ctbn/CTBN.py +573 -0
  42. pyagrum/ctbn/CTBNGenerator.py +216 -0
  43. pyagrum/ctbn/CTBNInference.py +459 -0
  44. pyagrum/ctbn/CTBNLearner.py +161 -0
  45. pyagrum/ctbn/SamplesStats.py +671 -0
  46. pyagrum/ctbn/StatsIndepTest.py +355 -0
  47. pyagrum/ctbn/__init__.py +79 -0
  48. pyagrum/ctbn/constants.py +54 -0
  49. pyagrum/ctbn/notebook.py +264 -0
  50. pyagrum/defaults.ini +199 -0
  51. pyagrum/deprecated.py +95 -0
  52. pyagrum/explain/_ComputationCausal.py +75 -0
  53. pyagrum/explain/_ComputationConditional.py +48 -0
  54. pyagrum/explain/_ComputationMarginal.py +48 -0
  55. pyagrum/explain/_CustomShapleyCache.py +110 -0
  56. pyagrum/explain/_Explainer.py +176 -0
  57. pyagrum/explain/_Explanation.py +70 -0
  58. pyagrum/explain/_FIFOCache.py +54 -0
  59. pyagrum/explain/_ShallCausalValues.py +204 -0
  60. pyagrum/explain/_ShallConditionalValues.py +155 -0
  61. pyagrum/explain/_ShallMarginalValues.py +155 -0
  62. pyagrum/explain/_ShallValues.py +296 -0
  63. pyagrum/explain/_ShapCausalValues.py +208 -0
  64. pyagrum/explain/_ShapConditionalValues.py +126 -0
  65. pyagrum/explain/_ShapMarginalValues.py +191 -0
  66. pyagrum/explain/_ShapleyValues.py +298 -0
  67. pyagrum/explain/__init__.py +81 -0
  68. pyagrum/explain/_explGeneralizedMarkovBlanket.py +152 -0
  69. pyagrum/explain/_explIndependenceListForPairs.py +146 -0
  70. pyagrum/explain/_explInformationGraph.py +264 -0
  71. pyagrum/explain/notebook/__init__.py +54 -0
  72. pyagrum/explain/notebook/_bar.py +142 -0
  73. pyagrum/explain/notebook/_beeswarm.py +174 -0
  74. pyagrum/explain/notebook/_showShapValues.py +97 -0
  75. pyagrum/explain/notebook/_waterfall.py +220 -0
  76. pyagrum/explain/shapley.py +225 -0
  77. pyagrum/lib/__init__.py +46 -0
  78. pyagrum/lib/_colors.py +390 -0
  79. pyagrum/lib/bn2graph.py +299 -0
  80. pyagrum/lib/bn2roc.py +1026 -0
  81. pyagrum/lib/bn2scores.py +217 -0
  82. pyagrum/lib/bn_vs_bn.py +605 -0
  83. pyagrum/lib/cn2graph.py +305 -0
  84. pyagrum/lib/discreteTypeProcessor.py +1102 -0
  85. pyagrum/lib/discretizer.py +58 -0
  86. pyagrum/lib/dynamicBN.py +390 -0
  87. pyagrum/lib/explain.py +57 -0
  88. pyagrum/lib/export.py +84 -0
  89. pyagrum/lib/id2graph.py +258 -0
  90. pyagrum/lib/image.py +387 -0
  91. pyagrum/lib/ipython.py +307 -0
  92. pyagrum/lib/mrf2graph.py +471 -0
  93. pyagrum/lib/notebook.py +1821 -0
  94. pyagrum/lib/proba_histogram.py +552 -0
  95. pyagrum/lib/utils.py +138 -0
  96. pyagrum/pyagrum.py +31495 -0
  97. pyagrum/skbn/_MBCalcul.py +242 -0
  98. pyagrum/skbn/__init__.py +49 -0
  99. pyagrum/skbn/_learningMethods.py +282 -0
  100. pyagrum/skbn/_utils.py +297 -0
  101. pyagrum/skbn/bnclassifier.py +1014 -0
  102. pyagrum_nightly-2.3.0.9.dev202512061764412981.dist-info/LICENSE.md +12 -0
  103. pyagrum_nightly-2.3.0.9.dev202512061764412981.dist-info/LICENSES/LGPL-3.0-or-later.txt +304 -0
  104. pyagrum_nightly-2.3.0.9.dev202512061764412981.dist-info/LICENSES/MIT.txt +18 -0
  105. pyagrum_nightly-2.3.0.9.dev202512061764412981.dist-info/METADATA +145 -0
  106. pyagrum_nightly-2.3.0.9.dev202512061764412981.dist-info/RECORD +107 -0
  107. pyagrum_nightly-2.3.0.9.dev202512061764412981.dist-info/WHEEL +4 -0
@@ -0,0 +1,264 @@
1
+ ############################################################################
2
+ # This file is part of the aGrUM/pyAgrum library. #
3
+ # #
4
+ # Copyright (c) 2005-2025 by #
5
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
6
+ # - Christophe GONZALES(_at_AMU) #
7
+ # #
8
+ # The aGrUM/pyAgrum library is free software; you can redistribute it #
9
+ # and/or modify it under the terms of either : #
10
+ # #
11
+ # - the GNU Lesser General Public License as published by #
12
+ # the Free Software Foundation, either version 3 of the License, #
13
+ # or (at your option) any later version, #
14
+ # - the MIT license (MIT), #
15
+ # - or both in dual license, as here. #
16
+ # #
17
+ # (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) #
18
+ # #
19
+ # This aGrUM/pyAgrum library is distributed in the hope that it will be #
20
+ # useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #
21
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS #
22
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
23
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
24
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #
25
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR #
26
+ # OTHER DEALINGS IN THE SOFTWARE. #
27
+ # #
28
+ # See LICENCES for more details. #
29
+ # #
30
+ # SPDX-FileCopyrightText: Copyright 2005-2025 #
31
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
32
+ # - Christophe GONZALES(_at_AMU) #
33
+ # SPDX-License-Identifier: LGPL-3.0-or-later OR MIT #
34
+ # #
35
+ # Contact : info_at_agrum_dot_org #
36
+ # homepage : http://agrum.gitlab.io #
37
+ # gitlab : https://gitlab.com/agrumery/agrum #
38
+ # #
39
+ ############################################################################
40
+
41
+ """
42
+ This file defines some helpers for handling CTBNs in notebooks
43
+ """
44
+
45
+ from tempfile import mkdtemp
46
+ import matplotlib.pyplot as plt
47
+ import IPython
48
+ import time
49
+ import hashlib
50
+
51
+ import pyagrum as gum
52
+ from pyagrum.lib import proba_histogram
53
+ import pyagrum.lib._colors as gumcols
54
+ import pyagrum.lib.notebook as gnb
55
+ import pydot as dot
56
+
57
+ from pyagrum.ctbn import CTBN
58
+ from pyagrum.ctbn import ForwardSamplingInference
59
+
60
+
61
+ def getCtbnGraph(ctbn: CTBN, size=None):
62
+ """
63
+ Returns a HTML representing the CTBN.
64
+
65
+ Parameters
66
+ ----------
67
+ ctbn : CTBN
68
+ The CTBN.
69
+ size : int|str
70
+ The size of the rendered graph.
71
+
72
+ Returns
73
+ -------
74
+ pydot.Dot
75
+ The dot representation.
76
+ """
77
+ if size is None:
78
+ size = gum.config["ctbn", "default_graph_size"]
79
+ return gnb.getDot(ctbn.toDot(), size)
80
+
81
+
82
+ def showCtbnGraph(ctbn: CTBN, size=None):
83
+ """
84
+ Show a pydot svg representation of the CTBN.
85
+
86
+ Parameters
87
+ ----------
88
+ ctbn : CTBN
89
+ The CTBN.
90
+ size : int|str
91
+ The size of the rendered graph.
92
+ """
93
+
94
+ if size is None:
95
+ size = gum.config["ctbn", "default_graph_size"]
96
+ gnb.showDot(ctbn.toDot(), size)
97
+
98
+
99
+ def getCIMs(ctbn: CTBN, size=None):
100
+ """
101
+ Returns a HTML representing the CIMS of the CTBN.
102
+
103
+ Parameters
104
+ ----------
105
+ ctbn : CTBN
106
+ The CTBN.
107
+ size : int|str
108
+ """
109
+ gnb.flow.clear()
110
+ for var in ctbn.names():
111
+ gnb.flow.add(ctbn.CIM(var)._pot, caption=f"CIM({var})")
112
+ return gnb.flow.html()
113
+
114
+
115
+ def showCIMs(ctbn: CTBN, size=None):
116
+ """
117
+ Show a pydot svg representation of the CIMs of the CTBN.
118
+
119
+ Parameters
120
+ ----------
121
+ ctbn : CTBN
122
+ The CTBN.
123
+ size : int|str
124
+ """
125
+ html = getCIMs(ctbn, size=size)
126
+ IPython.display.display(html)
127
+
128
+
129
+ def CTBNinference2dot(
130
+ ctbn, engine, size=None, targets=None, nodeColor=None, arcWidth=None, arcColor=None, cmapNode=None, cmapArc=None
131
+ ):
132
+ """
133
+ create a pydot representation of an inference in a CTBN
134
+
135
+ Parameters
136
+ ----------
137
+ ctbn : CTBN
138
+ the Bayesian network
139
+ size: str
140
+ size of the rendered graph
141
+ engine: pyagrum.Inference
142
+ inference algorithm used. If None, LazyPropagation will be used
143
+ targets: set
144
+ set of targets. If targets={} then each node is a target
145
+ nodeColor: dict
146
+ a nodeMap of values to be shown as color nodes (with special color for 0 and 1)
147
+ arcWidth: dict
148
+ a arcMap of values to be shown as bold arcs
149
+ arcColor: dict
150
+ a arcMap of values (between 0 and 1) to be shown as color of arcs
151
+ cmapNode: ColorMap
152
+ color map to show the vals of Nodes
153
+ cmapArc: ColorMap
154
+ color map to show the vals of Arcs
155
+
156
+ Returns
157
+ -------
158
+ the desired representation of the inference
159
+ """
160
+ if targets is None:
161
+ targets = {}
162
+ if cmapNode is None:
163
+ cmapNode = plt.get_cmap(gum.config["notebook", "default_node_cmap"])
164
+
165
+ if cmapArc is None:
166
+ cmapArc = plt.get_cmap(gum.config["notebook", "default_arc_cmap"])
167
+
168
+ # defaukt
169
+ maxarcs = 100
170
+ minarcs = 0
171
+
172
+ if arcWidth is not None:
173
+ minarcs = min(arcWidth.values())
174
+ maxarcs = max(arcWidth.values())
175
+
176
+ startTime = time.time()
177
+ if engine is None:
178
+ ie = ForwardSamplingInference(ctbn)
179
+ else:
180
+ ie = engine
181
+
182
+ ie.makeInference()
183
+ stopTime = time.time()
184
+
185
+ temp_dir = mkdtemp("", "tmp", None) # with TemporaryDirectory() as temp_dir:
186
+
187
+ dotstr = 'digraph structs {\n fontcolor="' + gumcols.getBlackInTheme() + '";bgcolor="transparent";'
188
+
189
+ if gum.config.asBool["notebook", "show_inference_time"]:
190
+ dotstr += f' label="Inference in {1000 * (stopTime - startTime):6.2f}ms";\n'
191
+
192
+ fontname, fontsize = gumcols.fontFromMatplotlib()
193
+ dotstr += f' node [fillcolor="{gum.config["notebook", "default_node_bgcolor"]}", style=filled,color="{gum.config["notebook", "default_node_fgcolor"]}",fontname="{fontname}",fontsize="{fontsize}"];\n'
194
+ dotstr += f' edge [color="{gumcols.getBlackInTheme()}"];\n'
195
+
196
+ showdag = ctbn._graph
197
+
198
+ for nid in showdag.nodes():
199
+ name = ctbn.variable(nid).name()
200
+
201
+ # defaults
202
+ bgcol = gum.config["notebook", "default_node_bgcolor"]
203
+ fgcol = gum.config["notebook", "default_node_fgcolor"]
204
+ if len(targets) == 0 or name in targets or nid in targets:
205
+ bgcol = gum.config["notebook", "figure_facecolor"]
206
+
207
+ if nodeColor is not None and (name in nodeColor or nid in nodeColor):
208
+ bgcol = gumcols.proba2bgcolor(nodeColor[name], cmapNode)
209
+ fgcol = gumcols.proba2fgcolor(nodeColor[name], cmapNode)
210
+
211
+ # 'hard' colour for evidence (?)
212
+ # if name in evs or nid in evs:
213
+ # bgcol = gum.config["notebook", "evidence_bgcolor"]
214
+ # fgcol = gum.config["notebook", "evidence_fgcolor"]
215
+ colorattribute = f'fillcolor="{bgcol}", fontcolor="{fgcol}", color="#000000"'
216
+ if len(targets) == 0 or name in targets or nid in targets:
217
+ filename = temp_dir + hashlib.md5(name.encode()).hexdigest() + "." + gum.config["notebook", "graph_format"]
218
+ proba_histogram.saveFigProba(ie.posterior(name), filename, bgcolor=bgcol)
219
+ dotstr += f' "{name}" [shape=rectangle,image="{filename}",label="", {colorattribute}];\n'
220
+ else:
221
+ dotstr += f' "{name}" [{colorattribute}]'
222
+
223
+ for a in showdag.arcs():
224
+ (n, j) = a
225
+ pw = 1
226
+ av = f"{n} → {j}"
227
+ col = gumcols.getBlackInTheme()
228
+
229
+ if arcWidth is not None and a in arcWidth:
230
+ if maxarcs != minarcs:
231
+ pw = 0.1 + 5 * (arcWidth[a] - minarcs) / (maxarcs - minarcs)
232
+ av = f"{n} → {j} : {arcWidth[a]}"
233
+
234
+ if arcColor is not None and a in arcColor:
235
+ col = gumcols.proba2color(arcColor[a], cmapArc)
236
+
237
+ dotstr += (
238
+ f' "{ctbn.variable(n).name()}"->"{ctbn.variable(j).name()}" [penwidth="{pw}",tooltip="{av}",color="{col}"];'
239
+ )
240
+
241
+ dotstr += "}"
242
+
243
+ g = dot.graph_from_dot_data(dotstr)[0]
244
+
245
+ if size is None:
246
+ size = gum.config["notebook", "default_graph_inference_size"]
247
+ g.set_size(size)
248
+ g.temp_dir = temp_dir
249
+
250
+ return g
251
+
252
+
253
+ def getCtbnInference(ctbn: CTBN, engine, targets=None, size=None):
254
+ if size is None:
255
+ size = gum.config["ctbn", "default_graph_size"]
256
+
257
+ return gnb.getGraph(CTBNinference2dot(ctbn, engine, targets=targets, size=size))
258
+
259
+
260
+ def showCtbnInference(ctbn: CTBN, engine, targets=None, size=None):
261
+ gnb._showGraph(getCtbnInference(ctbn, engine, targets=targets, size=size))
262
+
263
+
264
+ CTBN._repr_html_ = lambda ctbn: getCtbnGraph(ctbn)
pyagrum/defaults.ini ADDED
@@ -0,0 +1,199 @@
1
+ [core]
2
+ default_maxNumberOfThreads = 24
3
+
4
+ [notebook]
5
+ # displaying tensors in (HTML) table
6
+ tensor_visible_digits = 4
7
+ tensor_with_colors = True
8
+ tensor_color_0 = #FF7F64
9
+ tensor_color_1 = #7FFF64
10
+ tensor_with_fraction = False
11
+ tensor_fraction_limit = 50
12
+ tensor_fraction_round_error = 1e-6
13
+ tensor_fraction_with_latex = True
14
+
15
+ # for histograms with matplotlibs
16
+ histogram_horizontal_visible_digits=2
17
+ histogram_vertical_visible_digits=2
18
+ histogram_horizontal_threshold = 8
19
+ histogram_line_threshold = 40
20
+ histogram_color=darkseagreen
21
+ histogram_edge_color=darkgreen
22
+ histogram_use_percent = True
23
+ # histogram | bar
24
+ histogram_discretized_visualisation = histogram
25
+ histogram_discretized_scale = 1.0
26
+
27
+
28
+ # compact | classical
29
+ histogram_mode=compact
30
+ histogram_epsilon=1e-8
31
+
32
+ # merge | revmerge | nomerge
33
+ tensor_parent_values = merge
34
+
35
+ # see matplotlib
36
+ figure_facecolor = #E0E0E0
37
+
38
+ # flow configuration
39
+ flow_background_color = transparent
40
+ flow_border_color = transparent
41
+ flow_border_width = 0
42
+
43
+ # svg or png
44
+ graph_format = svg
45
+
46
+ show_inference_time = True
47
+
48
+ #theming
49
+ default_arc_color = #4A4A4A
50
+ default_node_bgcolor = #404040
51
+ default_node_fgcolor = white
52
+ evidence_bgcolor = sandybrown
53
+ evidence_fgcolor = black
54
+ default_node_cmap = Pastel1
55
+ default_arc_cmap = BuGn
56
+ default_edge_cmap = BuGn
57
+
58
+ default_graph_size = 5
59
+ default_graph_inference_size = 8
60
+
61
+ # TB | LR
62
+ graph_rankdir = TB
63
+ # dot | neato | fdp | sfdp | twopi | circo | nop | nop2 | osage | patchwork
64
+ graph_layout = dot
65
+
66
+ # graph | factorgraph
67
+ default_markovrandomfield_view = factorgraph
68
+
69
+ # junctiontree / cliquegraph
70
+ junctiontree_graph_size = 10
71
+ junctiontree_with_names=True
72
+ junctiontree_separator_bgcolor=palegreen
73
+ junctiontree_separator_fgcolor=black
74
+ junctiontree_separator_fontsize=8
75
+ junctiontree_clique_bgcolor=burlywood
76
+ junctiontree_clique_fgcolor=black
77
+ junctiontree_clique_fontsize=10
78
+ junctiontree_map_cliquescale=0.3
79
+ junctiontree_map_sepscale=0.1
80
+ junctiontree_map_edgelen=1
81
+ junctiontree_map_size=10
82
+
83
+ # structural diff
84
+ graphdiff_missing_style=dashed
85
+ graphdiff_missing_color=red
86
+ graphdiff_overflow_style=dashed
87
+ graphdiff_overflow_color=purple
88
+ graphdiff_reversed_style=solid
89
+ graphdiff_reversed_color=purple
90
+ graphdiff_correct_style=solid
91
+ graphdiff_correct_color=grey
92
+
93
+
94
+ [BN]
95
+ allow_modification_when_saving = False
96
+
97
+ [factorgraph]
98
+ #theming
99
+ default_node_bgcolor = coral
100
+ default_node_fgcolor = black
101
+ default_factor_bgcolor = burlywood
102
+ edge_length = 0.7
103
+ edge_length_inference = 0.9
104
+ # dot | neato | fdp | sfdp | twopi | circo | nop | nop2 | osage | patchwork
105
+ graph_layout = neato
106
+
107
+ [dynamicBN]
108
+ #theming
109
+ default_graph_size = 6
110
+
111
+ [influenceDiagram]
112
+ #theming
113
+ default_graph_size = 6
114
+ default_chance_bgcolor = #808080
115
+ default_chance_fgcolor = white
116
+ default_utility_bgcolor = #50508A
117
+ default_utility_fgcolor = white
118
+ default_decision_bgcolor = #9A5050
119
+ default_decision_fgcolor = white
120
+
121
+ chance_shape = ellipse
122
+ utility_shape = hexagon
123
+ decision_shape = box
124
+
125
+ decision_arc_style = tapered, bold, dotted
126
+ utility_arc_style = dashed
127
+
128
+ default_id_size=6
129
+ default_id_inference_size=6
130
+
131
+ utility_visible_digits = 2
132
+ utility_show_stdev = True
133
+
134
+ #show utility (False) or -utility (Loss)
135
+ utility_show_loss = False
136
+
137
+ [credalnet]
138
+ #theming
139
+ default_node_bgcolor = #404040
140
+ default_node_fgcolor = white
141
+ histo_max_color = #BBFFAA
142
+
143
+ [causal]
144
+ show_latent_names = False
145
+ # latex command for notation of intervention in formula
146
+ #\hookrightarrow\mkern-6.5mu
147
+ latex_do_prefix = \text{do}(
148
+ latex_do_suffix = )
149
+
150
+ #theming
151
+ default_graph_size = 2.5
152
+ default_node_bgcolor = #404040
153
+ default_node_fgcolor = white
154
+ default_latent_bgcolor = #A08080
155
+ default_latent_fgcolor = black
156
+
157
+ [ROC]
158
+ draw_color = #008800
159
+ fill_color = #AAEEAA
160
+
161
+ [ctbn]
162
+ show_latent_names = False
163
+ default_graph_size = 2.5
164
+ default_node_bgcolor = #404040
165
+ default_node_fgcolor = white
166
+ default_latent_bgcolor = #A08080
167
+ default_latent_fgcolor = black
168
+
169
+ [bnmixture]
170
+ default_graph_size = 5
171
+
172
+ default_line_size = 1.0
173
+ default_head_size = 0.25
174
+ default_arrow_type=normal
175
+ default_arc_cmap = Greens
176
+ default_arc_color = #4A4A4A
177
+ default_arc_style = solid
178
+ default_node_bgcolor = #404040
179
+ default_node_fgcolor = white
180
+ default_layout = fdp
181
+ default_overlap = 0
182
+
183
+
184
+ default_bar_capsize = 1.5
185
+ default_bar_height = 0.8
186
+ default_boot_histo_scale = 2.0
187
+ default_histo_scale = 1.0
188
+
189
+ correct_arc_style = solid
190
+ correct_arc_color = green
191
+ incorrect_arc_style = dashed
192
+ incorrect_arc_color = green
193
+
194
+ left_quantile = 0.2
195
+ right_quantile = 0.8
196
+
197
+ [Pickle]
198
+ add_version = True
199
+ add_date = True
pyagrum/deprecated.py ADDED
@@ -0,0 +1,95 @@
1
+ ############################################################################
2
+ # This file is part of the aGrUM/pyAgrum library. #
3
+ # #
4
+ # Copyright (c) 2005-2025 by #
5
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
6
+ # - Christophe GONZALES(_at_AMU) #
7
+ # #
8
+ # The aGrUM/pyAgrum library is free software; you can redistribute it #
9
+ # and/or modify it under the terms of either : #
10
+ # #
11
+ # - the GNU Lesser General Public License as published by #
12
+ # the Free Software Foundation, either version 3 of the License, #
13
+ # or (at your option) any later version, #
14
+ # - the MIT license (MIT), #
15
+ # - or both in dual license, as here. #
16
+ # #
17
+ # (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) #
18
+ # #
19
+ # This aGrUM/pyAgrum library is distributed in the hope that it will be #
20
+ # useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #
21
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS #
22
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
23
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
24
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #
25
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR #
26
+ # OTHER DEALINGS IN THE SOFTWARE. #
27
+ # #
28
+ # See LICENCES for more details. #
29
+ # #
30
+ # SPDX-FileCopyrightText: Copyright 2005-2025 #
31
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
32
+ # - Christophe GONZALES(_at_AMU) #
33
+ # SPDX-License-Identifier: LGPL-3.0-or-later OR MIT #
34
+ # #
35
+ # Contact : info_at_agrum_dot_org #
36
+ # homepage : http://agrum.gitlab.io #
37
+ # gitlab : https://gitlab.com/agrumery/agrum #
38
+ # #
39
+ ############################################################################
40
+
41
+ """
42
+ Deprecated for older pyAgrum
43
+ """
44
+
45
+ import warnings
46
+ import functools
47
+
48
+
49
+ def deprecated_arg(newA: str, oldA: str, version: str):
50
+ """
51
+ Annotation of a function when changing the name of an argument of the function
52
+
53
+ Example
54
+ ------
55
+ @gum.deprecated_arg("x","old_x","1.8")
56
+ def f(x:int):
57
+ return 2*X
58
+
59
+ Parameters
60
+ ----------
61
+ newA:str
62
+ the new name of the argument
63
+ oldA:str
64
+ the old name of the argument
65
+ version:str
66
+ the version of pyAgrum
67
+ """
68
+
69
+ def deco(f):
70
+ @functools.wraps(f)
71
+ def wrapper(*args, **kwargs):
72
+ if oldA in kwargs:
73
+ if newA in kwargs:
74
+ warnings.warn(
75
+ f"""
76
+ ** pyAgrum : argument '{oldA}' is deprecated since '{version}', '{newA}' is used instead.
77
+ """,
78
+ DeprecationWarning,
79
+ stacklevel=2,
80
+ )
81
+ kwargs.pop(oldA)
82
+ else:
83
+ warnings.warn(
84
+ f"""
85
+ ** pyAgrum : argument '{oldA}' is deprecated since '{version}', please use '{newA}' is instead.
86
+ """,
87
+ DeprecationWarning,
88
+ stacklevel=2,
89
+ )
90
+ kwargs[newA] = kwargs.pop(oldA)
91
+ return f(*args, **kwargs)
92
+
93
+ return wrapper
94
+
95
+ return deco
@@ -0,0 +1,75 @@
1
+ ############################################################################
2
+ # This file is part of the aGrUM/pyAgrum library. #
3
+ # #
4
+ # Copyright (c) 2005-2025 by #
5
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
6
+ # - Christophe GONZALES(_at_AMU) #
7
+ # #
8
+ # The aGrUM/pyAgrum library is free software; you can redistribute it #
9
+ # and/or modify it under the terms of either : #
10
+ # #
11
+ # - the GNU Lesser General Public License as published by #
12
+ # the Free Software Foundation, either version 3 of the License, #
13
+ # or (at your option) any later version, #
14
+ # - the MIT license (MIT), #
15
+ # - or both in dual license, as here. #
16
+ # #
17
+ # (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) #
18
+ # #
19
+ # This aGrUM/pyAgrum library is distributed in the hope that it will be #
20
+ # useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #
21
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS #
22
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
23
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
24
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #
25
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR #
26
+ # OTHER DEALINGS IN THE SOFTWARE. #
27
+ # #
28
+ # See LICENCES for more details. #
29
+ # #
30
+ # SPDX-FileCopyrightText: Copyright 2005-2025 #
31
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
32
+ # - Christophe GONZALES(_at_AMU) #
33
+ # SPDX-License-Identifier: LGPL-3.0-or-later OR MIT #
34
+ # #
35
+ # Contact : info_at_agrum_dot_org #
36
+ # homepage : http://agrum.gitlab.io #
37
+ # gitlab : https://gitlab.com/agrumery/agrum #
38
+ # #
39
+ ############################################################################
40
+
41
+ import pyagrum as gum
42
+
43
+ # Calculations
44
+ import numpy as np
45
+
46
+
47
+ class CausalComputation:
48
+ @staticmethod
49
+ def _outOfCoalition(tau: list[int], inter: list[int]) -> list[int]:
50
+ # Returns the intersection of the parameter inter and the complement of the coalition tau.
51
+ return [i for i in inter if i not in tau]
52
+
53
+ @staticmethod
54
+ def _doCalculus(bn: gum.BayesNet, tau: list[int]) -> gum.BayesNet:
55
+ # Creates a new Bayesian Network by removing incoming arcs to the nodes in tau.
56
+ doNetTemplate = gum.BayesNet(bn)
57
+ for i in tau:
58
+ parents = doNetTemplate.parents(i)
59
+ for j in parents:
60
+ doNetTemplate.eraseArc(j, i)
61
+ return doNetTemplate
62
+
63
+ @staticmethod
64
+ def _chgCpt(doNetTemplate: gum.BayesNet, tau: list[int], alpha: list[int]) -> None:
65
+ # Changes the conditional probability tables (CPTs) of the nodes in tau to reflect the values in alpha.
66
+ for i, j in zip(tau, alpha):
67
+ doNetTemplate.cpt(i).fillWith(0.0)
68
+ doNetTemplate.cpt(i)[int(j)] = 1.0
69
+
70
+ @staticmethod
71
+ def _weight(evidces: dict[int, int], count: int, doLazy: gum.LazyPropagation) -> np.ndarray:
72
+ # Returns the evidces probability.
73
+ # The signature must be : Dict[int, int], int, **kwargs
74
+ doLazy.updateEvidence(evidces)
75
+ return doLazy.evidenceProbability() * count
@@ -0,0 +1,48 @@
1
+ ############################################################################
2
+ # This file is part of the aGrUM/pyAgrum library. #
3
+ # #
4
+ # Copyright (c) 2005-2025 by #
5
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
6
+ # - Christophe GONZALES(_at_AMU) #
7
+ # #
8
+ # The aGrUM/pyAgrum library is free software; you can redistribute it #
9
+ # and/or modify it under the terms of either : #
10
+ # #
11
+ # - the GNU Lesser General Public License as published by #
12
+ # the Free Software Foundation, either version 3 of the License, #
13
+ # or (at your option) any later version, #
14
+ # - the MIT license (MIT), #
15
+ # - or both in dual license, as here. #
16
+ # #
17
+ # (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) #
18
+ # #
19
+ # This aGrUM/pyAgrum library is distributed in the hope that it will be #
20
+ # useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #
21
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS #
22
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
23
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
24
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #
25
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR #
26
+ # OTHER DEALINGS IN THE SOFTWARE. #
27
+ # #
28
+ # See LICENCES for more details. #
29
+ # #
30
+ # SPDX-FileCopyrightText: Copyright 2005-2025 #
31
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
32
+ # - Christophe GONZALES(_at_AMU) #
33
+ # SPDX-License-Identifier: LGPL-3.0-or-later OR MIT #
34
+ # #
35
+ # Contact : info_at_agrum_dot_org #
36
+ # homepage : http://agrum.gitlab.io #
37
+ # gitlab : https://gitlab.com/agrumery/agrum #
38
+ # #
39
+ ############################################################################
40
+
41
+ import numpy as np
42
+
43
+
44
+ class ConditionalComputation:
45
+ @staticmethod
46
+ def _weight(evidces: dict[int, int], count: int) -> np.ndarray:
47
+ # The signature must be : Dict[int, int], int, **kwargs
48
+ return count