pyAgrum-nightly 2.3.1.9.dev202512261765915415__cp310-abi3-macosx_10_15_x86_64.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 +172 -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.1.9.dev202512261765915415.dist-info/LICENSE.md +12 -0
  103. pyagrum_nightly-2.3.1.9.dev202512261765915415.dist-info/LICENSES/LGPL-3.0-or-later.txt +304 -0
  104. pyagrum_nightly-2.3.1.9.dev202512261765915415.dist-info/LICENSES/MIT.txt +18 -0
  105. pyagrum_nightly-2.3.1.9.dev202512261765915415.dist-info/METADATA +145 -0
  106. pyagrum_nightly-2.3.1.9.dev202512261765915415.dist-info/RECORD +107 -0
  107. pyagrum_nightly-2.3.1.9.dev202512261765915415.dist-info/WHEEL +4 -0
pyagrum/__init__.py ADDED
@@ -0,0 +1,165 @@
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
+ `pyAgrum <http://agrum.org>`_ a scientific C++ and Python library dedicated to Bayesian Networks and other Probabilistic Graphical Models. Based on the C++ `aGrUM <https://agrum.lip6.fr>`_ library, it provides a high-level interface to the C++ part of aGrUM allowing to create, manage and perform efficient computations with Bayesian networks and others probabilsitic graphical models (Markov random fields, influence diagrams and LIMIDs, dynamic BN, probabilistic relational models).
43
+
44
+ The module is generated using the `SWIG <https://www.swig.org>`_ interface generator. Custom-written code was added to make the interface more friendly.
45
+
46
+ pyAgrum includes :
47
+ * API documentation <https://pyagrum.readthedocs.io>,
48
+ * examples as `notebooks <https://pyagrum.readthedocs.io/en/latest/notebooks/01-Tutorial.html>`_,
49
+ * a `website <http://agrum.org>`_.
50
+ """
51
+
52
+ # selection of imports extracted from dir(.pyagrum)
53
+
54
+ # submodule BASE
55
+ from .pyagrum import log2
56
+ from .pyagrum import statsObj
57
+ from .pyagrum import fastGraph
58
+ from .pyagrum import config
59
+ from .pyagrum import (
60
+ DiscretizedVariable,
61
+ LabelizedVariable,
62
+ RangeVariable,
63
+ DiscreteVariable,
64
+ IntegerVariable,
65
+ NumericalDiscreteVariable,
66
+ )
67
+ from .pyagrum import Tensor, Instantiation, Tensor
68
+ from .pyagrum import Arc, Edge, DiGraph, UndiGraph, MixedGraph, DAG, PDAG, CliqueGraph
69
+ from .pyagrum import JunctionTreeGenerator
70
+ from .pyagrum import MeekRules
71
+ from .pyagrum import ApproximationScheme
72
+ from .pyagrum import fastVariable
73
+ from .pyagrum import initRandom, randomProba, randomDistribution, randomGeneratorSeed, randomValue
74
+ from .pyagrum import isOMP, getNumberOfThreads, getMaxNumberOfThreads, getNumberOfLogicalProcessors, setNumberOfThreads
75
+ from .pyagrum import VarType_DISCRETIZED, VarType_LABELIZED, VarType_RANGE, VarType_INTEGER, VarType_NUMERICAL
76
+ from .pyagrum import (
77
+ DefaultInLabel,
78
+ DuplicateElement,
79
+ DuplicateLabel,
80
+ GumException,
81
+ FatalError,
82
+ FormatNotFound,
83
+ GraphError,
84
+ IOError,
85
+ InvalidArc,
86
+ InvalidArgument,
87
+ InvalidArgumentsNumber,
88
+ InvalidDirectedCycle,
89
+ InvalidEdge,
90
+ InvalidNode,
91
+ DatabaseError,
92
+ MissingValueInDatabase,
93
+ MissingVariableInDatabase,
94
+ NoChild,
95
+ NoNeighbour,
96
+ NoParent,
97
+ NotFound,
98
+ NullElement,
99
+ OperationNotAllowed,
100
+ OutOfBounds,
101
+ ArgumentError,
102
+ SizeError,
103
+ SyntaxError,
104
+ UndefinedElement,
105
+ UndefinedIteratorKey,
106
+ UndefinedIteratorValue,
107
+ UnknownLabelInDatabase,
108
+ CPTError,
109
+ )
110
+
111
+ # submodule BN
112
+ from .pyagrum import fastBN
113
+ from .pyagrum import availableBNExts, loadBN, saveBN
114
+ from .pyagrum import randomBN, generateSample
115
+ from .pyagrum import mutilateBN
116
+ from .pyagrum import BayesNet, BayesNetFragment, EssentialGraph, MarkovBlanket
117
+ from .pyagrum import ExactBNdistance, GibbsBNdistance, StructuralComparator
118
+ from .pyagrum import LazyPropagation, ShaferShenoyInference, VariableElimination
119
+ from .pyagrum import LoopyBeliefPropagation, GibbsSampling, MonteCarloSampling, ImportanceSampling, WeightedSampling
120
+ from .pyagrum import LoopyImportanceSampling, LoopyGibbsSampling, LoopyWeightedSampling, LoopyMonteCarloSampling
121
+ from .pyagrum import PythonApproximationListener, PythonBNListener, PythonLoadListener, PythonDatabaseGeneratorListener
122
+ from .pyagrum import BNGenerator
123
+ from .pyagrum import BNDatabaseGenerator, InformationTheory
124
+ from .pyagrum import BNLearner
125
+ from .pyagrum import PRMexplorer
126
+
127
+ import sys
128
+
129
+ # sublodule MRF
130
+ try:
131
+ from .pyagrum import getPosterior
132
+ from .pyagrum import availableMRFExts, loadMRF, saveMRF
133
+ from .pyagrum import fastMRF
134
+ from .pyagrum import MarkovRandomField, ShaferShenoyMRFInference
135
+ except ImportError:
136
+ sys.stderr.write("Could not load Markov Random Field submodule")
137
+
138
+ # submodule CN
139
+ try:
140
+ from .pyagrum import CredalNet, CNMonteCarloSampling, CNLoopyPropagation
141
+ except ImportError:
142
+ sys.stderr.write("Could not load Credal Net submodule")
143
+
144
+ # submodule ID
145
+ try:
146
+ from .pyagrum import IDGenerator
147
+ from .pyagrum import availableIDExts, loadID, saveID
148
+ from .pyagrum import fastID
149
+ from .pyagrum import InfluenceDiagram, ShaferShenoyLIMIDInference
150
+ except ImportError:
151
+ sys.stderr.write("Could not load Influence Diagram submodule")
152
+
153
+ from .common import (
154
+ __version__,
155
+ __license__,
156
+ __project_url__,
157
+ __project_name__,
158
+ __project_description__,
159
+ __project__,
160
+ about,
161
+ )
162
+
163
+ # deprecated
164
+ from .deprecated import deprecated_arg
165
+ from .pyagrum import Potential
pyagrum/_pyagrum.so ADDED
Binary file
@@ -0,0 +1,268 @@
1
+ from typing import Tuple
2
+ from numpy import quantile, array
3
+
4
+ ############################################################################
5
+ # This file is part of the aGrUM/pyAgrum library. #
6
+ # #
7
+ # Copyright (c) 2005-2025 by #
8
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
9
+ # - Christophe GONZALES(_at_AMU) #
10
+ # #
11
+ # The aGrUM/pyAgrum library is free software; you can redistribute it #
12
+ # and/or modify it under the terms of either : #
13
+ # #
14
+ # - the GNU Lesser General Public License as published by #
15
+ # the Free Software Foundation, either version 3 of the License, #
16
+ # or (at your option) any later version, #
17
+ # - the MIT license (MIT), #
18
+ # - or both in dual license, as here. #
19
+ # #
20
+ # (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) #
21
+ # #
22
+ # This aGrUM/pyAgrum library is distributed in the hope that it will be #
23
+ # useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, #
24
+ # INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS #
25
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #
26
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #
27
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, #
28
+ # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR #
29
+ # OTHER DEALINGS IN THE SOFTWARE. #
30
+ # #
31
+ # See LICENCES for more details. #
32
+ # #
33
+ # SPDX-FileCopyrightText: Copyright 2005-2025 #
34
+ # - Pierre-Henri WUILLEMIN(_at_LIP6) #
35
+ # - Christophe GONZALES(_at_AMU) #
36
+ # SPDX-License-Identifier: LGPL-3.0-or-later OR MIT #
37
+ # #
38
+ # Contact : info_at_agrum_dot_org #
39
+ # homepage : http://agrum.gitlab.io #
40
+ # gitlab : https://gitlab.com/agrumery/agrum #
41
+ # #
42
+ ############################################################################
43
+
44
+ import pyagrum
45
+
46
+ import pyagrum.bnmixture as BNM
47
+
48
+
49
+ def tensor2ref(ref, tens) -> "pyagrum.Tensor":
50
+ """
51
+ Returns a copy of ``tens`` but with a reference to ``ref`` 's variables instead. Allow to sum tensors that have the same variables
52
+ but with different instantiations of them.
53
+
54
+ Parameters
55
+ ----------
56
+ ref : pyagrum.Tensor
57
+ Tensor containing variables of reference.
58
+ tens : pyagrum.Tensor
59
+ Tensor to convert.
60
+
61
+ Returns
62
+ -------
63
+ pyagrum.Tensor
64
+ The converted tensor with values of ``tens`` and variable references of ``ref``.
65
+ """
66
+ res = pyagrum.Tensor()
67
+ for v in tens.names:
68
+ res.add(ref.variable(v))
69
+ return res.fillWith(tens)
70
+
71
+
72
+ class IMixtureInference:
73
+ """
74
+ Interface class for inference on Mixture models.
75
+ """
76
+
77
+ def __init__(self):
78
+ self._inferences = []
79
+ raise NotImplementedError("Interface should not be initialized !")
80
+
81
+ def setEvidence(self, evs):
82
+ """
83
+ Erases all the evidences and apply addEvidence(key,value) for every pairs in ``evs``. Does this for every BN in the model, excluding reference BN.
84
+
85
+ Parameters
86
+ ----------
87
+ evs : dict
88
+ A dict of evidences.
89
+ """
90
+ for ie in self._inferences:
91
+ ie.setEvidence(evs)
92
+
93
+ def makeInference(self):
94
+ """
95
+ Compute inference for all BNs in the model, excluding reference BN.
96
+ """
97
+ for ie in self._inferences:
98
+ ie.makeInference()
99
+
100
+ def _posteriors(self, name: str):
101
+ """
102
+ Parameters
103
+ ----------
104
+ name : str
105
+ Name of the variable.
106
+
107
+ Returns
108
+ -------
109
+ List[pyagrum.Tensor]
110
+ List of (not normalized) posteriors of variable ``name`` for each BN in the model, excluding reference BN.
111
+ """
112
+ return {ie._model.property("name"): pyagrum.Tensor(ie.posterior(name)) for ie in self._inferences}
113
+
114
+
115
+ class BNMixtureInference(IMixtureInference):
116
+ """
117
+ Class used for inference on BNMixtures.
118
+
119
+ Parameters
120
+ ----------
121
+ bnm : BNM.BNMixture
122
+ Model used.
123
+ engine : Optional
124
+ Inference tool used to compute inference. You shuold give the class and not an initialized object. Example : engine=pyagrum.LazyPropagation is ok
125
+ but not engine=pyagrum.LazyPropagation(bnm).
126
+ """
127
+
128
+ def __init__(self, bnm: BNM.BNMixture, engine=pyagrum.LazyPropagation):
129
+ """
130
+ Parameters
131
+ ----------
132
+ bnm : BNM.BNMixture
133
+ Model used.
134
+ engine : Optional
135
+ Inference tool used to compute inference. You shuold give the class and not an initialized object. Example : engine=pyagrum.LazyPropagation is ok
136
+ but not engine=pyagrum.LazyPropagation(bnm).
137
+ """
138
+ self._bnm = bnm
139
+ self._engine = engine
140
+ self._inferences = [self._engine(bn) for bn in self._bnm.BNs()]
141
+
142
+ def posterior(self, name: str) -> "pyagrum.Tensor":
143
+ """
144
+ Parameters
145
+ ----------
146
+ name : str
147
+ Variable to compute posterior for.
148
+
149
+ Returns
150
+ -------
151
+ pyagrum.Tensor
152
+ The weighted mean (over all the BNs in the model) of the posterior of a variable.
153
+ """
154
+ posts = self._posteriors(name)
155
+
156
+ ret = pyagrum.Tensor()
157
+ for bn_name in posts:
158
+ ret += posts[bn_name].toVarsIn(self._bnm) * self._bnm.weight(bn_name)
159
+
160
+ return ret.normalize()
161
+
162
+
163
+ class BootstrapMixtureInference(IMixtureInference):
164
+ """
165
+ Class used for inference on BootstrapMixture objects. The main difference with BNMixtureInference is that the returned posterior is not a mean of all posteriors in the BNs but only
166
+ the one of the reference BN. The other BNs are used to estimate parameters such as max, min and quantile values.
167
+
168
+ Parameters
169
+ ----------
170
+ bnm : BNM.BootstrapMixture
171
+ Model used.
172
+ engine : Optional
173
+ Inference tool used to compute inference. You shold give the class and not an initialized object. Example : engine=pyagrum.LazyPropagation is ok
174
+ but not engine=pyagrum.LazyPropagation(bnm).
175
+ """
176
+
177
+ def __init__(self, bnm: BNM.BootstrapMixture, engine=pyagrum.LazyPropagation):
178
+ self._bnm = bnm
179
+ self._engine = engine
180
+ self._ref_inference = self._engine(pyagrum.BayesNet(self._bnm._refBN))
181
+ self._inferences = [self._engine(bn) for bn in self._bnm.BNs()]
182
+
183
+ def setEvidence(self, evs):
184
+ """
185
+ Erases all the evidences and apply addEvidence(key,value) for every pairs in ``evs``. Does this for every BN in the model, including reference BN.
186
+
187
+ Parameters
188
+ ----------
189
+ evs : dict
190
+ A dict of evidences.
191
+ """
192
+ self._ref_inference.setEvidence(evs)
193
+ super().setEvidence(evs)
194
+
195
+ def makeInference(self):
196
+ """
197
+ Compute inference for all BNs (including reference BN) in the model.
198
+ """
199
+ self._ref_inference.makeInference()
200
+ super().makeInference()
201
+
202
+ def posterior(self, name: str) -> "pyagrum.Tensor":
203
+ """
204
+ Parameters
205
+ ----------
206
+ name : str
207
+ Variable to compute posterior for.
208
+
209
+ Returns
210
+ -------
211
+ pyagrum.Tensor
212
+ The posterior of variable ``name`` in the reference BN.
213
+ """
214
+ ref_post = self._ref_inference.posterior(name)
215
+ return ref_post.normalize()
216
+
217
+ def quantiles(self, name: str) -> Tuple[pyagrum.Tensor, pyagrum.Tensor]:
218
+ """
219
+ Parameters
220
+ ----------
221
+ name : str
222
+ Variable to compute quantiles for.
223
+
224
+ Returns
225
+ -------
226
+ Tuple[pyagrum.Tensor, pyagrum.Tensor]
227
+ Two tensors to store the quantile values. Each tensor stores the quantile for each state of the variable.
228
+ The values considered are those of the BNs in the Mixture (excluding reference BN).
229
+
230
+ Raises
231
+ ------
232
+ pyagrum.SizeError
233
+ If the mixture doesn't contain any BN.
234
+ """
235
+ if self._bnm.size() == 0:
236
+ raise pyagrum.SizeError("The mixture doesn't contain any BN, can't compute quantiles")
237
+ q1 = float(pyagrum.config["bnmixture", "left_quantile"])
238
+ q2 = float(pyagrum.config["bnmixture", "right_quantile"])
239
+ var = self._bnm.variable(name)
240
+
241
+ # init tensors to return
242
+ ret1 = pyagrum.Tensor()
243
+ ret1.add(var)
244
+ ret1.fillWith(0)
245
+ ret2 = pyagrum.Tensor()
246
+ ret2.add(var)
247
+ ret2.fillWith(0)
248
+ I = pyagrum.Instantiation()
249
+ I.add(var)
250
+
251
+ # normalize posteriors
252
+ posteriors = self._posteriors(name)
253
+ for nam in posteriors:
254
+ posteriors[nam] = posteriors[nam].toVarsIn(self._bnm).normalize()
255
+
256
+ # set quantile values
257
+ I.setFirst()
258
+ while not I.end():
259
+ values = []
260
+ for nam in posteriors:
261
+ values.append(posteriors[nam].get(I))
262
+ v1 = quantile(array(values), q1)
263
+ v2 = quantile(array(values), q2)
264
+ ret1.set(I, v1)
265
+ ret2.set(I, v2)
266
+ I.inc()
267
+
268
+ return (ret1, ret2)