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
pyagrum/lib/ipython.py ADDED
@@ -0,0 +1,307 @@
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
+ tools for BN analysis in ipython (and spyder)
43
+ """
44
+
45
+ import IPython.display
46
+ import matplotlib as mpl
47
+ import matplotlib.pyplot as plt
48
+ import numpy as np
49
+ import pydot as dot
50
+
51
+ from IPython.display import Image, display
52
+
53
+ import pyagrum as gum
54
+ from pyagrum.lib.bn2graph import BN2dot
55
+ from pyagrum.lib.id2graph import ID2dot
56
+ from pyagrum.lib.mrf2graph import MRF2UGdot
57
+ from pyagrum.lib.mrf2graph import MRF2FactorGraphdot
58
+ from pyagrum.lib.bn_vs_bn import GraphicalBNComparator
59
+ from pyagrum.lib.proba_histogram import proba2histo
60
+
61
+ # check if an instance of ipython exists
62
+ try:
63
+ get_ipython
64
+ except NameError:
65
+ raise ImportError(
66
+ "[pyAgrum ERROR] pyagrum.lib.ipython has to be imported from an IPython's instance (mainly ipython's console)."
67
+ ) from None
68
+
69
+
70
+ def configuration():
71
+ """
72
+ Display the collection of dependance and versions
73
+ """
74
+ from collections import OrderedDict
75
+ import sys
76
+ import os
77
+
78
+ packages = OrderedDict()
79
+ packages["OS"] = "%s [%s]" % (os.name, sys.platform)
80
+ packages["Python"] = sys.version
81
+ packages["IPython"] = IPython.__version__
82
+ packages["MatPlotLib"] = mpl.__version__
83
+ packages["Numpy"] = np.__version__
84
+ packages["pyAgrum"] = gum.__version__
85
+
86
+ for name in packages:
87
+ print("%s : %s" % (name, packages[name]))
88
+
89
+
90
+ def showGraph(gr, size=None):
91
+ """
92
+ show a pydot graph in a notebook
93
+
94
+ Parameters
95
+ ----------
96
+ gr: pydot.Dot
97
+ the graph to show
98
+ size: int|str
99
+ the size of the visualisation
100
+ """
101
+ if size is None:
102
+ size = gum.config["notebook", "default_graph_size"]
103
+
104
+ gr.set_size(size)
105
+ display(Image(gr.create_png()))
106
+
107
+
108
+ def _from_dotstring(dotstring):
109
+ g = dot.graph_from_dot_data(dotstring)[0]
110
+ return g
111
+
112
+
113
+ def showDot(dotstring, size=None):
114
+ """
115
+ show a dot string as a graph
116
+
117
+ Parameters
118
+ ----------
119
+ dotstring: str
120
+ the dot string
121
+ size: float | str
122
+ the size of the graphe
123
+ """
124
+ showGraph(_from_dotstring(dotstring), size)
125
+
126
+
127
+ def showBNDiff(bn1, bn2, size=None):
128
+ """show a graphical diff between the arcs of _bn1 (reference) with those of _bn2.
129
+
130
+ * full black line: the arc is common for both
131
+ * full red line: the arc is common but inverted in _bn2
132
+ * dotted black line: the arc is added in _bn2
133
+ * dotted red line: the arc is removed in _bn2
134
+
135
+ :param BayesNet bn1: referent model for the comparison
136
+ :param BayesNet bn2: bn compared to the referent model
137
+ :param size: size of the rendered graph
138
+ """
139
+ if size is None:
140
+ size = gum.config["notebook", "default_graph_size"]
141
+ cmp = GraphicalBNComparator(bn1, bn2)
142
+ showGraph(cmp.dotDiff(), size)
143
+
144
+
145
+ def showJunctionTree(bn, withNames=True, size=None):
146
+ """
147
+ Show a junction tree
148
+
149
+ :param bn: the Bayesian network
150
+ :param boolean withNames: display the variable names or the node id in the clique
151
+ :param size: size of the rendered graph
152
+ """
153
+ jtg = gum.JunctionTreeGenerator()
154
+ jt = jtg.junctionTree(bn)
155
+ if withNames:
156
+ return showDot(jt.toDotWithNames(bn), size)
157
+ else:
158
+ return showDot(jt.toDot(), size)
159
+
160
+
161
+ def showBN(bn, size=None, nodeColor=None, arcWidth=None, arcColor=None, cmap=None, cmapArc=None):
162
+ """
163
+ show a Bayesian network
164
+
165
+ :param bn: the Bayesian network
166
+ :param size: size of the rendered graph
167
+ :param format: render as "png" or "svg"
168
+ :param vals: a nodeMap of values to be shown as color nodes
169
+ :param arcvals: a arcMap of values to be shown as bold arcs
170
+ :param cmap: color map to show the vals
171
+ """
172
+ if size is None:
173
+ size = gum.config["notebook", "default_graph_size"]
174
+
175
+ if cmapArc is None:
176
+ cmapArc = cmap
177
+
178
+ return showGraph(BN2dot(bn, size, nodeColor, arcWidth, arcColor, cmap, cmapArc), size)
179
+
180
+
181
+ def showProba(p, scale=1.0):
182
+ """
183
+ Show a mono-dim Tensor
184
+
185
+ :param p: the mono-dim Tensor
186
+ :return:
187
+ """
188
+ _ = proba2histo(p, scale)
189
+ # fig.patch.set_facecolor(gum.config["notebook", "figure_facecolor"])
190
+ IPython.display.set_matplotlib_formats(gum.config["notebook", "graph_format"])
191
+ plt.show()
192
+
193
+
194
+ def showPosterior(bn, evs, target):
195
+ """
196
+ shortcut for showProba(gum.getPosterior(bn,evs,target))
197
+
198
+ :param bn: the BayesNet
199
+ :param evs: map of evidence
200
+ :param target: name of target variable
201
+ """
202
+ showProba(gum.getPosterior(bn, evs=evs, target=target))
203
+
204
+
205
+ def showMRF(
206
+ mrf, view=None, size=None, nodeColor=None, factorColor=None, edgeWidth=None, edgeColor=None, cmap=None, cmapEdge=None
207
+ ):
208
+ """
209
+ show a Markov random field
210
+
211
+ :param mrf: the Markov random field
212
+ :param view: 'graph' | 'factorgraph’ | None (default)
213
+ :param size: size of the rendered graph
214
+ :param nodeColor: a nodeMap of values (between 0 and 1) to be shown as color of nodes (with special colors for 0 and 1)
215
+ :param factorColor: a function returning a value (beeween 0 and 1) to be shown as a color of factor. (used when view='factorgraph')
216
+ :param edgeWidth: a edgeMap of values to be shown as width of edges (used when view='graph')
217
+ :param edgeColor: a edgeMap of values (between 0 and 1) to be shown as color of edges (used when view='graph')
218
+ :param cmap: color map to show the colors
219
+ :param cmapEdge: color map to show the edge color if distinction is needed
220
+ :return: the graph
221
+ """
222
+ if view is None:
223
+ view = gum.config["notebook", "default_markovrandomfield_view"]
224
+
225
+ if size is None:
226
+ size = gum.config["notebook", "default_graph_size"]
227
+
228
+ if cmapEdge is None:
229
+ cmapEdge = cmap
230
+
231
+ if view == "graph":
232
+ dottxt = MRF2UGdot(mrf, size, nodeColor, edgeWidth, edgeColor, cmap, cmapEdge)
233
+ else:
234
+ dottxt = MRF2FactorGraphdot(mrf, size, nodeColor, factorColor, cmapNode=cmap)
235
+
236
+ return showGraph(dottxt, size)
237
+
238
+
239
+ def showInfluenceDiagram(diag, size=None):
240
+ """
241
+ show an influence diagram as a graph
242
+
243
+ :param diag: the influence diagram
244
+ :param size: size of the rendered graph
245
+ :return: the representation of the influence diagram
246
+ """
247
+ if size is None:
248
+ size = gum.config["influenceDiagram", "default_id_size"]
249
+
250
+ return showGraph(ID2dot(diag), size)
251
+
252
+
253
+ def showInference(
254
+ model,
255
+ engine=None,
256
+ evs=None,
257
+ targets=None,
258
+ size=None,
259
+ nodeColor=None,
260
+ factorColor=None,
261
+ arcWidth=None,
262
+ arcColor=None,
263
+ cmap=None,
264
+ cmapArc=None,
265
+ graph=None,
266
+ view=None,
267
+ ):
268
+ import warnings
269
+
270
+ warnings.warn(
271
+ "gum.lib.ipython does not provide `showInference` due to the use of svg format (not compatible with spyder)."
272
+ )
273
+
274
+
275
+ def showTensor(p):
276
+ print(p)
277
+
278
+
279
+ def show(model, size=None):
280
+ """
281
+ propose a (visual) representation of a model in ipython console
282
+
283
+ :param GraphicalModel model: the model to show (pyagrum.BayesNet, pyagrum.MarkovRandomField, pyagrum.InfluenceDiagram or pyagrum.Tensor)
284
+
285
+ :param int size: optional size for the graphical model (no effect for Tensor)
286
+ """
287
+ if isinstance(model, gum.BayesNet):
288
+ showBN(model, size)
289
+ elif isinstance(model, gum.MarkovRandomField):
290
+ showMRF(model, size)
291
+ elif isinstance(model, gum.InfluenceDiagram):
292
+ showInfluenceDiagram(model, size)
293
+ elif isinstance(model, gum.Tensor):
294
+ showTensor(model)
295
+ else:
296
+ raise gum.InvalidArgument("Argument model should be a PGM (BayesNet, MarkovRandomField or Influence Diagram")
297
+
298
+
299
+ # check if an instance of ipython exists
300
+ try:
301
+ get_ipython
302
+ except NameError:
303
+ import warnings
304
+
305
+ warnings.warn("""
306
+ ** pyagrum.lib.notebook has to be import from an IPython's instance.
307
+ """)