1# This file was automatically generated by SWIG (http://www.swig.org).
2# Version 4.1.0
3#
4# Do not make changes to this file unless you know what you are doing--modify
5# the SWIG interface file instead.
6
7"""pyAgrum is a scientific C++ and Python library dedicated to Bayesian Networks and other Probabilistic Graphical Models.  It provides a high-level interface to the part of the C++ aGrUM library allowing to create, model, learn, use, calculate with and embed Bayesian Networks and other graphical models. Some specific (python and C++) codes are added in order to simplify and extend the aGrUM API. The module is mainly generated by the SWIG interface generator."""
8
9from sys import version_info as _swig_python_version_info
10if _swig_python_version_info < (3, 0):
11    raise RuntimeError("Python 3.x or later required")
12
13## added by passForType (pyAgrum)
14from typing import List,Set,Dict,Tuple
15## end of added by passForType (pyAgrum)
16
17# Import the low-level C/C++ module
18if __package__ or "." in __name__:
19    from . import _pyAgrum
20else:
21    import _pyAgrum
22
23try:
24    import builtins as __builtin__
25except ImportError:
26    import __builtin__
27
28def _swig_repr(self):
29    try:
30        strthis = "proxy of " + self.this.__repr__()
31    except __builtin__.Exception:
32        strthis = ""
33    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
34
35
36def _swig_setattr_nondynamic_instance_variable(set):
37    def set_instance_attr(self, name, value):
38        if name == "thisown":
39            self.this.own(value)
40        elif name == "this":
41            set(self, name, value)
42        elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
43            set(self, name, value)
44        else:
45            raise AttributeError("You cannot add instance attributes to %s" % self)
46    return set_instance_attr
47
48
49def _swig_setattr_nondynamic_class_variable(set):
50    def set_class_attr(cls, name, value):
51        if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
52            set(cls, name, value)
53        else:
54            raise AttributeError("You cannot add class attributes to %s" % cls)
55    return set_class_attr
56
57
58def _swig_add_metaclass(metaclass):
59    """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
60    def wrapper(cls):
61        return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
62    return wrapper
63
64
65class _SwigNonDynamicMeta(type):
66    """Meta class to enforce nondynamic attributes (no new attributes) for a class"""
67    __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)
68
69
70import weakref
71
72class SwigPyIterator(object):
73    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
74
75    def __init__(self, *args, **kwargs):
76        raise AttributeError("No constructor defined - class is abstract")
77    __repr__ = _swig_repr
78    __swig_destroy__ = _pyAgrum.delete_SwigPyIterator
79
80    def value(self) -> object:
81        return _pyAgrum.SwigPyIterator_value(self)
82
83    def incr(self, n: int=1) -> "swig::SwigPyIterator *":
84        return _pyAgrum.SwigPyIterator_incr(self, n)
85
86    def decr(self, n: int=1) -> "swig::SwigPyIterator *":
87        return _pyAgrum.SwigPyIterator_decr(self, n)
88
89    def distance(self, x: "SwigPyIterator") -> "ptrdiff_t":
90        return _pyAgrum.SwigPyIterator_distance(self, x)
91
92    def equal(self, x: "SwigPyIterator") -> bool:
93        return _pyAgrum.SwigPyIterator_equal(self, x)
94
95    def copy(self) -> "swig::SwigPyIterator *":
96        return _pyAgrum.SwigPyIterator_copy(self)
97
98    def next(self) -> object:
99        return _pyAgrum.SwigPyIterator_next(self)
100
101    def __next__(self) -> object:
102        return _pyAgrum.SwigPyIterator___next__(self)
103
104    def previous(self) -> object:
105        return _pyAgrum.SwigPyIterator_previous(self)
106
107    def advance(self, n: "ptrdiff_t") -> "swig::SwigPyIterator *":
108        return _pyAgrum.SwigPyIterator_advance(self, n)
109
110    def __eq__(self, x: "SwigPyIterator") -> bool:
111        return _pyAgrum.SwigPyIterator___eq__(self, x)
112
113    def __ne__(self, x: "SwigPyIterator") -> bool:
114        return _pyAgrum.SwigPyIterator___ne__(self, x)
115
116    def __iadd__(self, n: "ptrdiff_t") -> "swig::SwigPyIterator &":
117        return _pyAgrum.SwigPyIterator___iadd__(self, n)
118
119    def __isub__(self, n: "ptrdiff_t") -> "swig::SwigPyIterator &":
120        return _pyAgrum.SwigPyIterator___isub__(self, n)
121
122    def __add__(self, n: "ptrdiff_t") -> "swig::SwigPyIterator *":
123        return _pyAgrum.SwigPyIterator___add__(self, n)
124
125    def __sub__(self, *args) -> "ptrdiff_t":
126        return _pyAgrum.SwigPyIterator___sub__(self, *args)
127    def __iter__(self):
128        return self
129
130# Register SwigPyIterator in _pyAgrum:
131_pyAgrum.SwigPyIterator_swigregister(SwigPyIterator)
132
133
134import numpy
135from numbers import Number
136
137class JunctionTreeGenerator(object):
138    r"""
139
140    JunctionTreeGenerator is use to generate junction tree or binary junction tree from Bayesian networks.
141
142    JunctionTreeGenerator() -> JunctionTreeGenerator
143        default constructor
144
145    """
146
147    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
148    __repr__ = _swig_repr
149
150    def junctionTree(self, *args) -> "pyAgrum.JunctionTree":
151        r"""
152
153        Computes the junction tree for its parameters. If the first parameter is a graph, the heurisitcs assume that all the node have the same domain size (2). If given, the heuristic takes into account the partial order for its elimination order.
154
155        Parameters
156        ----------
157        g : pyAgrum.UndiGraph
158        	a undirected graph
159
160        dag : pyAgrum.DAG
161        	a dag
162
163        bn : pyAgrum.BayesNet
164        	a BayesianNetwork
165
166        partial_order: List[List[int]]
167        	a partial order among the nodeIDs
168
169        Returns
170        -------
171        pyAgrum.CliqueGraph
172        	the current junction tree.
173
174        """
175        return _pyAgrum.JunctionTreeGenerator_junctionTree(self, *args)
176
177    def eliminationOrder(self, *args) -> object:
178        r"""
179
180        Computes the elimination for its parameters. If the first parameter is a graph, the heurisitcs assume that all the node have the same domain size (2). If given, the heuristic takes into account the partial order for its elimination order.
181
182        Parameters
183        ----------
184        g : pyAgrum.UndiGraph
185        	a undirected graph
186
187        dag : pyAgrum.DAG
188        	a dag
189
190        bn : pyAgrum.BayesNet
191        	a BayesianNetwork
192
193        partial_order: List[List[int]]
194        	a partial order among the nodeIDs
195
196        Returns
197        -------
198        pyAgrum.CliqueGraph
199        	the current elimination order.
200
201        """
202        return _pyAgrum.JunctionTreeGenerator_eliminationOrder(self, *args)
203
204    def binaryJoinTree(self, *args) -> "pyAgrum.JunctionTree":
205        r"""
206
207        Computes the binary joint tree for its parameters. If the first parameter is a graph, the heurisitcs assume that all the node have the same domain size (2). If given, the heuristic takes into account the partial order for its elimination order.
208
209        Parameters
210        ----------
211        g : pyAgrum.UndiGraph
212        	a undirected graph
213
214        dag : pyAgrum.DAG
215        	a dag
216
217        bn : pyAgrum.BayesNet
218        	a BayesianNetwork
219
220        partial_order: List[List[int]]
221        	a partial order among the nodeIDs
222
223        Returns
224        -------
225        pyAgrum.CliqueGraph
226        	the current binary joint tree
227
228        """
229        return _pyAgrum.JunctionTreeGenerator_binaryJoinTree(self, *args)
230
231    def __init__(self):
232        r"""
233
234        JunctionTreeGenerator is use to generate junction tree or binary junction tree from Bayesian networks.
235
236        JunctionTreeGenerator() -> JunctionTreeGenerator
237            default constructor
238
239        """
240        _pyAgrum.JunctionTreeGenerator_swiginit(self, _pyAgrum.new_JunctionTreeGenerator())
241    __swig_destroy__ = _pyAgrum.delete_JunctionTreeGenerator
242
243# Register JunctionTreeGenerator in _pyAgrum:
244_pyAgrum.JunctionTreeGenerator_swigregister(JunctionTreeGenerator)
245
246class PythonBNListener(object):
247    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
248    __repr__ = _swig_repr
249
250    def __init__(self, bn: "pyAgrum.BayesNet", vnm: "pyAgrum.VariableNodeMap"):
251        _pyAgrum.PythonBNListener_swiginit(self, _pyAgrum.new_PythonBNListener(bn, vnm))
252    __swig_destroy__ = _pyAgrum.delete_PythonBNListener
253
254    def whenNodeAdded(self, source: object, id: int) -> None:
255        return _pyAgrum.PythonBNListener_whenNodeAdded(self, source, id)
256
257    def whenNodeDeleted(self, arg2: object, id: int) -> None:
258        return _pyAgrum.PythonBNListener_whenNodeDeleted(self, arg2, id)
259
260    def whenArcAdded(self, arg2: object, src: int, dst: int) -> None:
261        return _pyAgrum.PythonBNListener_whenArcAdded(self, arg2, src, dst)
262
263    def whenArcDeleted(self, arg2: object, src: int, dst: int) -> None:
264        return _pyAgrum.PythonBNListener_whenArcDeleted(self, arg2, src, dst)
265
266    def setWhenArcAdded(self, pyfunc: object) -> None:
267        r"""
268
269
270
271        """
272        return _pyAgrum.PythonBNListener_setWhenArcAdded(self, pyfunc)
273
274    def setWhenArcDeleted(self, pyfunc: object) -> None:
275        r"""
276
277
278
279        """
280        return _pyAgrum.PythonBNListener_setWhenArcDeleted(self, pyfunc)
281
282    def setWhenNodeAdded(self, pyfunc: object) -> None:
283        r"""
284
285
286
287        """
288        return _pyAgrum.PythonBNListener_setWhenNodeAdded(self, pyfunc)
289
290    def setWhenNodeDeleted(self, pyfunc: object) -> None:
291        r"""
292
293
294
295        """
296        return _pyAgrum.PythonBNListener_setWhenNodeDeleted(self, pyfunc)
297
298# Register PythonBNListener in _pyAgrum:
299_pyAgrum.PythonBNListener_swigregister(PythonBNListener)
300
301class PythonLoadListener(object):
302    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
303    __repr__ = _swig_repr
304
305    def whenLoading(self, buffer: object, percent: int) -> None:
306        return _pyAgrum.PythonLoadListener_whenLoading(self, buffer, percent)
307
308    def setPythonListener(self, l: object) -> bool:
309        r"""
310
311
312
313        """
314        return _pyAgrum.PythonLoadListener_setPythonListener(self, l)
315
316    def __init__(self):
317        _pyAgrum.PythonLoadListener_swiginit(self, _pyAgrum.new_PythonLoadListener())
318    __swig_destroy__ = _pyAgrum.delete_PythonLoadListener
319
320# Register PythonLoadListener in _pyAgrum:
321_pyAgrum.PythonLoadListener_swigregister(PythonLoadListener)
322
323
324def _fillLoadListeners_(py_listener: List["pyAgrum.PythonLoadListener"], l: object) -> int:
325    return _pyAgrum._fillLoadListeners_(py_listener, l)
326class PythonApproximationListener(object):
327    r"""
328
329    Parameters
330    ----------
331    algo : IApproximationSchemeConfiguration
332    	an approxmation scheme
333
334    """
335
336    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
337    __repr__ = _swig_repr
338
339    def __init__(self, algo: "IApproximationSchemeConfiguration"):
340        r"""
341
342        Parameters
343        ----------
344        algo : IApproximationSchemeConfiguration
345        	an approxmation scheme
346
347        """
348        _pyAgrum.PythonApproximationListener_swiginit(self, _pyAgrum.new_PythonApproximationListener(algo))
349    __swig_destroy__ = _pyAgrum.delete_PythonApproximationListener
350
351    def whenProgress(self, src: object, step: int, error: float, duration: float) -> None:
352        return _pyAgrum.PythonApproximationListener_whenProgress(self, src, step, error, duration)
353
354    def whenStop(self, src: object, message: str) -> None:
355        return _pyAgrum.PythonApproximationListener_whenStop(self, src, message)
356
357    def setWhenProgress(self, pyfunc: object) -> None:
358        r"""
359
360        Parameters
361        ----------
362        pyfunc
363        	the function to execute
364
365        """
366        return _pyAgrum.PythonApproximationListener_setWhenProgress(self, pyfunc)
367
368    def setWhenStop(self, pyfunc: object) -> None:
369        r"""
370
371        Parameters
372        ----------
373        pyfunc
374        	the function to execute
375
376        """
377        return _pyAgrum.PythonApproximationListener_setWhenStop(self, pyfunc)
378
379# Register PythonApproximationListener in _pyAgrum:
380_pyAgrum.PythonApproximationListener_swigregister(PythonApproximationListener)
381
382class PythonDatabaseGeneratorListener(object):
383    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
384    __repr__ = _swig_repr
385
386    def __init__(self, notif: "BNDatabaseGenerator"):
387        _pyAgrum.PythonDatabaseGeneratorListener_swiginit(self, _pyAgrum.new_PythonDatabaseGeneratorListener(notif))
388    __swig_destroy__ = _pyAgrum.delete_PythonDatabaseGeneratorListener
389
390    def whenProgress(self, src: object, step: int, duration: float) -> None:
391        return _pyAgrum.PythonDatabaseGeneratorListener_whenProgress(self, src, step, duration)
392
393    def whenStop(self, src: object, message: str) -> None:
394        return _pyAgrum.PythonDatabaseGeneratorListener_whenStop(self, src, message)
395
396    def setWhenProgress(self, pyfunc: object) -> None:
397        return _pyAgrum.PythonDatabaseGeneratorListener_setWhenProgress(self, pyfunc)
398
399    def setWhenStop(self, pyfunc: object) -> None:
400        return _pyAgrum.PythonDatabaseGeneratorListener_setWhenStop(self, pyfunc)
401
402# Register PythonDatabaseGeneratorListener in _pyAgrum:
403_pyAgrum.PythonDatabaseGeneratorListener_swigregister(PythonDatabaseGeneratorListener)
404
405class BNGenerator(object):
406    r"""
407
408    BNGenerator is used to easily generate Bayesian networks.
409
410    BNGenerator() -> BNGenerator
411        default constructor
412
413    """
414
415    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
416    __repr__ = _swig_repr
417
418    def generate(self, n_nodes: int=10, n_arcs: int=15, n_modmax: int=4) -> "pyAgrum.BayesNet":
419        r"""
420
421        Generate a new Bayesian network
422
423        Parameters
424        ----------
425        n_nodes : int
426        	the number of nodes (default=10)
427        n_arcs : int
428        	the number of arcs (default=15)
429        n_nodmax : int
430        	the max number of modalities for a node (default=4)
431
432        Returns
433        -------
434        pyAgrum.BayesNet
435        	the generated Bayesian network
436
437        Raises
438        ------
439        pyAgrum.OperationNotAllowed
440        	If n_modmax < 2
441        pyAgrum.OperationNotAllowed
442        	If n_arcs is incompatible with n_nodes (not enough arcs)
443
444        """
445        return _pyAgrum.BNGenerator_generate(self, n_nodes, n_arcs, n_modmax)
446
447    def __init__(self):
448        r"""
449
450        BNGenerator is used to easily generate Bayesian networks.
451
452        BNGenerator() -> BNGenerator
453            default constructor
454
455        """
456        _pyAgrum.BNGenerator_swiginit(self, _pyAgrum.new_BNGenerator())
457    __swig_destroy__ = _pyAgrum.delete_BNGenerator
458
459# Register BNGenerator in _pyAgrum:
460_pyAgrum.BNGenerator_swigregister(BNGenerator)
461
462class IDGenerator(object):
463    r"""
464
465    IDGenerator is used to easily generate influence diagrams.
466
467    IDGenerator() -> IDGenerator
468        default constructor
469
470    """
471
472    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
473    __repr__ = _swig_repr
474
475    def generate(self, nbrNodes: int=10, arcDensity: float=0.2, chanceNodeDensity: float=0.8, utilityNodeDensity: float=0.1, max_modality: int=2) -> "pyAgrum.InfluenceDiagram":
476        r"""
477
478        Generate a new influence diagram given the parameters.
479
480        Parameters
481        ----------
482        nbrNodes : int
483        	the number of node
484        arcDensity : float
485        	the density of arc (1 for a complete graph)
486        chanceNodeDensity : float
487        	the density of chance node
488        utilityNodeDensity : float
489        	the density of utility node
490        max_modality : int
491        	the maximum value for modalities
492
493        Returns
494        -------
495        pyAgrum.InfluenceDiagram
496        	the generated influence diagram
497
498        """
499        return _pyAgrum.IDGenerator_generate(self, nbrNodes, arcDensity, chanceNodeDensity, utilityNodeDensity, max_modality)
500
501    def __init__(self):
502        r"""
503
504        IDGenerator is used to easily generate influence diagrams.
505
506        IDGenerator() -> IDGenerator
507            default constructor
508
509        """
510        _pyAgrum.IDGenerator_swiginit(self, _pyAgrum.new_IDGenerator())
511    __swig_destroy__ = _pyAgrum.delete_IDGenerator
512
513# Register IDGenerator in _pyAgrum:
514_pyAgrum.IDGenerator_swigregister(IDGenerator)
515
516class PRMexplorer(object):
517    r"""
518
519    PRMexplorer helps navigate through probabilistic relational models.
520
521    PRMexplorer() -> PRMexplorer
522        default constructor
523
524    """
525
526    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
527    __repr__ = _swig_repr
528
529    def __init__(self):
530        r"""
531
532        PRMexplorer helps navigate through probabilistic relational models.
533
534        PRMexplorer() -> PRMexplorer
535            default constructor
536
537        """
538        _pyAgrum.PRMexplorer_swiginit(self, _pyAgrum.new_PRMexplorer())
539    __swig_destroy__ = _pyAgrum.delete_PRMexplorer
540
541    def load(self, *args) -> None:
542        r"""
543
544        Load a PRM into the explorer.
545
546        Parameters
547        ----------
548        filename : str
549        	the name of the o3prm file
550        classpath : str
551        	the classpath of the PRM
552
553        Raises
554        ------
555        pyAgrum.FatalError
556        	If file not found
557
558        """
559        return _pyAgrum.PRMexplorer_load(self, *args)
560
561    def isType(self, name: str) -> object:
562        r"""
563
564        Parameters
565        ----------
566        name : str
567        	an element name
568
569        Returns
570        -------
571        bool
572        	True if the parameter correspond to a type in the PRM
573
574        """
575        return _pyAgrum.PRMexplorer_isType(self, name)
576
577    def isClass(self, name: str) -> object:
578        r"""
579
580        Parameters
581        ----------
582        name : str
583        	an element name
584
585        Returns
586        -------
587        bool
588        	True if the parameter correspond to a class in the PRM
589
590        """
591        return _pyAgrum.PRMexplorer_isClass(self, name)
592
593    def isInterface(self, name: str) -> object:
594        r"""
595
596        Parameters
597        ----------
598        name : str
599        	an element name
600
601        Returns
602        -------
603        bool
604        	True if the parameter correspond to an interface in the PRM
605
606        """
607        return _pyAgrum.PRMexplorer_isInterface(self, name)
608
609    def classes(self) -> object:
610        r"""
611
612        Returns
613        -------
614        list
615        	the list of classes
616
617        """
618        return _pyAgrum.PRMexplorer_classes(self)
619
620    def classAttributes(self, class_name: str) -> object:
621        r"""
622
623        Parameters
624        ----------
625        class_name : str
626        	a class name
627
628        Returns
629        -------
630        list
631        	the list of attributes
632
633        Raises
634        ------
635        pyAgrum.IndexError
636        	If the class is not in the PRM
637
638        """
639        return _pyAgrum.PRMexplorer_classAttributes(self, class_name)
640
641    def isAttribute(self, class_name: str, att_name: str) -> object:
642        r"""
643
644        Parameters
645        ----------
646        class_name : str
647        	a class name
648        att_name : str
649        	the name of the attribute to be tested
650
651        Returns
652        -------
653        bool
654        	True if att_name is an attribute of class_name
655
656        Raises
657        ------
658        pyAgrum.IndexError
659        	If the class is not in the PRM
660        pyAgrum.IndexError
661        	If att_name is not an element of class_name
662
663        """
664        return _pyAgrum.PRMexplorer_isAttribute(self, class_name, att_name)
665
666    def classReferences(self, class_name: str) -> object:
667        r"""
668
669        Parameters
670        ----------
671        class_name : str
672        	a class name
673
674        Returns
675        -------
676        list
677        	the list of references
678
679        Raises
680        ------
681        pyAgrum.IndexError
682        	If the class is not in the PRM
683
684        """
685        return _pyAgrum.PRMexplorer_classReferences(self, class_name)
686
687    def classParameters(self, class_name: str) -> object:
688        r"""
689
690        Parameters
691        ----------
692        class_name : str
693        	a class name
694
695        Returns
696        -------
697        list
698        	the list of parameters
699
700        Raises
701        ------
702        pyAgrum.IndexError
703        	If the class is not in the PRM
704
705        """
706        return _pyAgrum.PRMexplorer_classParameters(self, class_name)
707
708    def classImplements(self, class_name: str) -> object:
709        r"""
710
711        Parameters
712        ----------
713        class_name : str
714        	a class name
715
716        Returns
717        -------
718        list
719        	the list of interfaces implemented by the class
720
721        """
722        return _pyAgrum.PRMexplorer_classImplements(self, class_name)
723    aggType = property(_pyAgrum.PRMexplorer_aggType_get, _pyAgrum.PRMexplorer_aggType_set, doc=r"""
724
725    min/max/count/exists/forall/or/and/amplitude/median
726
727    """)
728
729    def classAggregates(self, class_name: str) -> object:
730        r"""
731
732        Parameters
733        ----------
734        class_name : str
735        	a class name
736
737        Returns
738        -------
739        list
740        	the list of aggregates in the class
741
742        Raises
743        ------
744        pyAgrum.IndexError
745        	If the class is not in the PRM
746
747        """
748        return _pyAgrum.PRMexplorer_classAggregates(self, class_name)
749
750    def classSlotChains(self, class_name: str) -> object:
751        r"""
752
753        Parameters
754        ----------
755        class_name : str
756        	a class name
757
758        Returns
759        -------
760        list
761        	the list of class slot chains
762
763        Raises
764        ------
765        pyAgrum.IndexError
766        	if the class is not in the PRM
767
768        """
769        return _pyAgrum.PRMexplorer_classSlotChains(self, class_name)
770
771    def classDag(self, class_name: str) -> object:
772        r"""
773
774        Parameters
775        ----------
776        class_name : str
777        	a class name
778
779        Returns
780        -------
781        tuple
782        	a description of the DAG
783
784        Raises
785        ------
786        pyAgrum.IndexError
787        	If the class is not in the PRM
788
789        """
790        return _pyAgrum.PRMexplorer_classDag(self, class_name)
791
792    def getalltheSystems(self) -> object:
793        r"""
794
795        Returns
796        -------
797        list
798        	the list of all the systems and their components
799
800        """
801        return _pyAgrum.PRMexplorer_getalltheSystems(self)
802
803    def getSuperClass(self, class_name: str) -> object:
804        r"""
805
806        Parameters
807        ----------
808        class_name : str
809        	a class name
810
811        Returns
812        -------
813        str
814        	the class extended by class_name
815
816        Raises
817        ------
818        pyAgrum.IndexError
819        	If the class is not in the PRM
820
821        """
822        return _pyAgrum.PRMexplorer_getSuperClass(self, class_name)
823
824    def getDirectSubClass(self, class_name: str) -> object:
825        r"""
826
827        Parameters
828        ----------
829        class_name : str
830        	a class name
831
832        Returns
833        -------
834        list
835        	the list of direct subclasses
836
837        Raises
838        ------
839        pyAgrum.IndexError
840        	If the class is not in the PRM
841
842        """
843        return _pyAgrum.PRMexplorer_getDirectSubClass(self, class_name)
844
845    def cpf(self, class_name: str, attribute: str) -> "pyAgrum.Potential":
846        r"""
847
848        Parameters
849        ----------
850        class_name : str
851        	a class name
852
853        attribute : str
854        	an attribute
855
856        Returns
857        -------
858        pyAgrum.Potential
859        	the potential of the attribute
860
861        Raises
862        ------
863        pyAgrum.OperationNotAllowed
864        	If the class element doesn't have any pyAgrum.Potential (like a gum::PRMReferenceSlot).
865        pyAgrum.IndexError
866        	If the class is not in the PRM
867        pyAgrum.IndexError
868        	If the attribute in parameters does not exist
869
870        """
871        return _pyAgrum.PRMexplorer_cpf(self, class_name, attribute)
872
873    def types(self) -> object:
874        r"""
875
876        Returns
877        -------
878        list
879        	the list of the custom types in the PRM
880
881        """
882        return _pyAgrum.PRMexplorer_types(self)
883
884    def getSuperType(self, type_name: str) -> object:
885        r"""
886
887        Parameters
888        ----------
889        type_name : str
890        	a type name
891
892        Returns
893        -------
894        str
895        	the type extended by type_name
896
897        Raises
898        ------
899        pyAgrum.IndexError
900        	If the type is not in the PRM
901
902        """
903        return _pyAgrum.PRMexplorer_getSuperType(self, type_name)
904
905    def getDirectSubTypes(self, type_name: str) -> object:
906        r"""
907
908        Parameters
909        ----------
910        type_name : str
911        	a type name
912
913        Returns
914        -------
915        list
916        	the list of direct subtypes
917
918        Raises
919        ------
920        pyAgrum.IndexError
921        	If the type is not in the PRM
922
923        """
924        return _pyAgrum.PRMexplorer_getDirectSubTypes(self, type_name)
925
926    def getLabels(self, type_name: str) -> object:
927        r"""
928
929        Parameters
930        ----------
931        type_name : str
932        	a type name
933
934        Returns
935        -------
936        list
937        	the list of type labels
938
939        Raises
940        ------
941        pyAgrum.IndexError
942        	If the type is not in the PRM
943
944        """
945        return _pyAgrum.PRMexplorer_getLabels(self, type_name)
946
947    def getLabelMap(self, type_name: str) -> object:
948        r"""
949
950        Parameters
951        ----------
952        type_name : str
953        	a type name
954
955        Returns
956        -------
957        dict
958        	a dict containing pairs of label and their values
959
960        Raises
961        ------
962        pyAgrum.IndexError
963        	If the type is not in the PRM
964
965        """
966        return _pyAgrum.PRMexplorer_getLabelMap(self, type_name)
967
968    def interfaces(self) -> object:
969        r"""
970
971        Returns
972        -------
973        list
974        	the list of interfaces in the PRM
975
976        """
977        return _pyAgrum.PRMexplorer_interfaces(self)
978
979    def interAttributes(self, interface_name: str, allAttributes: bool=False) -> object:
980        r"""
981
982        Parameters
983        ----------
984        interface_name : str
985        	an interface
986
987        allAttributes : bool
988        	True if supertypes of a custom type should be indicated
989
990        Returns
991        -------
992        list
993        	the list of (<type>,<attribute_name>) for the given interface
994
995        Raises
996        ------
997        pyAgrum.IndexError
998        	If the type is not in the PRM
999
1000        """
1001        return _pyAgrum.PRMexplorer_interAttributes(self, interface_name, allAttributes)
1002
1003    def interReferences(self, interface_name: str) -> object:
1004        r"""
1005
1006        Parameters
1007        ----------
1008        interface_name : str
1009        	an interface
1010
1011        Returns
1012        -------
1013        list
1014        	the list of (<reference_type>,<reference_name>,<True if the reference is an array>) for the given interface
1015
1016        Raises
1017        ------
1018        pyAgrum.IndexError
1019        	If the type is not in the PRM
1020
1021        """
1022        return _pyAgrum.PRMexplorer_interReferences(self, interface_name)
1023
1024    def getSuperInterface(self, interface_name: str) -> object:
1025        r"""
1026
1027        Parameters
1028        ----------
1029        interface_name : str
1030        	an interface name
1031
1032        Returns
1033        -------
1034        str
1035        	the interace extended by interface_name
1036
1037        Raises
1038        ------
1039        pyAgrum.IndexError
1040        	If the interface is not in the PRM
1041
1042        """
1043        return _pyAgrum.PRMexplorer_getSuperInterface(self, interface_name)
1044
1045    def getDirectSubInterfaces(self, interface_name: str) -> object:
1046        r"""
1047
1048        Parameters
1049        ----------
1050        interface_name : str
1051        	an interface name
1052
1053        Returns
1054        -------
1055        list
1056        	the list of direct subinterfaces
1057
1058        Raises
1059        ------
1060        pyAgrum.IndexError
1061        	If the interface is not in the PRM
1062
1063        """
1064        return _pyAgrum.PRMexplorer_getDirectSubInterfaces(self, interface_name)
1065
1066    def getImplementations(self, interface_name: str) -> object:
1067        r"""
1068
1069        Parameters
1070        ----------
1071        interface_name : str
1072        	an interface name
1073
1074        Returns
1075        -------
1076        str
1077        	the list of classes implementing the interface
1078
1079        Raises
1080        ------
1081        pyAgrum.IndexError
1082        	If the interface is not in the PRM
1083
1084        """
1085        return _pyAgrum.PRMexplorer_getImplementations(self, interface_name)
1086
1087# Register PRMexplorer in _pyAgrum:
1088_pyAgrum.PRMexplorer_swigregister(PRMexplorer)
1089
1090class Vector(object):
1091    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1092    __repr__ = _swig_repr
1093
1094    def iterator(self) -> "swig::SwigPyIterator *":
1095        return _pyAgrum.Vector_iterator(self)
1096    def __iter__(self):
1097        return self.iterator()
1098
1099    def __nonzero__(self) -> bool:
1100        return _pyAgrum.Vector___nonzero__(self)
1101
1102    def __bool__(self) -> bool:
1103        return _pyAgrum.Vector___bool__(self)
1104
1105    def __len__(self) -> int:
1106        return _pyAgrum.Vector___len__(self)
1107
1108    def __getslice__(self, i: int, j: int) -> List[float]:
1109        return _pyAgrum.Vector___getslice__(self, i, j)
1110
1111    def __setslice__(self, *args) -> None:
1112        return _pyAgrum.Vector___setslice__(self, *args)
1113
1114    def __delslice__(self, i: int, j: int) -> None:
1115        return _pyAgrum.Vector___delslice__(self, i, j)
1116
1117    def __delitem__(self, *args) -> None:
1118        return _pyAgrum.Vector___delitem__(self, *args)
1119
1120    def __getitem__(self, *args) -> float:
1121        return _pyAgrum.Vector___getitem__(self, *args)
1122
1123    def __setitem__(self, *args) -> None:
1124        return _pyAgrum.Vector___setitem__(self, *args)
1125
1126    def pop(self) -> float:
1127        return _pyAgrum.Vector_pop(self)
1128
1129    def append(self, x: float) -> None:
1130        return _pyAgrum.Vector_append(self, x)
1131
1132    def empty(self) -> bool:
1133        return _pyAgrum.Vector_empty(self)
1134
1135    def size(self) -> int:
1136        return _pyAgrum.Vector_size(self)
1137
1138    def swap(self, v: "Vector") -> None:
1139        return _pyAgrum.Vector_swap(self, v)
1140
1141    def begin(self) -> "std::vector< double >::iterator":
1142        return _pyAgrum.Vector_begin(self)
1143
1144    def end(self) -> "std::vector< double >::iterator":
1145        return _pyAgrum.Vector_end(self)
1146
1147    def rbegin(self) -> "std::vector< double >::reverse_iterator":
1148        return _pyAgrum.Vector_rbegin(self)
1149
1150    def rend(self) -> "std::vector< double >::reverse_iterator":
1151        return _pyAgrum.Vector_rend(self)
1152
1153    def clear(self) -> None:
1154        return _pyAgrum.Vector_clear(self)
1155
1156    def get_allocator(self) -> "std::vector< double >::allocator_type":
1157        return _pyAgrum.Vector_get_allocator(self)
1158
1159    def pop_back(self) -> None:
1160        return _pyAgrum.Vector_pop_back(self)
1161
1162    def erase(self, *args) -> "std::vector< double >::iterator":
1163        return _pyAgrum.Vector_erase(self, *args)
1164
1165    def __init__(self, *args):
1166        _pyAgrum.Vector_swiginit(self, _pyAgrum.new_Vector(*args))
1167
1168    def push_back(self, x: float) -> None:
1169        return _pyAgrum.Vector_push_back(self, x)
1170
1171    def front(self) -> float:
1172        return _pyAgrum.Vector_front(self)
1173
1174    def back(self) -> float:
1175        return _pyAgrum.Vector_back(self)
1176
1177    def assign(self, n: int, x: float) -> None:
1178        return _pyAgrum.Vector_assign(self, n, x)
1179
1180    def resize(self, *args) -> None:
1181        return _pyAgrum.Vector_resize(self, *args)
1182
1183    def insert(self, *args) -> None:
1184        return _pyAgrum.Vector_insert(self, *args)
1185
1186    def reserve(self, n: int) -> None:
1187        return _pyAgrum.Vector_reserve(self, n)
1188
1189    def capacity(self) -> int:
1190        return _pyAgrum.Vector_capacity(self)
1191    __swig_destroy__ = _pyAgrum.delete_Vector
1192
1193# Register Vector in _pyAgrum:
1194_pyAgrum.Vector_swigregister(Vector)
1195
1196class Vector_int(object):
1197    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1198    __repr__ = _swig_repr
1199
1200    def iterator(self) -> "swig::SwigPyIterator *":
1201        return _pyAgrum.Vector_int_iterator(self)
1202    def __iter__(self):
1203        return self.iterator()
1204
1205    def __nonzero__(self) -> bool:
1206        return _pyAgrum.Vector_int___nonzero__(self)
1207
1208    def __bool__(self) -> bool:
1209        return _pyAgrum.Vector_int___bool__(self)
1210
1211    def __len__(self) -> int:
1212        return _pyAgrum.Vector_int___len__(self)
1213
1214    def __getslice__(self, i: int, j: int) -> List[int]:
1215        return _pyAgrum.Vector_int___getslice__(self, i, j)
1216
1217    def __setslice__(self, *args) -> None:
1218        return _pyAgrum.Vector_int___setslice__(self, *args)
1219
1220    def __delslice__(self, i: int, j: int) -> None:
1221        return _pyAgrum.Vector_int___delslice__(self, i, j)
1222
1223    def __delitem__(self, *args) -> None:
1224        return _pyAgrum.Vector_int___delitem__(self, *args)
1225
1226    def __getitem__(self, *args) -> int:
1227        return _pyAgrum.Vector_int___getitem__(self, *args)
1228
1229    def __setitem__(self, *args) -> None:
1230        return _pyAgrum.Vector_int___setitem__(self, *args)
1231
1232    def pop(self) -> int:
1233        return _pyAgrum.Vector_int_pop(self)
1234
1235    def append(self, x: int) -> None:
1236        return _pyAgrum.Vector_int_append(self, x)
1237
1238    def empty(self) -> bool:
1239        return _pyAgrum.Vector_int_empty(self)
1240
1241    def size(self) -> int:
1242        return _pyAgrum.Vector_int_size(self)
1243
1244    def swap(self, v: "Vector_int") -> None:
1245        return _pyAgrum.Vector_int_swap(self, v)
1246
1247    def begin(self) -> "std::vector< int >::iterator":
1248        return _pyAgrum.Vector_int_begin(self)
1249
1250    def end(self) -> "std::vector< int >::iterator":
1251        return _pyAgrum.Vector_int_end(self)
1252
1253    def rbegin(self) -> "std::vector< int >::reverse_iterator":
1254        return _pyAgrum.Vector_int_rbegin(self)
1255
1256    def rend(self) -> "std::vector< int >::reverse_iterator":
1257        return _pyAgrum.Vector_int_rend(self)
1258
1259    def clear(self) -> None:
1260        return _pyAgrum.Vector_int_clear(self)
1261
1262    def get_allocator(self) -> "std::vector< int >::allocator_type":
1263        return _pyAgrum.Vector_int_get_allocator(self)
1264
1265    def pop_back(self) -> None:
1266        return _pyAgrum.Vector_int_pop_back(self)
1267
1268    def erase(self, *args) -> "std::vector< int >::iterator":
1269        return _pyAgrum.Vector_int_erase(self, *args)
1270
1271    def __init__(self, *args):
1272        _pyAgrum.Vector_int_swiginit(self, _pyAgrum.new_Vector_int(*args))
1273
1274    def push_back(self, x: int) -> None:
1275        return _pyAgrum.Vector_int_push_back(self, x)
1276
1277    def front(self) -> int:
1278        return _pyAgrum.Vector_int_front(self)
1279
1280    def back(self) -> int:
1281        return _pyAgrum.Vector_int_back(self)
1282
1283    def assign(self, n: int, x: int) -> None:
1284        return _pyAgrum.Vector_int_assign(self, n, x)
1285
1286    def resize(self, *args) -> None:
1287        return _pyAgrum.Vector_int_resize(self, *args)
1288
1289    def insert(self, *args) -> None:
1290        return _pyAgrum.Vector_int_insert(self, *args)
1291
1292    def reserve(self, n: int) -> None:
1293        return _pyAgrum.Vector_int_reserve(self, n)
1294
1295    def capacity(self) -> int:
1296        return _pyAgrum.Vector_int_capacity(self)
1297    __swig_destroy__ = _pyAgrum.delete_Vector_int
1298
1299# Register Vector_int in _pyAgrum:
1300_pyAgrum.Vector_int_swigregister(Vector_int)
1301
1302class Vector_string(object):
1303    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1304    __repr__ = _swig_repr
1305
1306    def iterator(self) -> "swig::SwigPyIterator *":
1307        return _pyAgrum.Vector_string_iterator(self)
1308    def __iter__(self):
1309        return self.iterator()
1310
1311    def __nonzero__(self) -> bool:
1312        return _pyAgrum.Vector_string___nonzero__(self)
1313
1314    def __bool__(self) -> bool:
1315        return _pyAgrum.Vector_string___bool__(self)
1316
1317    def __len__(self) -> "std::vector< str >::size_type":
1318        return _pyAgrum.Vector_string___len__(self)
1319
1320    def __getslice__(self, i: "std::vector< str >::difference_type", j: "std::vector< str >::difference_type") -> List[str]:
1321        return _pyAgrum.Vector_string___getslice__(self, i, j)
1322
1323    def __setslice__(self, *args) -> None:
1324        return _pyAgrum.Vector_string___setslice__(self, *args)
1325
1326    def __delslice__(self, i: "std::vector< str >::difference_type", j: "std::vector< str >::difference_type") -> None:
1327        return _pyAgrum.Vector_string___delslice__(self, i, j)
1328
1329    def __delitem__(self, *args) -> None:
1330        return _pyAgrum.Vector_string___delitem__(self, *args)
1331
1332    def __getitem__(self, *args) -> str:
1333        return _pyAgrum.Vector_string___getitem__(self, *args)
1334
1335    def __setitem__(self, *args) -> None:
1336        return _pyAgrum.Vector_string___setitem__(self, *args)
1337
1338    def pop(self) -> str:
1339        return _pyAgrum.Vector_string_pop(self)
1340
1341    def append(self, x: str) -> None:
1342        return _pyAgrum.Vector_string_append(self, x)
1343
1344    def empty(self) -> bool:
1345        return _pyAgrum.Vector_string_empty(self)
1346
1347    def size(self) -> "std::vector< str >::size_type":
1348        return _pyAgrum.Vector_string_size(self)
1349
1350    def swap(self, v: "Vector_string") -> None:
1351        return _pyAgrum.Vector_string_swap(self, v)
1352
1353    def begin(self) -> "std::vector< str >::iterator":
1354        return _pyAgrum.Vector_string_begin(self)
1355
1356    def end(self) -> "std::vector< str >::iterator":
1357        return _pyAgrum.Vector_string_end(self)
1358
1359    def rbegin(self) -> "std::vector< str >::reverse_iterator":
1360        return _pyAgrum.Vector_string_rbegin(self)
1361
1362    def rend(self) -> "std::vector< str >::reverse_iterator":
1363        return _pyAgrum.Vector_string_rend(self)
1364
1365    def clear(self) -> None:
1366        return _pyAgrum.Vector_string_clear(self)
1367
1368    def get_allocator(self) -> "std::vector< str >::allocator_type":
1369        return _pyAgrum.Vector_string_get_allocator(self)
1370
1371    def pop_back(self) -> None:
1372        return _pyAgrum.Vector_string_pop_back(self)
1373
1374    def erase(self, *args) -> "std::vector< str >::iterator":
1375        return _pyAgrum.Vector_string_erase(self, *args)
1376
1377    def __init__(self, *args):
1378        _pyAgrum.Vector_string_swiginit(self, _pyAgrum.new_Vector_string(*args))
1379
1380    def push_back(self, x: str) -> None:
1381        return _pyAgrum.Vector_string_push_back(self, x)
1382
1383    def front(self) -> str:
1384        return _pyAgrum.Vector_string_front(self)
1385
1386    def back(self) -> str:
1387        return _pyAgrum.Vector_string_back(self)
1388
1389    def assign(self, n: "std::vector< str >::size_type", x: str) -> None:
1390        return _pyAgrum.Vector_string_assign(self, n, x)
1391
1392    def resize(self, *args) -> None:
1393        return _pyAgrum.Vector_string_resize(self, *args)
1394
1395    def insert(self, *args) -> None:
1396        return _pyAgrum.Vector_string_insert(self, *args)
1397
1398    def reserve(self, n: "std::vector< str >::size_type") -> None:
1399        return _pyAgrum.Vector_string_reserve(self, n)
1400
1401    def capacity(self) -> "std::vector< str >::size_type":
1402        return _pyAgrum.Vector_string_capacity(self)
1403    __swig_destroy__ = _pyAgrum.delete_Vector_string
1404
1405# Register Vector_string in _pyAgrum:
1406_pyAgrum.Vector_string_swigregister(Vector_string)
1407
1408class SetIteratorStaticEnd(object):
1409    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1410    __repr__ = _swig_repr
1411
1412    def __init__(self):
1413        _pyAgrum.SetIteratorStaticEnd_swiginit(self, _pyAgrum.new_SetIteratorStaticEnd())
1414    __swig_destroy__ = _pyAgrum.delete_SetIteratorStaticEnd
1415
1416# Register SetIteratorStaticEnd in _pyAgrum:
1417_pyAgrum.SetIteratorStaticEnd_swigregister(SetIteratorStaticEnd)
1418
1419class GumException(Exception):
1420    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1421    __repr__ = _swig_repr
1422
1423    def __init__(self, *args):
1424        _pyAgrum.GumException_swiginit(self, _pyAgrum.new_GumException(*args))
1425    __swig_destroy__ = _pyAgrum.delete_GumException
1426
1427    def what(self) -> str:
1428        return _pyAgrum.GumException_what(self)
1429
1430    def errorContent(self) -> str:
1431        r"""
1432
1433        Returns
1434        -------
1435        str
1436        	the error content
1437
1438        """
1439        return _pyAgrum.GumException_errorContent(self)
1440
1441    def errorType(self) -> str:
1442        r"""
1443
1444        Returns
1445        -------
1446        str
1447        	the error type
1448
1449        """
1450        return _pyAgrum.GumException_errorType(self)
1451
1452    def errorCallStack(self) -> str:
1453        r"""
1454
1455        Returns
1456        -------
1457        str
1458        	the error call stack
1459
1460        """
1461        return _pyAgrum.GumException_errorCallStack(self)
1462
1463# Register GumException in _pyAgrum:
1464_pyAgrum.GumException_swigregister(GumException)
1465
1466
1467def _createMsg_(filename: str, function: str, line: int, msg: str) -> str:
1468    return _pyAgrum._createMsg_(filename, function, line, msg)
1469class FatalError(GumException):
1470    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1471    __repr__ = _swig_repr
1472
1473    def __init__(self, *args):
1474        _pyAgrum.FatalError_swiginit(self, _pyAgrum.new_FatalError(*args))
1475    __swig_destroy__ = _pyAgrum.delete_FatalError
1476
1477# Register FatalError in _pyAgrum:
1478_pyAgrum.FatalError_swigregister(FatalError)
1479
1480class NotImplementedYet(GumException):
1481    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1482    __repr__ = _swig_repr
1483
1484    def __init__(self, *args):
1485        _pyAgrum.NotImplementedYet_swiginit(self, _pyAgrum.new_NotImplementedYet(*args))
1486    __swig_destroy__ = _pyAgrum.delete_NotImplementedYet
1487
1488# Register NotImplementedYet in _pyAgrum:
1489_pyAgrum.NotImplementedYet_swigregister(NotImplementedYet)
1490
1491class IteratorError(GumException):
1492    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1493    __repr__ = _swig_repr
1494
1495    def __init__(self, *args):
1496        _pyAgrum.IteratorError_swiginit(self, _pyAgrum.new_IteratorError(*args))
1497    __swig_destroy__ = _pyAgrum.delete_IteratorError
1498
1499# Register IteratorError in _pyAgrum:
1500_pyAgrum.IteratorError_swigregister(IteratorError)
1501
1502class UndefinedIteratorValue(IteratorError):
1503    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1504    __repr__ = _swig_repr
1505
1506    def __init__(self, *args):
1507        _pyAgrum.UndefinedIteratorValue_swiginit(self, _pyAgrum.new_UndefinedIteratorValue(*args))
1508    __swig_destroy__ = _pyAgrum.delete_UndefinedIteratorValue
1509
1510# Register UndefinedIteratorValue in _pyAgrum:
1511_pyAgrum.UndefinedIteratorValue_swigregister(UndefinedIteratorValue)
1512
1513class UndefinedIteratorKey(IteratorError):
1514    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1515    __repr__ = _swig_repr
1516
1517    def __init__(self, *args):
1518        _pyAgrum.UndefinedIteratorKey_swiginit(self, _pyAgrum.new_UndefinedIteratorKey(*args))
1519    __swig_destroy__ = _pyAgrum.delete_UndefinedIteratorKey
1520
1521# Register UndefinedIteratorKey in _pyAgrum:
1522_pyAgrum.UndefinedIteratorKey_swigregister(UndefinedIteratorKey)
1523
1524class NullElement(GumException):
1525    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1526    __repr__ = _swig_repr
1527
1528    def __init__(self, *args):
1529        _pyAgrum.NullElement_swiginit(self, _pyAgrum.new_NullElement(*args))
1530    __swig_destroy__ = _pyAgrum.delete_NullElement
1531
1532# Register NullElement in _pyAgrum:
1533_pyAgrum.NullElement_swigregister(NullElement)
1534
1535class UndefinedElement(GumException):
1536    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1537    __repr__ = _swig_repr
1538
1539    def __init__(self, *args):
1540        _pyAgrum.UndefinedElement_swiginit(self, _pyAgrum.new_UndefinedElement(*args))
1541    __swig_destroy__ = _pyAgrum.delete_UndefinedElement
1542
1543# Register UndefinedElement in _pyAgrum:
1544_pyAgrum.UndefinedElement_swigregister(UndefinedElement)
1545
1546class SizeError(GumException):
1547    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1548    __repr__ = _swig_repr
1549
1550    def __init__(self, *args):
1551        _pyAgrum.SizeError_swiginit(self, _pyAgrum.new_SizeError(*args))
1552    __swig_destroy__ = _pyAgrum.delete_SizeError
1553
1554# Register SizeError in _pyAgrum:
1555_pyAgrum.SizeError_swigregister(SizeError)
1556
1557class ArgumentError(GumException):
1558    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1559    __repr__ = _swig_repr
1560
1561    def __init__(self, *args):
1562        _pyAgrum.ArgumentError_swiginit(self, _pyAgrum.new_ArgumentError(*args))
1563    __swig_destroy__ = _pyAgrum.delete_ArgumentError
1564
1565# Register ArgumentError in _pyAgrum:
1566_pyAgrum.ArgumentError_swigregister(ArgumentError)
1567
1568class InvalidArgumentsNumber(ArgumentError):
1569    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1570    __repr__ = _swig_repr
1571
1572    def __init__(self, *args):
1573        _pyAgrum.InvalidArgumentsNumber_swiginit(self, _pyAgrum.new_InvalidArgumentsNumber(*args))
1574    __swig_destroy__ = _pyAgrum.delete_InvalidArgumentsNumber
1575
1576# Register InvalidArgumentsNumber in _pyAgrum:
1577_pyAgrum.InvalidArgumentsNumber_swigregister(InvalidArgumentsNumber)
1578
1579class InvalidArgument(ArgumentError):
1580    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1581    __repr__ = _swig_repr
1582
1583    def __init__(self, *args):
1584        _pyAgrum.InvalidArgument_swiginit(self, _pyAgrum.new_InvalidArgument(*args))
1585    __swig_destroy__ = _pyAgrum.delete_InvalidArgument
1586
1587# Register InvalidArgument in _pyAgrum:
1588_pyAgrum.InvalidArgument_swigregister(InvalidArgument)
1589
1590class IOError(GumException):
1591    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1592    __repr__ = _swig_repr
1593
1594    def __init__(self, *args):
1595        _pyAgrum.IOError_swiginit(self, _pyAgrum.new_IOError(*args))
1596    __swig_destroy__ = _pyAgrum.delete_IOError
1597
1598# Register IOError in _pyAgrum:
1599_pyAgrum.IOError_swigregister(IOError)
1600
1601class FormatNotFound(IOError):
1602    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1603    __repr__ = _swig_repr
1604
1605    def __init__(self, *args):
1606        _pyAgrum.FormatNotFound_swiginit(self, _pyAgrum.new_FormatNotFound(*args))
1607    __swig_destroy__ = _pyAgrum.delete_FormatNotFound
1608
1609# Register FormatNotFound in _pyAgrum:
1610_pyAgrum.FormatNotFound_swigregister(FormatNotFound)
1611
1612class OperationNotAllowed(GumException):
1613    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1614    __repr__ = _swig_repr
1615
1616    def __init__(self, *args):
1617        _pyAgrum.OperationNotAllowed_swiginit(self, _pyAgrum.new_OperationNotAllowed(*args))
1618    __swig_destroy__ = _pyAgrum.delete_OperationNotAllowed
1619
1620# Register OperationNotAllowed in _pyAgrum:
1621_pyAgrum.OperationNotAllowed_swigregister(OperationNotAllowed)
1622
1623class NotFound(GumException):
1624    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1625    __repr__ = _swig_repr
1626
1627    def __init__(self, *args):
1628        _pyAgrum.NotFound_swiginit(self, _pyAgrum.new_NotFound(*args))
1629    __swig_destroy__ = _pyAgrum.delete_NotFound
1630
1631# Register NotFound in _pyAgrum:
1632_pyAgrum.NotFound_swigregister(NotFound)
1633
1634class OutOfBounds(ArgumentError):
1635    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1636    __repr__ = _swig_repr
1637
1638    def __init__(self, *args):
1639        _pyAgrum.OutOfBounds_swiginit(self, _pyAgrum.new_OutOfBounds(*args))
1640    __swig_destroy__ = _pyAgrum.delete_OutOfBounds
1641
1642# Register OutOfBounds in _pyAgrum:
1643_pyAgrum.OutOfBounds_swigregister(OutOfBounds)
1644
1645class DuplicateElement(ArgumentError):
1646    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1647    __repr__ = _swig_repr
1648
1649    def __init__(self, *args):
1650        _pyAgrum.DuplicateElement_swiginit(self, _pyAgrum.new_DuplicateElement(*args))
1651    __swig_destroy__ = _pyAgrum.delete_DuplicateElement
1652
1653# Register DuplicateElement in _pyAgrum:
1654_pyAgrum.DuplicateElement_swigregister(DuplicateElement)
1655
1656class DuplicateLabel(ArgumentError):
1657    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1658    __repr__ = _swig_repr
1659
1660    def __init__(self, *args):
1661        _pyAgrum.DuplicateLabel_swiginit(self, _pyAgrum.new_DuplicateLabel(*args))
1662    __swig_destroy__ = _pyAgrum.delete_DuplicateLabel
1663
1664# Register DuplicateLabel in _pyAgrum:
1665_pyAgrum.DuplicateLabel_swigregister(DuplicateLabel)
1666
1667class GraphError(GumException):
1668    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1669    __repr__ = _swig_repr
1670
1671    def __init__(self, *args):
1672        _pyAgrum.GraphError_swiginit(self, _pyAgrum.new_GraphError(*args))
1673    __swig_destroy__ = _pyAgrum.delete_GraphError
1674
1675# Register GraphError in _pyAgrum:
1676_pyAgrum.GraphError_swigregister(GraphError)
1677
1678class NoNeighbour(GraphError):
1679    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1680    __repr__ = _swig_repr
1681
1682    def __init__(self, *args):
1683        _pyAgrum.NoNeighbour_swiginit(self, _pyAgrum.new_NoNeighbour(*args))
1684    __swig_destroy__ = _pyAgrum.delete_NoNeighbour
1685
1686# Register NoNeighbour in _pyAgrum:
1687_pyAgrum.NoNeighbour_swigregister(NoNeighbour)
1688
1689class NoParent(GraphError):
1690    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1691    __repr__ = _swig_repr
1692
1693    def __init__(self, *args):
1694        _pyAgrum.NoParent_swiginit(self, _pyAgrum.new_NoParent(*args))
1695    __swig_destroy__ = _pyAgrum.delete_NoParent
1696
1697# Register NoParent in _pyAgrum:
1698_pyAgrum.NoParent_swigregister(NoParent)
1699
1700class NoChild(GraphError):
1701    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1702    __repr__ = _swig_repr
1703
1704    def __init__(self, *args):
1705        _pyAgrum.NoChild_swiginit(self, _pyAgrum.new_NoChild(*args))
1706    __swig_destroy__ = _pyAgrum.delete_NoChild
1707
1708# Register NoChild in _pyAgrum:
1709_pyAgrum.NoChild_swigregister(NoChild)
1710
1711class InvalidEdge(GraphError):
1712    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1713    __repr__ = _swig_repr
1714
1715    def __init__(self, *args):
1716        _pyAgrum.InvalidEdge_swiginit(self, _pyAgrum.new_InvalidEdge(*args))
1717    __swig_destroy__ = _pyAgrum.delete_InvalidEdge
1718
1719# Register InvalidEdge in _pyAgrum:
1720_pyAgrum.InvalidEdge_swigregister(InvalidEdge)
1721
1722class InvalidArc(GraphError):
1723    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1724    __repr__ = _swig_repr
1725
1726    def __init__(self, *args):
1727        _pyAgrum.InvalidArc_swiginit(self, _pyAgrum.new_InvalidArc(*args))
1728    __swig_destroy__ = _pyAgrum.delete_InvalidArc
1729
1730# Register InvalidArc in _pyAgrum:
1731_pyAgrum.InvalidArc_swigregister(InvalidArc)
1732
1733class InvalidNode(GraphError):
1734    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1735    __repr__ = _swig_repr
1736
1737    def __init__(self, *args):
1738        _pyAgrum.InvalidNode_swiginit(self, _pyAgrum.new_InvalidNode(*args))
1739    __swig_destroy__ = _pyAgrum.delete_InvalidNode
1740
1741# Register InvalidNode in _pyAgrum:
1742_pyAgrum.InvalidNode_swigregister(InvalidNode)
1743
1744class DefaultInLabel(GraphError):
1745    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1746    __repr__ = _swig_repr
1747
1748    def __init__(self, *args):
1749        _pyAgrum.DefaultInLabel_swiginit(self, _pyAgrum.new_DefaultInLabel(*args))
1750    __swig_destroy__ = _pyAgrum.delete_DefaultInLabel
1751
1752# Register DefaultInLabel in _pyAgrum:
1753_pyAgrum.DefaultInLabel_swigregister(DefaultInLabel)
1754
1755class InvalidDirectedCycle(GraphError):
1756    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1757    __repr__ = _swig_repr
1758
1759    def __init__(self, *args):
1760        _pyAgrum.InvalidDirectedCycle_swiginit(self, _pyAgrum.new_InvalidDirectedCycle(*args))
1761    __swig_destroy__ = _pyAgrum.delete_InvalidDirectedCycle
1762
1763# Register InvalidDirectedCycle in _pyAgrum:
1764_pyAgrum.InvalidDirectedCycle_swigregister(InvalidDirectedCycle)
1765
1766class CPTError(GumException):
1767    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1768    __repr__ = _swig_repr
1769
1770    def __init__(self, *args):
1771        _pyAgrum.CPTError_swiginit(self, _pyAgrum.new_CPTError(*args))
1772    __swig_destroy__ = _pyAgrum.delete_CPTError
1773
1774# Register CPTError in _pyAgrum:
1775_pyAgrum.CPTError_swigregister(CPTError)
1776
1777class IncompatibleEvidence(GumException):
1778    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1779    __repr__ = _swig_repr
1780
1781    def __init__(self, *args):
1782        _pyAgrum.IncompatibleEvidence_swiginit(self, _pyAgrum.new_IncompatibleEvidence(*args))
1783    __swig_destroy__ = _pyAgrum.delete_IncompatibleEvidence
1784
1785# Register IncompatibleEvidence in _pyAgrum:
1786_pyAgrum.IncompatibleEvidence_swigregister(IncompatibleEvidence)
1787
1788class FactoryError(GumException):
1789    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1790    __repr__ = _swig_repr
1791
1792    def __init__(self, *args):
1793        _pyAgrum.FactoryError_swiginit(self, _pyAgrum.new_FactoryError(*args))
1794    __swig_destroy__ = _pyAgrum.delete_FactoryError
1795
1796# Register FactoryError in _pyAgrum:
1797_pyAgrum.FactoryError_swigregister(FactoryError)
1798
1799class FactoryInvalidState(FactoryError):
1800    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1801    __repr__ = _swig_repr
1802
1803    def __init__(self, *args):
1804        _pyAgrum.FactoryInvalidState_swiginit(self, _pyAgrum.new_FactoryInvalidState(*args))
1805    __swig_destroy__ = _pyAgrum.delete_FactoryInvalidState
1806
1807# Register FactoryInvalidState in _pyAgrum:
1808_pyAgrum.FactoryInvalidState_swigregister(FactoryInvalidState)
1809
1810class TypeError(FactoryError):
1811    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1812    __repr__ = _swig_repr
1813
1814    def __init__(self, *args):
1815        _pyAgrum.TypeError_swiginit(self, _pyAgrum.new_TypeError(*args))
1816    __swig_destroy__ = _pyAgrum.delete_TypeError
1817
1818# Register TypeError in _pyAgrum:
1819_pyAgrum.TypeError_swigregister(TypeError)
1820
1821class WrongClassElement(FactoryError):
1822    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1823    __repr__ = _swig_repr
1824
1825    def __init__(self, *args):
1826        _pyAgrum.WrongClassElement_swiginit(self, _pyAgrum.new_WrongClassElement(*args))
1827    __swig_destroy__ = _pyAgrum.delete_WrongClassElement
1828
1829# Register WrongClassElement in _pyAgrum:
1830_pyAgrum.WrongClassElement_swigregister(WrongClassElement)
1831
1832class PRMTypeError(FactoryError):
1833    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1834    __repr__ = _swig_repr
1835
1836    def __init__(self, *args):
1837        _pyAgrum.PRMTypeError_swiginit(self, _pyAgrum.new_PRMTypeError(*args))
1838    __swig_destroy__ = _pyAgrum.delete_PRMTypeError
1839
1840# Register PRMTypeError in _pyAgrum:
1841_pyAgrum.PRMTypeError_swigregister(PRMTypeError)
1842
1843class LearningError(GumException):
1844    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1845    __repr__ = _swig_repr
1846
1847    def __init__(self, *args):
1848        _pyAgrum.LearningError_swiginit(self, _pyAgrum.new_LearningError(*args))
1849    __swig_destroy__ = _pyAgrum.delete_LearningError
1850
1851# Register LearningError in _pyAgrum:
1852_pyAgrum.LearningError_swigregister(LearningError)
1853
1854class IncompatibleScoreApriori(LearningError):
1855    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1856    __repr__ = _swig_repr
1857
1858    def __init__(self, *args):
1859        _pyAgrum.IncompatibleScoreApriori_swiginit(self, _pyAgrum.new_IncompatibleScoreApriori(*args))
1860    __swig_destroy__ = _pyAgrum.delete_IncompatibleScoreApriori
1861
1862# Register IncompatibleScoreApriori in _pyAgrum:
1863_pyAgrum.IncompatibleScoreApriori_swigregister(IncompatibleScoreApriori)
1864
1865class PossiblyIncompatibleScoreApriori(LearningError):
1866    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1867    __repr__ = _swig_repr
1868
1869    def __init__(self, *args):
1870        _pyAgrum.PossiblyIncompatibleScoreApriori_swiginit(self, _pyAgrum.new_PossiblyIncompatibleScoreApriori(*args))
1871    __swig_destroy__ = _pyAgrum.delete_PossiblyIncompatibleScoreApriori
1872
1873# Register PossiblyIncompatibleScoreApriori in _pyAgrum:
1874_pyAgrum.PossiblyIncompatibleScoreApriori_swigregister(PossiblyIncompatibleScoreApriori)
1875
1876class DatabaseError(LearningError):
1877    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1878    __repr__ = _swig_repr
1879
1880    def __init__(self, *args):
1881        _pyAgrum.DatabaseError_swiginit(self, _pyAgrum.new_DatabaseError(*args))
1882    __swig_destroy__ = _pyAgrum.delete_DatabaseError
1883
1884# Register DatabaseError in _pyAgrum:
1885_pyAgrum.DatabaseError_swigregister(DatabaseError)
1886
1887class MissingVariableInDatabase(LearningError):
1888    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1889    __repr__ = _swig_repr
1890
1891    def __init__(self, *args):
1892        _pyAgrum.MissingVariableInDatabase_swiginit(self, _pyAgrum.new_MissingVariableInDatabase(*args))
1893    __swig_destroy__ = _pyAgrum.delete_MissingVariableInDatabase
1894
1895# Register MissingVariableInDatabase in _pyAgrum:
1896_pyAgrum.MissingVariableInDatabase_swigregister(MissingVariableInDatabase)
1897
1898class MissingValueInDatabase(LearningError):
1899    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1900    __repr__ = _swig_repr
1901
1902    def __init__(self, *args):
1903        _pyAgrum.MissingValueInDatabase_swiginit(self, _pyAgrum.new_MissingValueInDatabase(*args))
1904    __swig_destroy__ = _pyAgrum.delete_MissingValueInDatabase
1905
1906# Register MissingValueInDatabase in _pyAgrum:
1907_pyAgrum.MissingValueInDatabase_swigregister(MissingValueInDatabase)
1908
1909class UnknownLabelInDatabase(LearningError):
1910    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1911    __repr__ = _swig_repr
1912
1913    def __init__(self, *args):
1914        _pyAgrum.UnknownLabelInDatabase_swiginit(self, _pyAgrum.new_UnknownLabelInDatabase(*args))
1915    __swig_destroy__ = _pyAgrum.delete_UnknownLabelInDatabase
1916
1917# Register UnknownLabelInDatabase in _pyAgrum:
1918_pyAgrum.UnknownLabelInDatabase_swigregister(UnknownLabelInDatabase)
1919
1920class SyntaxError(IOError):
1921    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
1922    __repr__ = _swig_repr
1923
1924    def __init__(self, *args):
1925        _pyAgrum.SyntaxError_swiginit(self, _pyAgrum.new_SyntaxError(*args))
1926
1927    def col(self) -> int:
1928        r"""
1929
1930        Returns
1931        -------
1932        int
1933        	the indice of the colonne of the error
1934
1935        """
1936        return _pyAgrum.SyntaxError_col(self)
1937
1938    def line(self) -> int:
1939        r"""
1940
1941        Returns
1942        -------
1943        int
1944        	the indice of the line of the error
1945
1946        """
1947        return _pyAgrum.SyntaxError_line(self)
1948
1949    def filename(self) -> str:
1950        return _pyAgrum.SyntaxError_filename(self)
1951
1952    def what(self) -> str:
1953        return _pyAgrum.SyntaxError_what(self)
1954    __swig_destroy__ = _pyAgrum.delete_SyntaxError
1955
1956# Register SyntaxError in _pyAgrum:
1957_pyAgrum.SyntaxError_swigregister(SyntaxError)
1958
1959
1960def randomValue(max: int=2) -> int:
1961    r"""
1962
1963    Returns
1964    -------
1965    int
1966      a value randomly drawn (0 or 1)
1967
1968    """
1969    return _pyAgrum.randomValue(max)
1970
1971def randomProba() -> float:
1972    r"""
1973
1974    Returns
1975    -------
1976    float
1977        a random number between 0 and 1 included (i.e. a proba).
1978
1979    """
1980    return _pyAgrum.randomProba()
1981
1982def randomGeneratorSeed() -> int:
1983    r"""
1984
1985    Returns
1986    -------
1987    int
1988      a randomly generated seed
1989
1990    """
1991    return _pyAgrum.randomGeneratorSeed()
1992
1993def initRandom(seed: int=0) -> None:
1994    r"""
1995
1996    Initialize random generator seed.
1997
1998    Parameters
1999    ----------
2000    seed : int
2001      the seed used to initialize the random generator
2002
2003    """
2004    return _pyAgrum.initRandom(seed)
2005
2006def getRandomGenerator(seed: int=0) -> "std::default_random_engine":
2007    r"""
2008
2009    Returns
2010    -------
2011    tbw
2012      the random generator
2013
2014    """
2015    return _pyAgrum.getRandomGenerator(seed)
2016
2017def isOMP() -> bool:
2018    r"""
2019
2020    Returns
2021    -------
2022    bool
2023      True if OMP has been set at compilation, False otherwise
2024
2025    """
2026    return _pyAgrum.isOMP()
2027
2028def setNumberOfThreads(number: int) -> None:
2029    r"""
2030
2031    To aNone spare cycles (less then 100% CPU occupied), use more threads than logical processors (x2 is a good all-around value).
2032
2033    Returns
2034    -------
2035    number : int
2036      the number of threads to be used
2037
2038    """
2039    return _pyAgrum.setNumberOfThreads(number)
2040
2041def getMaxNumberOfThreads() -> int:
2042    r"""
2043
2044    Returns
2045    -------
2046    int
2047      the max number of threads
2048
2049    """
2050    return _pyAgrum.getMaxNumberOfThreads()
2051
2052def getThreadNumber() -> int:
2053    r"""
2054
2055    Returns
2056    -------
2057    int
2058      the number of thread
2059
2060    """
2061    return _pyAgrum.getThreadNumber()
2062
2063def getNumberOfRunningThreads() -> int:
2064    r"""
2065
2066    Returns
2067    -------
2068    int
2069      the number of running threads
2070
2071    """
2072    return _pyAgrum.getNumberOfRunningThreads()
2073
2074def getNumberOfLogicalProcessors() -> int:
2075    r"""
2076
2077    Returns
2078    -------
2079    int
2080      the number of logical processors
2081
2082    """
2083    return _pyAgrum.getNumberOfLogicalProcessors()
2084
2085def setNestedParallelism(value: bool) -> None:
2086    r"""
2087
2088    Parameters
2089    ----------
2090    value : bool
2091      True if nested parallelism should be activated
2092
2093    """
2094    return _pyAgrum.setNestedParallelism(value)
2095
2096def getNestedParallelism() -> bool:
2097    r"""
2098
2099    Returns
2100    -------
2101    bool
2102      True if nested parallelism is enabled
2103
2104    """
2105    return _pyAgrum.getNestedParallelism()
2106
2107def setDynamicThreadsNumber(value: bool) -> None:
2108    r"""
2109
2110    Parameters
2111    ----------
2112    value : bool
2113      True if the number of threads should be dynamic
2114
2115    """
2116    return _pyAgrum.setDynamicThreadsNumber(value)
2117
2118def getDynamicThreadsNumber() -> bool:
2119    r"""
2120
2121    Returns
2122    -------
2123    bool
2124      True if dynamic threads number is enabled
2125
2126    """
2127    return _pyAgrum.getDynamicThreadsNumber()
2128VarType_Discretized = _pyAgrum.VarType_Discretized
2129VarType_Labelized = _pyAgrum.VarType_Labelized
2130VarType_Integer = _pyAgrum.VarType_Integer
2131VarType_Range = _pyAgrum.VarType_Range
2132VarType_Continuous = _pyAgrum.VarType_Continuous
2133class Variable(object):
2134    r"""
2135
2136    Abstract class used by DiscreteVariable.
2137
2138    """
2139
2140    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
2141
2142    def __init__(self, *args, **kwargs):
2143        raise AttributeError("No constructor defined - class is abstract")
2144    __repr__ = _swig_repr
2145    __swig_destroy__ = _pyAgrum.delete_Variable
2146
2147    def clone(self) -> "pyAgrum.Variable":
2148        r"""
2149
2150        Copy factory
2151
2152        Returns
2153        -------
2154        pyAgrum.DiscreteVariable
2155        	a pointer on a new copy of this
2156
2157        """
2158        return _pyAgrum.Variable_clone(self)
2159
2160    def __eq__(self, aRV: "pyAgrum.Variable") -> bool:
2161        return _pyAgrum.Variable___eq__(self, aRV)
2162
2163    def __ne__(self, aRV: "pyAgrum.Variable") -> bool:
2164        return _pyAgrum.Variable___ne__(self, aRV)
2165
2166    def setName(self, theValue: str) -> None:
2167        r"""
2168
2169        sets the name of the variable.
2170
2171        Parameters
2172        ----------
2173        theValue : str
2174        	the new description of the variable
2175
2176        """
2177        return _pyAgrum.Variable_setName(self, theValue)
2178
2179    def name(self) -> str:
2180        r"""
2181
2182        Returns
2183        -------
2184        str
2185        	the name of the variable
2186
2187        """
2188        return _pyAgrum.Variable_name(self)
2189
2190    def setDescription(self, theValue: str) -> None:
2191        r"""
2192
2193        set the description of the variable.
2194
2195        Parameters
2196        ----------
2197        theValue : str
2198        	the new description of the variable
2199
2200        """
2201        return _pyAgrum.Variable_setDescription(self, theValue)
2202
2203    def description(self) -> str:
2204        r"""
2205
2206        Returns
2207        -------
2208        str
2209        	the description of the variable
2210
2211        """
2212        return _pyAgrum.Variable_description(self)
2213
2214    def varType(self) -> int:
2215        return _pyAgrum.Variable_varType(self)
2216
2217    def domain(self) -> str:
2218        return _pyAgrum.Variable_domain(self)
2219
2220# Register Variable in _pyAgrum:
2221_pyAgrum.Variable_swigregister(Variable)
2222
2223class DiscreteVariable(Variable):
2224    r"""
2225
2226    DiscreteVariable is the (abstract) base class for discrete random variables.
2227
2228    """
2229
2230    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
2231
2232    def __init__(self, *args, **kwargs):
2233        raise AttributeError("No constructor defined - class is abstract")
2234    __swig_destroy__ = _pyAgrum.delete_DiscreteVariable
2235
2236    def clone(self) -> "pyAgrum.DiscreteVariable":
2237        r"""
2238
2239        Returns
2240        -------
2241        pyAgrum.DiscreteVariable
2242        	a copy of the DiscreteVariable
2243
2244        """
2245        return _pyAgrum.DiscreteVariable_clone(self)
2246
2247    def empty(self) -> bool:
2248        r"""
2249
2250        Returns
2251        -------
2252        bool
2253        	True if the domain size < 2
2254
2255        """
2256        return _pyAgrum.DiscreteVariable_empty(self)
2257
2258    def domainSize(self) -> int:
2259        r"""
2260
2261        Returns
2262        -------
2263        int
2264        	the number of modalities in the variable domain
2265
2266        """
2267        return _pyAgrum.DiscreteVariable_domainSize(self)
2268
2269    def labels(self) -> List[str]:
2270        r"""
2271
2272        Returns
2273        -------
2274        tuple
2275        	a tuple containing the labels
2276
2277        """
2278        return _pyAgrum.DiscreteVariable_labels(self)
2279
2280    def numerical(self, indice: int) -> float:
2281        r"""
2282
2283        Parameters
2284        ----------
2285        indice : int
2286        	an index
2287
2288        Returns
2289        -------
2290        float
2291        	the numerical representation of the indice-th value
2292
2293        """
2294        return _pyAgrum.DiscreteVariable_numerical(self, indice)
2295
2296    def varType(self) -> int:
2297        r"""
2298
2299        returns the type of variable
2300
2301        Returns
2302        -------
2303        int :
2304        	the type of the variable, 0: DiscretizedVariable, 1: LabelizedVariable, 2: RangeVariable
2305
2306        """
2307        return _pyAgrum.DiscreteVariable_varType(self)
2308
2309    def __eq__(self, aRV: "pyAgrum.DiscreteVariable") -> bool:
2310        return _pyAgrum.DiscreteVariable___eq__(self, aRV)
2311
2312    def __ne__(self, aRV: "pyAgrum.DiscreteVariable") -> bool:
2313        return _pyAgrum.DiscreteVariable___ne__(self, aRV)
2314
2315    def index(self, label: str) -> int:
2316        r"""
2317
2318        Parameters
2319        ----------
2320        label : str
2321        	a label
2322
2323        Returns
2324        -------
2325        int
2326        	the indice of the label
2327
2328        """
2329        return _pyAgrum.DiscreteVariable_index(self, label)
2330
2331    def label(self, i: int) -> str:
2332        r"""
2333
2334        Parameters
2335        ----------
2336        i : int
2337        	the index of the label we wish to return
2338
2339        Returns
2340        -------
2341        str
2342        	the indice-th label
2343
2344        Raises
2345        ------
2346        pyAgrum.OutOfBound
2347        	If the variable does not contain the label
2348
2349        """
2350        return _pyAgrum.DiscreteVariable_label(self, i)
2351
2352    def toStringWithDescription(self) -> str:
2353        r"""
2354
2355        Returns
2356        -------
2357        str
2358        	a description of the variable
2359
2360        """
2361        return _pyAgrum.DiscreteVariable_toStringWithDescription(self)
2362
2363    def domain(self) -> str:
2364        r"""
2365
2366        Returns
2367        -------
2368        str
2369        	the domain of the variable
2370
2371        """
2372        return _pyAgrum.DiscreteVariable_domain(self)
2373
2374    def stype(self) -> str:
2375        return _pyAgrum.DiscreteVariable_stype(self)
2376
2377    def __repr__(self) -> str:
2378        return _pyAgrum.DiscreteVariable___repr__(self)
2379
2380    def __str__(self) -> str:
2381        return _pyAgrum.DiscreteVariable___str__(self)
2382
2383    def __hash__(self):
2384        return hash(self.name())
2385
2386    def __getitem__(self,label):   # adding the y() function here
2387        return self.index(label)
2388
2389
2390    def toLabelizedVar(self) -> "pyAgrum.LabelizedVariable":
2391        r"""
2392
2393        Returns
2394        -------
2395        pyAgrum.LabelizedVariable
2396        	the labelized variable
2397
2398        Raises
2399        ------
2400        pyAgrum.RuntimeError
2401        	If the variable is not a LabelizedVariable
2402
2403        """
2404        return _pyAgrum.DiscreteVariable_toLabelizedVar(self)
2405
2406    def toRangeVar(self) -> "pyAgrum.RangeVariable":
2407        r"""
2408
2409        Returns
2410        -------
2411        pyAgrum.RangeVariable
2412        	the range variable
2413
2414        Raises
2415        ------
2416        pyAgrum.RuntimeError
2417        	If the variable is not a RangeVariable
2418
2419        """
2420        return _pyAgrum.DiscreteVariable_toRangeVar(self)
2421
2422    def toIntegerVar(self) -> "pyAgrum.IntegerVariable":
2423        return _pyAgrum.DiscreteVariable_toIntegerVar(self)
2424
2425    def toDiscretizedVar(self) -> "pyAgrum.DiscretizedVariable":
2426        r"""
2427
2428        Returns
2429        -------
2430        pyAgrum.DiscretizedVariable
2431        	the discretized variable
2432
2433        Raises
2434        ------
2435        pyAgrum.RuntimeError
2436        	If the variable is not a DiscretizedVariable
2437
2438        """
2439        return _pyAgrum.DiscreteVariable_toDiscretizedVar(self)
2440
2441# Register DiscreteVariable in _pyAgrum:
2442_pyAgrum.DiscreteVariable_swigregister(DiscreteVariable)
2443
2444class LabelizedVariable(DiscreteVariable):
2445    r"""
2446
2447    LabelizedVariable is a discrete random variable with a customizable sequence of labels.
2448
2449    LabelizedVariable(aName, aDesc='', nbrLabel=2) -> LabelizedVariable
2450        Parameters:
2451            * **aName** (*str*) -- the name of the variable
2452            * **aDesc** (*str*) -- the (optional) description of the variable
2453            * **nbrLabel** (*int) -- the number of labels to create (2 by default)
2454
2455    LabelizedVariable(aLDRV) -> LabelizedVariable
2456        Parameters:
2457            * **aLDRV** (*pyAgrum.LabelizedVariable*) -- The pyAgrum.LabelizedVariable that will be copied
2458
2459    Examples
2460    --------
2461    >>> import pyAgrum as gum
2462    >>> # creating a variable with 3 labels : '0', '1' and '2'
2463    >>> va=gum.LabelizedVariable('a','a labelized variable',3)
2464    >>> print(va)
2465    a:Labelized(<0,1,2>)
2466    >>> va.addLabel('foo')
2467    ("pyAgrum.LabelizedVariable"@0x7fc4c840dd90) a:Labelized(<0,1,2,foo>)
2468    >>> va.changeLabel(1,'bar')
2469    >>> print(va)
2470    a:Labelized(<0,bar,2,foo>)
2471    >>> vb=gum.LabelizedVariable('b','b',0).addLabel('A').addLabel('B').addLabel('C')
2472    >>> print(vb)
2473    b:Labelized(<A,B,C>)
2474    >>> vb.labels()
2475    ('A', 'B', 'C')
2476    >>> vb.isLabel('E')
2477    False
2478    >>> vb.label(2)
2479    'C'
2480    >>> vc=gum.LabelizedVariable('b','b',['one','two','three'])
2481    >>> vc
2482    ("pyAgrum.LabelizedVariable"@0x7fc4c840c130) b:Labelized(<one,two,three>)
2483
2484    """
2485
2486    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
2487
2488    def __init__(self, *args):
2489        _pyAgrum.LabelizedVariable_swiginit(self, _pyAgrum.new_LabelizedVariable(*args))
2490    __swig_destroy__ = _pyAgrum.delete_LabelizedVariable
2491
2492    def clone(self) -> "pyAgrum.LabelizedVariable":
2493        r"""
2494
2495        Returns
2496        -------
2497        pyAgrum.LabelizedVariable
2498        	a copy of the LabelizedVariable
2499
2500        """
2501        return _pyAgrum.LabelizedVariable_clone(self)
2502
2503    def index(self, label: str) -> int:
2504        r"""
2505
2506        Parameters
2507        ----------
2508        label : str
2509        	a label
2510
2511        Returns
2512        -------
2513        int
2514        	the indice of the label
2515
2516        """
2517        return _pyAgrum.LabelizedVariable_index(self, label)
2518
2519    def isLabel(self, aLabel: str) -> bool:
2520        r"""
2521
2522        Indicates whether the variable already has the label passed in argument
2523
2524        Parameters
2525        ----------
2526        aLabel : str
2527        	the label to be tested
2528
2529        Returns
2530        -------
2531        bool
2532        	True if the label already exists
2533
2534        """
2535        return _pyAgrum.LabelizedVariable_isLabel(self, aLabel)
2536
2537    def addLabel(self,*args):
2538        """
2539        Add a label with a new index (we assume that we will NEVER remove a label).
2540
2541        Parameters
2542        ----------
2543        aLabel : str
2544            the label to be added to the labelized variable
2545
2546        Returns
2547        -------
2548        pyAgrum.LabelizedVariable
2549            the labelized variable
2550
2551        Raises
2552        ------
2553        gum.DuplicateElement
2554            If the variable already contains the label
2555        """
2556        _pyAgrum.LabelizedVariable_addLabel(self,*args)
2557        return self
2558
2559
2560
2561    def changeLabel(self, pos: int, aLabel: str) -> None:
2562        r"""
2563
2564        Change the label at the specified index
2565
2566        Parameters
2567        ----------
2568        pos : int
2569        	the index of the label to be changed
2570        aLabel : str
2571        	the label to be added to the labelized variable
2572
2573        Raises
2574        ------
2575        pyAgrum.DuplicatedElement
2576          If the variable already contains the new label
2577        pyAgrum.OutOfBounds
2578          If the index is greater than the size of the variable
2579
2580        """
2581        return _pyAgrum.LabelizedVariable_changeLabel(self, pos, aLabel)
2582
2583    def eraseLabels(self) -> None:
2584        r"""
2585
2586        Erase all the labels from the variable.
2587
2588        """
2589        return _pyAgrum.LabelizedVariable_eraseLabels(self)
2590
2591    def label(self, i: int) -> str:
2592        r"""
2593
2594        Parameters
2595        ----------
2596        i : int
2597        	the index of the label we wish to return
2598
2599        Returns
2600        -------
2601        str
2602        	the indice-th label
2603
2604        Raises
2605        ------
2606        pyAgrum.OutOfBound
2607        	If the variable does not contain the label
2608
2609        """
2610        return _pyAgrum.LabelizedVariable_label(self, i)
2611
2612    def posLabel(self, label: str) -> int:
2613        return _pyAgrum.LabelizedVariable_posLabel(self, label)
2614
2615    def numerical(self, index: int) -> float:
2616        r"""
2617
2618        Parameters
2619        ----------
2620        indice : int
2621        	an index
2622
2623        Returns
2624        -------
2625        float
2626        	the numerical representation of the indice-th value
2627
2628        """
2629        return _pyAgrum.LabelizedVariable_numerical(self, index)
2630
2631    def domainSize(self) -> int:
2632        r"""
2633
2634        Returns
2635        -------
2636        int
2637        	the number of modalities in the variable domain
2638
2639        """
2640        return _pyAgrum.LabelizedVariable_domainSize(self)
2641
2642    def varType(self) -> int:
2643        r"""
2644
2645        returns the type of variable
2646
2647        Returns
2648        -------
2649        int :
2650        	the type of the variable, 0: DiscretizedVariable, 1: LabelizedVariable, 2: RangeVariable
2651
2652        """
2653        return _pyAgrum.LabelizedVariable_varType(self)
2654
2655    def domain(self) -> str:
2656        r"""
2657
2658        Returns
2659        -------
2660        str
2661            the domain of the variable as a string
2662
2663        """
2664        return _pyAgrum.LabelizedVariable_domain(self)
2665
2666    def stype(self) -> str:
2667        return _pyAgrum.LabelizedVariable_stype(self)
2668
2669    def __repr__(self) -> str:
2670        return _pyAgrum.LabelizedVariable___repr__(self)
2671
2672    def __str__(self) -> str:
2673        return _pyAgrum.LabelizedVariable___str__(self)
2674
2675# Register LabelizedVariable in _pyAgrum:
2676_pyAgrum.LabelizedVariable_swigregister(LabelizedVariable)
2677
2678class RangeVariable(DiscreteVariable):
2679    r"""
2680
2681    RangeVariable represents a variable with a range of integers as domain.
2682
2683    RangeVariable(aName, aDesc,minVal, maxVal) -> RangeVariable
2684        Parameters:
2685            * **aName** (*str*) -- the name of the variable
2686            * **aDesc** (*str*) -- the description of the variable
2687            * **minVal** (*int) -- the minimal integer of the interval
2688            * **maxVal** (*int) -- the maximal integer of the interval
2689
2690    RangeVariable(aName, aDesc='') -> RangeVariable
2691        Parameters:
2692            * **aName** (*str*) -- the name of the variable
2693            * **aDesc** (*str*) -- the description of the variable
2694
2695        By default ``minVal=0`` and ``maxVal=1``
2696
2697    RangeVariable(aRV) -> RangeVariable
2698        Parameters:
2699            * **aDV** (*RangeVariable*) -- the pyAgrum.RangeVariable that will be copied
2700
2701    Examples
2702    --------
2703    >>> import pyAgrum as gum
2704    >>> vI=gum.RangeVariable('I','I in [4,10]',4,10)
2705    >>> print(vI)
2706    I:Range([4,10])
2707    >>> vI.maxVal()
2708    10
2709    >>> vI.belongs(1)
2710    False
2711    >>> # where is the value 5 ?
2712    >>> vI.index('5')
2713    1
2714    >>> vI.labels()
2715    ('4', '5', '6', '7', '8', '9', '10')
2716
2717    """
2718
2719    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
2720
2721    def __init__(self, *args):
2722        _pyAgrum.RangeVariable_swiginit(self, _pyAgrum.new_RangeVariable(*args))
2723    __swig_destroy__ = _pyAgrum.delete_RangeVariable
2724
2725    def clone(self) -> "pyAgrum.RangeVariable":
2726        r"""
2727
2728        Returns
2729        -------
2730        pyAgrum.RangeVariable
2731        	a copy of the RangeVariable
2732
2733        """
2734        return _pyAgrum.RangeVariable_clone(self)
2735
2736    def domainSize(self) -> int:
2737        r"""
2738
2739        Returns
2740        -------
2741        int
2742        	the number of modalities in the variable domain
2743
2744        """
2745        return _pyAgrum.RangeVariable_domainSize(self)
2746
2747    def varType(self) -> int:
2748        r"""
2749
2750        returns the type of variable
2751
2752        Returns
2753        -------
2754        int :
2755        	the type of the variable, 0: DiscretizedVariable, 1: LabelizedVariable, 2: RangeVariable
2756
2757        """
2758        return _pyAgrum.RangeVariable_varType(self)
2759
2760    def label(self, index: int) -> str:
2761        r"""
2762
2763        Parameters
2764        ----------
2765        indice : int
2766          the index of the label we wish to return
2767
2768        Returns
2769        -------
2770        str
2771          the indice-th label
2772
2773        Raises
2774        ------
2775        pyAgrum.OutOfBound
2776          If the variable does not contain the label
2777
2778        """
2779        return _pyAgrum.RangeVariable_label(self, index)
2780
2781    def numerical(self, index: int) -> float:
2782        r"""
2783
2784        Parameters
2785        ----------
2786        indice : int
2787        	an index
2788
2789        Returns
2790        -------
2791        float
2792        	the numerical representation of the indice-th value
2793
2794        """
2795        return _pyAgrum.RangeVariable_numerical(self, index)
2796
2797    def minVal(self) -> int:
2798        r"""
2799
2800        Returns
2801        -------
2802        int :
2803          the lower bound of the variable
2804
2805        """
2806        return _pyAgrum.RangeVariable_minVal(self)
2807
2808    def setMinVal(self, minVal: int) -> None:
2809        r"""
2810
2811        Set a new value of the lower bound
2812
2813        Parameters
2814        ----------
2815        minVal : int
2816          The new value of the lower bound
2817
2818        Warnings
2819        --------
2820        An error should be raised if the value is higher than the upper bound.
2821
2822        """
2823        return _pyAgrum.RangeVariable_setMinVal(self, minVal)
2824
2825    def maxVal(self) -> int:
2826        r"""
2827
2828        Returns
2829        -------
2830        int :
2831          the upper bound of the variable.
2832
2833        """
2834        return _pyAgrum.RangeVariable_maxVal(self)
2835
2836    def setMaxVal(self, maxVal: int) -> None:
2837        r"""
2838
2839        Set a new value of the upper bound
2840
2841        Parameters
2842        ----------
2843        maxVal : int
2844          The new value of the upper bound
2845
2846        Warnings
2847        --------
2848        An error should be raised if the value is lower than the lower bound.
2849
2850        """
2851        return _pyAgrum.RangeVariable_setMaxVal(self, maxVal)
2852
2853    def belongs(self, val: int) -> bool:
2854        r"""
2855
2856        Parameters
2857        ----------
2858        val : int
2859          the value to be tested
2860
2861        Returns
2862        -------
2863        bool:
2864          True if the value in parameters belongs to the variable's interval.
2865
2866        """
2867        return _pyAgrum.RangeVariable_belongs(self, val)
2868
2869    def index(self, arg2: str) -> int:
2870        r"""
2871
2872        Parameters
2873        ----------
2874        arg2 : str
2875          a label
2876
2877        Returns
2878        -------
2879        int
2880          the indice of the label
2881
2882        """
2883        return _pyAgrum.RangeVariable_index(self, arg2)
2884
2885    def domain(self) -> str:
2886        r"""
2887
2888        Returns
2889        -------
2890        str
2891        	the domain of the variable
2892
2893        """
2894        return _pyAgrum.RangeVariable_domain(self)
2895
2896    def stype(self) -> str:
2897        return _pyAgrum.RangeVariable_stype(self)
2898
2899    def __repr__(self) -> str:
2900        return _pyAgrum.RangeVariable___repr__(self)
2901
2902    def __str__(self) -> str:
2903        return _pyAgrum.RangeVariable___str__(self)
2904
2905# Register RangeVariable in _pyAgrum:
2906_pyAgrum.RangeVariable_swigregister(RangeVariable)
2907
2908class IntegerVariable(DiscreteVariable):
2909    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
2910
2911    def __init__(self, *args):
2912        _pyAgrum.IntegerVariable_swiginit(self, _pyAgrum.new_IntegerVariable(*args))
2913
2914    def clone(self) -> "pyAgrum.IntegerVariable":
2915        r"""
2916
2917        Returns
2918        -------
2919        pyAgrum.DiscreteVariable
2920        	a copy of the DiscreteVariable
2921
2922        """
2923        return _pyAgrum.IntegerVariable_clone(self)
2924    __swig_destroy__ = _pyAgrum.delete_IntegerVariable
2925
2926    def __eq__(self, var: "pyAgrum.Variable") -> bool:
2927        return _pyAgrum.IntegerVariable___eq__(self, var)
2928
2929    def __ne__(self, var: "pyAgrum.Variable") -> bool:
2930        return _pyAgrum.IntegerVariable___ne__(self, var)
2931
2932    def domainSize(self) -> int:
2933        r"""
2934
2935        Returns
2936        -------
2937        int
2938        	the number of modalities in the variable domain
2939
2940        """
2941        return _pyAgrum.IntegerVariable_domainSize(self)
2942
2943    def varType(self) -> int:
2944        r"""
2945
2946        returns the type of variable
2947
2948        Returns
2949        -------
2950        int :
2951        	the type of the variable, 0: DiscretizedVariable, 1: LabelizedVariable, 2: RangeVariable
2952
2953        """
2954        return _pyAgrum.IntegerVariable_varType(self)
2955
2956    def index(self, label: str) -> int:
2957        r"""
2958
2959        Parameters
2960        ----------
2961        label : str
2962        	a label
2963
2964        Returns
2965        -------
2966        int
2967        	the indice of the label
2968
2969        """
2970        return _pyAgrum.IntegerVariable_index(self, label)
2971
2972    def label(self, index: int) -> str:
2973        r"""
2974
2975        Parameters
2976        ----------
2977        i : int
2978        	the index of the label we wish to return
2979
2980        Returns
2981        -------
2982        str
2983        	the indice-th label
2984
2985        Raises
2986        ------
2987        pyAgrum.OutOfBound
2988        	If the variable does not contain the label
2989
2990        """
2991        return _pyAgrum.IntegerVariable_label(self, index)
2992
2993    def numerical(self, index: int) -> float:
2994        r"""
2995
2996        Parameters
2997        ----------
2998        indice : int
2999        	an index
3000
3001        Returns
3002        -------
3003        float
3004        	the numerical representation of the indice-th value
3005
3006        """
3007        return _pyAgrum.IntegerVariable_numerical(self, index)
3008
3009    def domain(self) -> str:
3010        r"""
3011
3012        Returns
3013        -------
3014        str
3015        	the domain of the variable
3016
3017        """
3018        return _pyAgrum.IntegerVariable_domain(self)
3019
3020    def stype(self) -> str:
3021        return _pyAgrum.IntegerVariable_stype(self)
3022
3023    def integerDomain(self) -> List[int]:
3024        return _pyAgrum.IntegerVariable_integerDomain(self)
3025
3026    def addValue(self, value: int) -> "pyAgrum.IntegerVariable":
3027        return _pyAgrum.IntegerVariable_addValue(self, value)
3028
3029    def changeValue(self, old_value: int, new_value: int) -> None:
3030        return _pyAgrum.IntegerVariable_changeValue(self, old_value, new_value)
3031
3032    def eraseValue(self, value: int) -> None:
3033        return _pyAgrum.IntegerVariable_eraseValue(self, value)
3034
3035    def eraseValues(self) -> None:
3036        return _pyAgrum.IntegerVariable_eraseValues(self)
3037
3038    def __repr__(self) -> str:
3039        return _pyAgrum.IntegerVariable___repr__(self)
3040
3041    def __str__(self) -> str:
3042        return _pyAgrum.IntegerVariable___str__(self)
3043
3044# Register IntegerVariable in _pyAgrum:
3045_pyAgrum.IntegerVariable_swigregister(IntegerVariable)
3046
3047class IDiscretizedVariable(DiscreteVariable):
3048    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
3049
3050    def __init__(self, *args, **kwargs):
3051        raise AttributeError("No constructor defined - class is abstract")
3052    __repr__ = _swig_repr
3053    __swig_destroy__ = _pyAgrum.delete_IDiscretizedVariable
3054
3055    def clone(self) -> "pyAgrum.DiscretizedVariable":
3056        r"""
3057
3058        Returns
3059        -------
3060        pyAgrum.DiscreteVariable
3061        	a copy of the DiscreteVariable
3062
3063        """
3064        return _pyAgrum.IDiscretizedVariable_clone(self)
3065
3066# Register IDiscretizedVariable in _pyAgrum:
3067_pyAgrum.IDiscretizedVariable_swigregister(IDiscretizedVariable)
3068
3069class Edge(object):
3070    r"""
3071
3072    pyAgrum.Edge is the representation of an arc between two nodes represented by int : the first and the second.
3073
3074    Edge(aN1,aN2) -> Edge
3075        Parameters:
3076            * **aN1** (*int) -- the nodeId of the first node
3077            * **aN2** (*int) -- the nodeId of the secondnode
3078
3079    Edge(src) -> Edge
3080        Parameters:
3081            * **src** (*yAgrum.Edge*) -- the Edge to copy
3082
3083    """
3084
3085    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
3086    __repr__ = _swig_repr
3087
3088    def __init__(self, *args):
3089        _pyAgrum.Edge_swiginit(self, _pyAgrum.new_Edge(*args))
3090    __swig_destroy__ = _pyAgrum.delete_Edge
3091
3092    def other(self, id: int) -> int:
3093        r"""
3094
3095        Parameters
3096        ----------
3097        id : int
3098          the nodeId of one of the nodes of the Edge
3099
3100
3101        Returns
3102        ------
3103        int
3104          the nodeId of the other node
3105
3106        """
3107        return _pyAgrum.Edge_other(self, id)
3108
3109    def first(self) -> int:
3110        r"""
3111
3112        Returns
3113        ------
3114        int
3115          the nodeId of the first node of the arc (the tail)
3116
3117        """
3118        return _pyAgrum.Edge_first(self)
3119
3120    def second(self) -> int:
3121        r"""
3122
3123        Returns
3124        ------
3125        int
3126          the nodeId of the second node of the arc (the head)
3127
3128        """
3129        return _pyAgrum.Edge_second(self)
3130
3131    def __eq__(self, src: "pyAgrum.Edge") -> bool:
3132        return _pyAgrum.Edge___eq__(self, src)
3133
3134    def __ne__(self, src: "pyAgrum.Edge") -> bool:
3135        return _pyAgrum.Edge___ne__(self, src)
3136
3137# Register Edge in _pyAgrum:
3138_pyAgrum.Edge_swigregister(Edge)
3139
3140class Arc(object):
3141    r"""
3142
3143    pyAgrum.Arc is the representation of an arc between two nodes represented by int : the head and the tail.
3144
3145    Arc(tail, head) -> Arc
3146        Parameters:
3147            * **tail** (*int) -- the tail
3148            * **head** (*int) -- the head
3149
3150    Arc(src) -> Arc
3151        Parameters:
3152            * **src** (*Arc*) -- the pyAgrum.Arc to copy
3153
3154    """
3155
3156    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
3157    __repr__ = _swig_repr
3158
3159    def __init__(self, *args):
3160        _pyAgrum.Arc_swiginit(self, _pyAgrum.new_Arc(*args))
3161    __swig_destroy__ = _pyAgrum.delete_Arc
3162
3163    def tail(self) -> int:
3164        r"""
3165
3166        Returns
3167        -------
3168        int
3169          the id of the tail node
3170
3171        """
3172        return _pyAgrum.Arc_tail(self)
3173
3174    def head(self) -> int:
3175        r"""
3176
3177        Returns
3178        ------
3179        int
3180          the id of the head node
3181
3182        """
3183        return _pyAgrum.Arc_head(self)
3184
3185    def other(self, id: int) -> int:
3186        r"""
3187
3188        Parameters
3189        ----------
3190        id : int
3191          the nodeId of the head or the tail
3192
3193
3194        Returns
3195        -------
3196        int
3197          the nodeId of the other node
3198
3199        """
3200        return _pyAgrum.Arc_other(self, id)
3201
3202    def first(self) -> int:
3203        r"""
3204
3205        Returns
3206        -------
3207        int
3208          the nodeId of the first node of the arc (the tail)
3209
3210        """
3211        return _pyAgrum.Arc_first(self)
3212
3213    def second(self) -> int:
3214        r"""
3215
3216        Returns
3217        -------
3218        int
3219          the nodeId of the second node of the arc (the head)
3220
3221        """
3222        return _pyAgrum.Arc_second(self)
3223
3224    def __eq__(self, src: "pyAgrum.Arc") -> bool:
3225        return _pyAgrum.Arc___eq__(self, src)
3226
3227    def __ne__(self, src: "pyAgrum.Arc") -> bool:
3228        return _pyAgrum.Arc___ne__(self, src)
3229
3230# Register Arc in _pyAgrum:
3231_pyAgrum.Arc_swigregister(Arc)
3232
3233class UndiGraph(object):
3234    r"""
3235
3236    UndiGraph represents an Undirected Graph.
3237
3238    UndiGraph() -> UndiGraph
3239        default constructor
3240
3241    UndiGraph(src) -> UndiGraph
3242        Parameters!
3243            * **src** (*UndiGraph*) -- the pyAgrum.UndiGraph to copy
3244
3245
3246    """
3247
3248    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
3249
3250    def __init__(self, *args):
3251        _pyAgrum.UndiGraph_swiginit(self, _pyAgrum.new_UndiGraph(*args))
3252    __swig_destroy__ = _pyAgrum.delete_UndiGraph
3253
3254    def __eq__(self, g: "pyAgrum.UndiGraph") -> bool:
3255        return _pyAgrum.UndiGraph___eq__(self, g)
3256
3257    def __ne__(self, g: "pyAgrum.UndiGraph") -> bool:
3258        return _pyAgrum.UndiGraph___ne__(self, g)
3259
3260    def eraseNode(self, id: int) -> None:
3261        r"""
3262
3263        Erase the node and all the adjacent edges.
3264
3265        Parameters
3266        ----------
3267        id : int
3268          the id of the node
3269
3270        """
3271        return _pyAgrum.UndiGraph_eraseNode(self, id)
3272
3273    def clear(self) -> None:
3274        r"""
3275
3276        Remove all the nodes and edges from the graph.
3277
3278        """
3279        return _pyAgrum.UndiGraph_clear(self)
3280
3281    def toDot(self) -> str:
3282        r"""
3283
3284        Returns
3285        -------
3286        str
3287            a friendly display of the graph in DOT format
3288
3289        """
3290        return _pyAgrum.UndiGraph_toDot(self)
3291
3292    def hasUndirectedCycle(self) -> bool:
3293        r"""
3294
3295        Checks whether the graph contains cycles.
3296
3297        Returns
3298        -------
3299        bool
3300            True if the graph contains a cycle
3301
3302        """
3303        return _pyAgrum.UndiGraph_hasUndirectedCycle(self)
3304
3305    def partialUndiGraph(self, nodes: List[int]) -> "pyAgrum.UndiGraph":
3306        r"""
3307
3308        Parameters
3309        ----------
3310        nodesSet : Set
3311            The set of nodes composing the partial graph
3312
3313        Returns
3314        -------
3315        pyAgrum.UndiGraph
3316            The partial graph formed by the nodes given in parameter
3317
3318        """
3319        return _pyAgrum.UndiGraph_partialUndiGraph(self, nodes)
3320
3321    def nodes2ConnectedComponent(self) -> Dict[int,int]:
3322        return _pyAgrum.UndiGraph_nodes2ConnectedComponent(self)
3323
3324    def __repr__(self) -> str:
3325        return _pyAgrum.UndiGraph___repr__(self)
3326
3327    def __str__(self) -> str:
3328        return _pyAgrum.UndiGraph___str__(self)
3329
3330    def nodes(self) -> object:
3331        r"""
3332
3333        Returns
3334        -------
3335        set
3336            the set of ids
3337
3338        """
3339        return _pyAgrum.UndiGraph_nodes(self)
3340
3341    def connectedComponents(self):
3342      """ connected components from a graph/BN
3343
3344      Compute the connected components of a pyAgrum's graph or Bayesian Network
3345      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
3346
3347      The firstly visited node for each component is called a 'root' and is used as a key for the component.
3348      This root has been arbitrarily chosen during the algorithm.
3349
3350      Returns
3351      -------
3352      dict(int,Set[int])
3353        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
3354
3355      """
3356      nodes=self.nodes()
3357      connected_components=dict()
3358
3359      def parcours(node,orig):
3360          cc={node}
3361          nodes.discard(node)
3362          if hasattr(self,'children'):
3363              for chi in self.children(node):
3364                  if chi!=orig:
3365                      if chi in nodes:
3366                          cc|=parcours(chi,node)
3367
3368          if hasattr(self,'parents'):
3369              for par in self.parents(node):
3370                  if par!=orig:
3371                      if par in nodes:
3372                          cc|=parcours(par,node)
3373
3374          if hasattr(self,'neighbours'):
3375              for nei in self.neighbours(node):
3376                  if nei!=orig:
3377                      if nei in nodes:
3378                          cc|=parcours(nei,node)
3379          return cc
3380
3381      while (len(nodes)>0):
3382          root=nodes.pop()
3383          connected_components[root]=parcours(root,None)
3384      return connected_components
3385
3386
3387    def addNodes(self, n: int) -> object:
3388        r"""
3389
3390        Add n nodes.
3391
3392        Parameters
3393        ----------
3394        n : int
3395          the number of nodes to add.
3396
3397        Returns
3398        -------
3399        Set of int
3400          the new ids
3401
3402        """
3403        return _pyAgrum.UndiGraph_addNodes(self, n)
3404
3405    def edges(self) -> object:
3406        r"""
3407
3408        Returns
3409        -------
3410        List
3411          the list of the edges
3412
3413        """
3414        return _pyAgrum.UndiGraph_edges(self)
3415
3416    def neighbours(self, id: int) -> object:
3417        r"""
3418
3419        Parameters
3420        ----------
3421        id : int
3422            the id of the checked node
3423
3424        Returns
3425        -------
3426        Set
3427            The set of edges adjacent to the given node
3428
3429        """
3430        return _pyAgrum.UndiGraph_neighbours(self, id)
3431
3432    def addNode(self) -> int:
3433        r"""
3434
3435        Returns
3436        -------
3437        int
3438          the new NodeId
3439
3440        """
3441        return _pyAgrum.UndiGraph_addNode(self)
3442
3443    def addNodeWithId(self, id: int) -> None:
3444        r"""
3445
3446        Add a node by choosing a new NodeId.
3447
3448        Parameters
3449        ----------
3450        id : int
3451          The id of the new node
3452
3453        Raises
3454        ------
3455        pyAgrum.DuplicateElement
3456          If the given id is already used
3457
3458        """
3459        return _pyAgrum.UndiGraph_addNodeWithId(self, id)
3460
3461    def existsNode(self, id: int) -> bool:
3462        r"""
3463
3464        Check if a node with a certain id exists in the graph.
3465
3466        Parameters
3467        ----------
3468        id : int
3469            the checked id
3470
3471        Returns
3472        -------
3473        bool
3474            True if the node exists
3475
3476        """
3477        return _pyAgrum.UndiGraph_existsNode(self, id)
3478
3479    def size(self) -> int:
3480        r"""
3481
3482        Returns
3483        -------
3484        int
3485            the number of nodes in the graph
3486
3487        """
3488        return _pyAgrum.UndiGraph_size(self)
3489
3490    def empty(self) -> bool:
3491        r"""
3492
3493        Check if the graph is empty.
3494
3495        Returns
3496        -------
3497        bool
3498            True if the graph is empty
3499
3500        """
3501        return _pyAgrum.UndiGraph_empty(self)
3502
3503    def addEdge(self, *args) -> None:
3504        r"""
3505
3506        Insert a new edge into the graph.
3507
3508        Parameters
3509        ----------
3510        n1 : int
3511          the id of one node of the new inserted edge
3512        n2 : int
3513          the id of the other node of the new inserted edge
3514
3515        Raises
3516        ------
3517        pyAgrum.InvalidNode
3518          If n1 or n2 does not belong to the graph nodes.
3519
3520        """
3521        return _pyAgrum.UndiGraph_addEdge(self, *args)
3522
3523    def eraseEdge(self, n1: int, n2: int) -> None:
3524        r"""
3525
3526        Erase the edge between n1 and n2.
3527
3528        Parameters
3529        ----------
3530        n1 : int
3531          the id of the tail node
3532        n2 : int
3533          the id of the head node
3534
3535        """
3536        return _pyAgrum.UndiGraph_eraseEdge(self, n1, n2)
3537
3538    def existsEdge(self, n1: int, n2: int) -> bool:
3539        r"""
3540
3541        Check if an edge exists bewteen n1 and n2.
3542
3543        Parameters
3544        ----------
3545        n1 : int
3546          the id of one extremity of the edge
3547        n2 : int
3548          the id of the other extremity if tge edge
3549
3550        Returns
3551        -------
3552        bool
3553            True if the arc exists
3554
3555        """
3556        return _pyAgrum.UndiGraph_existsEdge(self, n1, n2)
3557
3558    def sizeEdges(self) -> int:
3559        r"""
3560
3561        Returns
3562        -------
3563        int
3564            the number of edges in the graph
3565
3566        """
3567        return _pyAgrum.UndiGraph_sizeEdges(self)
3568
3569    def emptyEdges(self) -> bool:
3570        r"""
3571
3572        Check if the graph doesn't contains edges.
3573
3574        Returns
3575        -------
3576        bool
3577            True if the graph doesn't contains edges
3578
3579        """
3580        return _pyAgrum.UndiGraph_emptyEdges(self)
3581
3582    def eraseNeighbours(self, n: int) -> None:
3583        r"""
3584
3585        Erase all the edges adjacent to a given node.
3586
3587        Parameters
3588        ----------
3589        n : int
3590          the id of the node
3591
3592        """
3593        return _pyAgrum.UndiGraph_eraseNeighbours(self, n)
3594
3595# Register UndiGraph in _pyAgrum:
3596_pyAgrum.UndiGraph_swigregister(UndiGraph)
3597
3598class DiGraph(object):
3599    r"""
3600
3601    DiGraph represents a Directed Graph.
3602
3603    DiGraph() -> DiGraph
3604        default constructor
3605
3606    DiGraph(src) -> DiGraph
3607        Parameters:
3608            * **src** (*pyAgrum.DiGraph*) -- the digraph to copy
3609
3610    """
3611
3612    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
3613
3614    def __init__(self, *args):
3615        _pyAgrum.DiGraph_swiginit(self, _pyAgrum.new_DiGraph(*args))
3616    __swig_destroy__ = _pyAgrum.delete_DiGraph
3617
3618    def __eq__(self, g: "DiGraph") -> bool:
3619        return _pyAgrum.DiGraph___eq__(self, g)
3620
3621    def __ne__(self, g: "DiGraph") -> bool:
3622        return _pyAgrum.DiGraph___ne__(self, g)
3623
3624    def eraseNode(self, id: int) -> None:
3625        r"""
3626
3627        Erase the node and all the related arcs.
3628
3629        Parameters
3630        ----------
3631        id : int
3632        	the id of the node
3633
3634        """
3635        return _pyAgrum.DiGraph_eraseNode(self, id)
3636
3637    def clear(self) -> None:
3638        r"""
3639
3640        Remove all the nodes and arcs from the graph.
3641
3642        """
3643        return _pyAgrum.DiGraph_clear(self)
3644
3645    def toDot(self) -> str:
3646        r"""
3647
3648        Returns
3649        -------
3650        str
3651            a friendly display of the graph in DOT format
3652
3653        """
3654        return _pyAgrum.DiGraph_toDot(self)
3655
3656    def topologicalOrder(self, clear: bool=True) -> List[int]:
3657        r"""
3658
3659        Returns
3660        -------
3661        List
3662            the list of the nodes Ids in a topological order
3663
3664        Raises
3665        ------
3666        pyAgrum.InvalidDirectedCycle
3667          If this graph contains cycles
3668
3669        """
3670        return _pyAgrum.DiGraph_topologicalOrder(self, clear)
3671
3672    def hasDirectedPath(self, _from: int, to: int) -> bool:
3673        r"""
3674
3675        Check if a directedpath exists bewteen from and to.
3676
3677        Parameters
3678        ----------
3679        from : int
3680        	the id of the first node of the (possible) path
3681        to : int
3682        	the id of the last node of the (possible) path
3683
3684        Returns
3685        -------
3686        bool
3687            True if the directed path exists
3688
3689        """
3690        return _pyAgrum.DiGraph_hasDirectedPath(self, _from, to)
3691
3692    def __repr__(self) -> str:
3693        return _pyAgrum.DiGraph___repr__(self)
3694
3695    def __str__(self) -> str:
3696        return _pyAgrum.DiGraph___str__(self)
3697
3698    def nodes(self) -> object:
3699        r"""
3700
3701        Returns
3702        -------
3703        set
3704            the set of ids
3705
3706        """
3707        return _pyAgrum.DiGraph_nodes(self)
3708
3709    def connectedComponents(self):
3710      """ connected components from a graph/BN
3711
3712      Compute the connected components of a pyAgrum's graph or Bayesian Network
3713      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
3714
3715      The firstly visited node for each component is called a 'root' and is used as a key for the component.
3716      This root has been arbitrarily chosen during the algorithm.
3717
3718      Returns
3719      -------
3720      dict(int,Set[int])
3721        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
3722
3723      """
3724      nodes=self.nodes()
3725      connected_components=dict()
3726
3727      def parcours(node,orig):
3728          cc={node}
3729          nodes.discard(node)
3730          if hasattr(self,'children'):
3731              for chi in self.children(node):
3732                  if chi!=orig:
3733                      if chi in nodes:
3734                          cc|=parcours(chi,node)
3735
3736          if hasattr(self,'parents'):
3737              for par in self.parents(node):
3738                  if par!=orig:
3739                      if par in nodes:
3740                          cc|=parcours(par,node)
3741
3742          if hasattr(self,'neighbours'):
3743              for nei in self.neighbours(node):
3744                  if nei!=orig:
3745                      if nei in nodes:
3746                          cc|=parcours(nei,node)
3747          return cc
3748
3749      while (len(nodes)>0):
3750          root=nodes.pop()
3751          connected_components[root]=parcours(root,None)
3752      return connected_components
3753
3754
3755    def addNodes(self, n: int) -> object:
3756        r"""
3757
3758        Add n nodes.
3759
3760        Parameters
3761        ----------
3762        n : int
3763          the number of nodes to add.
3764
3765        Returns
3766        -------
3767        Set of int
3768          the new ids
3769
3770        """
3771        return _pyAgrum.DiGraph_addNodes(self, n)
3772
3773    def arcs(self) -> object:
3774        r"""
3775
3776        Returns
3777        -------
3778        List
3779        	the list of the arcs
3780
3781        """
3782        return _pyAgrum.DiGraph_arcs(self)
3783
3784    def parents(self, id: int) -> object:
3785        r"""
3786
3787        Parameters
3788        ----------
3789        id :
3790        	The id of the child node
3791
3792        Returns
3793        -------
3794        Set
3795            the set of the parents ids.
3796
3797        """
3798        return _pyAgrum.DiGraph_parents(self, id)
3799
3800    def children(self, id: int) -> object:
3801        r"""
3802
3803        Parameters
3804        ----------
3805        id : int
3806          the id of the parent
3807
3808        Returns
3809        -------
3810        Set
3811        	the set of all the children
3812
3813        """
3814        return _pyAgrum.DiGraph_children(self, id)
3815
3816    def addNode(self) -> int:
3817        r"""
3818
3819        Returns
3820        -------
3821        int
3822          the new NodeId
3823
3824        """
3825        return _pyAgrum.DiGraph_addNode(self)
3826
3827    def addNodeWithId(self, id: int) -> None:
3828        r"""
3829
3830        Add a node by choosing a new NodeId.
3831
3832        Parameters
3833        ----------
3834        id : int
3835          The id of the new node
3836
3837        Raises
3838        ------
3839        pyAgrum.DuplicateElement
3840          If the given id is already used
3841
3842        """
3843        return _pyAgrum.DiGraph_addNodeWithId(self, id)
3844
3845    def existsNode(self, id: int) -> bool:
3846        r"""
3847
3848        Check if a node with a certain id exists in the graph.
3849
3850        Parameters
3851        ----------
3852        id : int
3853            the checked id
3854
3855        Returns
3856        -------
3857        bool
3858            True if the node exists
3859
3860        """
3861        return _pyAgrum.DiGraph_existsNode(self, id)
3862
3863    def size(self) -> int:
3864        r"""
3865
3866        Returns
3867        -------
3868        int
3869            the number of nodes in the graph
3870
3871        """
3872        return _pyAgrum.DiGraph_size(self)
3873
3874    def empty(self) -> bool:
3875        r"""
3876
3877        Check if the graph is empty.
3878
3879        Returns
3880        -------
3881        bool
3882            True if the graph is empty
3883
3884        """
3885        return _pyAgrum.DiGraph_empty(self)
3886
3887    def addArc(self, *args) -> None:
3888        r"""
3889
3890        Add an arc from tail to head.
3891
3892        Parameters
3893        ----------
3894        tail : int
3895          the id of the tail node
3896        head : int
3897          the id of the head node
3898
3899        Raises
3900        ------
3901        pyAgrum.InvalidNode
3902          If head or tail does not belong to the graph nodes.
3903
3904        """
3905        return _pyAgrum.DiGraph_addArc(self, *args)
3906
3907    def eraseArc(self, n1: int, n2: int) -> None:
3908        r"""
3909
3910        Erase the arc between n1 and n2.
3911
3912        Parameters
3913        ----------
3914        n1 : int
3915        	the id of the tail node
3916        n2 : int
3917        	the id of the head node
3918
3919        """
3920        return _pyAgrum.DiGraph_eraseArc(self, n1, n2)
3921
3922    def existsArc(self, n1: int, n2: int) -> bool:
3923        r"""
3924
3925        Check if an arc exists bewteen n1 and n2.
3926
3927        Parameters
3928        ----------
3929        n1 : int
3930        	the id of the tail node
3931        n2 : int
3932        	the id of the head node
3933
3934        Returns
3935        -------
3936        bool
3937            True if the arc exists
3938
3939        """
3940        return _pyAgrum.DiGraph_existsArc(self, n1, n2)
3941
3942    def eraseParents(self, n: int) -> None:
3943        r"""
3944
3945        Erase the arcs coming to the node.
3946
3947        Parameters
3948        ----------
3949        n : int
3950        	the id of the child node
3951
3952        """
3953        return _pyAgrum.DiGraph_eraseParents(self, n)
3954
3955    def eraseChildren(self, n: int) -> None:
3956        r"""
3957
3958        Erase the arcs heading through the node's children.
3959
3960        Parameters
3961        ----------
3962        n : int
3963        	the id of the parent node
3964
3965        """
3966        return _pyAgrum.DiGraph_eraseChildren(self, n)
3967
3968    def sizeArcs(self) -> int:
3969        r"""
3970
3971        Returns
3972        -------
3973        int
3974            the number of arcs in the graph
3975
3976        """
3977        return _pyAgrum.DiGraph_sizeArcs(self)
3978
3979    def emptyArcs(self) -> bool:
3980        r"""
3981
3982        Check if the graph doesn't contains arcs.
3983
3984        Returns
3985        -------
3986        bool
3987            True if the graph doesn't contains arcs
3988
3989        """
3990        return _pyAgrum.DiGraph_emptyArcs(self)
3991
3992# Register DiGraph in _pyAgrum:
3993_pyAgrum.DiGraph_swigregister(DiGraph)
3994
3995class DAG(DiGraph):
3996    r"""
3997
3998    DAG represents a Directed Acyclic Graph.
3999
4000    DAG() -> DAG
4001        default constructor
4002
4003    DAG(src) -> DAG
4004        Parameters:
4005            * **src** (*DAG*) -- the DAG to copy
4006
4007    """
4008
4009    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
4010    __repr__ = _swig_repr
4011
4012    def __init__(self, *args):
4013        _pyAgrum.DAG_swiginit(self, _pyAgrum.new_DAG(*args))
4014    __swig_destroy__ = _pyAgrum.delete_DAG
4015
4016    def moralGraph(self) -> "pyAgrum.UndiGraph":
4017        return _pyAgrum.DAG_moralGraph(self)
4018
4019    def moralizedAncestralGraph(self, nodes: List[int]) -> "pyAgrum.UndiGraph":
4020        return _pyAgrum.DAG_moralizedAncestralGraph(self, nodes)
4021
4022    def dSeparation(self, *args) -> bool:
4023        return _pyAgrum.DAG_dSeparation(self, *args)
4024
4025    def addArc(self, *args) -> None:
4026        r"""
4027
4028        Add an arc from tail to head.
4029
4030        Parameters
4031        ----------
4032        tail : int
4033          the id of the tail node
4034        head : int
4035          the id of the head node
4036
4037        Raises
4038        ------
4039        pyAgrum.InvalidDirectedCircle
4040        	If any (directed) cycle is created by this arc
4041        pyAgrum.InvalidNode
4042        	If head or tail does not belong to the graph nodes
4043
4044        """
4045        return _pyAgrum.DAG_addArc(self, *args)
4046
4047    def eraseArc(self, n1: int, n2: int) -> None:
4048        return _pyAgrum.DAG_eraseArc(self, n1, n2)
4049
4050    def existsArc(self, n1: int, n2: int) -> bool:
4051        return _pyAgrum.DAG_existsArc(self, n1, n2)
4052
4053    def eraseParents(self, n: int) -> None:
4054        return _pyAgrum.DAG_eraseParents(self, n)
4055
4056    def eraseChildren(self, n: int) -> None:
4057        return _pyAgrum.DAG_eraseChildren(self, n)
4058
4059    def sizeArcs(self) -> int:
4060        return _pyAgrum.DAG_sizeArcs(self)
4061
4062    def emptyArcs(self) -> bool:
4063        return _pyAgrum.DAG_emptyArcs(self)
4064
4065# Register DAG in _pyAgrum:
4066_pyAgrum.DAG_swigregister(DAG)
4067
4068class MixedGraph(UndiGraph, DiGraph):
4069    r"""
4070
4071    MixedGraph represents a graph with both arcs and edges.
4072
4073    MixedGraph() -> MixedGraph
4074        default constructor
4075
4076    MixedGraph(src) -> MixedGraph
4077        Parameters:
4078            * **src** (*pyAgrum.MixedGraph*) --the MixedGraph to copy
4079
4080    """
4081
4082    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
4083
4084    def __init__(self, *args):
4085        _pyAgrum.MixedGraph_swiginit(self, _pyAgrum.new_MixedGraph(*args))
4086    __swig_destroy__ = _pyAgrum.delete_MixedGraph
4087
4088    def __eq__(self, g: "MixedGraph") -> bool:
4089        return _pyAgrum.MixedGraph___eq__(self, g)
4090
4091    def __ne__(self, g: "MixedGraph") -> bool:
4092        return _pyAgrum.MixedGraph___ne__(self, g)
4093
4094    def eraseNode(self, id: int) -> None:
4095        r"""
4096
4097        Erase the node and all the related arcs and edges.
4098
4099        Parameters
4100        ----------
4101        id : int
4102        	the id of the node
4103
4104        """
4105        return _pyAgrum.MixedGraph_eraseNode(self, id)
4106
4107    def clear(self) -> None:
4108        r"""
4109
4110        Remove all the nodes and edges from the graph.
4111
4112        """
4113        return _pyAgrum.MixedGraph_clear(self)
4114
4115    def mixedOrientedPath(self, node1: int, node2: int) -> "pyAgrum.YetUnWrapped":
4116        r"""
4117
4118        Parameters
4119        ----------
4120        node1 : int
4121        	the id form which the path begins
4122        node2 : int
4123        	the id to witch the path ends
4124
4125        Returns
4126        -------
4127        List
4128        	 a path from node1 to node2, using edges and/or arcs (following the direction of the arcs). If no path is found, the returned list is empty.
4129
4130        """
4131        return _pyAgrum.MixedGraph_mixedOrientedPath(self, node1, node2)
4132
4133    def mixedUnorientedPath(self, node1: int, node2: int) -> "pyAgrum.YetUnWrapped":
4134        r"""
4135
4136        Parameters
4137        ----------
4138        node1 : int
4139        	the id from which the path begins
4140        node2 : int
4141        	the id to which the path ends
4142
4143        Returns
4144        -------
4145        List
4146        	 a path from node1 to node2, using edges and/or arcs (not necessarily following the direction of the arcs). If no path is found, the list is empty.
4147
4148
4149        """
4150        return _pyAgrum.MixedGraph_mixedUnorientedPath(self, node1, node2)
4151
4152    def toDot(self) -> str:
4153        r"""
4154
4155        Returns
4156        -------
4157        str
4158            a friendly display of the graph in DOT format
4159
4160        """
4161        return _pyAgrum.MixedGraph_toDot(self)
4162
4163    def adjacents(self, id: int) -> List[int]:
4164        return _pyAgrum.MixedGraph_adjacents(self, id)
4165
4166    def __repr__(self) -> str:
4167        return _pyAgrum.MixedGraph___repr__(self)
4168
4169    def __str__(self) -> str:
4170        return _pyAgrum.MixedGraph___str__(self)
4171
4172    def addNodes(self, n: int) -> object:
4173        r"""
4174
4175        Add n nodes.
4176
4177        Parameters
4178        ----------
4179        n : int
4180          the number of nodes to add.
4181
4182        Returns
4183        -------
4184        Set of int
4185          the new ids
4186
4187        """
4188        return _pyAgrum.MixedGraph_addNodes(self, n)
4189
4190    def addNode(self) -> int:
4191        r"""
4192
4193        Returns
4194        -------
4195        int
4196          the new NodeId
4197
4198        """
4199        return _pyAgrum.MixedGraph_addNode(self)
4200
4201    def addNodeWithId(self, id: int) -> None:
4202        r"""
4203
4204        Add a node by choosing a new NodeId.
4205
4206        Parameters
4207        ----------
4208        id : int
4209          The id of the new node
4210
4211        Raises
4212        ------
4213        pyAgrum.DuplicateElement
4214          If the given id is already used
4215
4216        """
4217        return _pyAgrum.MixedGraph_addNodeWithId(self, id)
4218
4219    def existsNode(self, id: int) -> bool:
4220        r"""
4221
4222        Check if a node with a certain id exists in the graph.
4223
4224        Parameters
4225        ----------
4226        id : int
4227            the checked id
4228
4229        Returns
4230        -------
4231        bool
4232            True if the node exists
4233
4234        """
4235        return _pyAgrum.MixedGraph_existsNode(self, id)
4236
4237    def size(self) -> int:
4238        r"""
4239
4240        Returns
4241        -------
4242        int
4243            the number of nodes in the graph
4244
4245        """
4246        return _pyAgrum.MixedGraph_size(self)
4247
4248    def empty(self) -> bool:
4249        r"""
4250
4251        Check if the graph is empty.
4252
4253        Returns
4254        -------
4255        bool
4256            True if the graph is empty
4257
4258        """
4259        return _pyAgrum.MixedGraph_empty(self)
4260
4261    def addEdge(self, n1: int, n2: int) -> None:
4262        r"""
4263
4264        Insert a new edge into the graph.
4265
4266        Parameters
4267        ----------
4268        n1 : int
4269          the id of one node of the new inserted edge
4270        n2 : int
4271          the id of the other node of the new inserted edge
4272
4273        Raises
4274        ------
4275        pyAgrum.InvalidNode
4276          If n1 or n2 does not belong to the graph nodes.
4277
4278        """
4279        return _pyAgrum.MixedGraph_addEdge(self, n1, n2)
4280
4281    def eraseEdge(self, n1: int, n2: int) -> None:
4282        r"""
4283
4284        Erase the edge between n1 and n2.
4285
4286        Parameters
4287        ----------
4288        n1 : int
4289          the id of the tail node
4290        n2 : int
4291          the id of the head node
4292
4293        """
4294        return _pyAgrum.MixedGraph_eraseEdge(self, n1, n2)
4295
4296    def existsEdge(self, n1: int, n2: int) -> bool:
4297        r"""
4298
4299        Check if an edge exists bewteen n1 and n2.
4300
4301        Parameters
4302        ----------
4303        n1 : int
4304          the id of one extremity of the edge
4305        n2 : int
4306          the id of the other extremity if tge edge
4307
4308        Returns
4309        -------
4310        bool
4311            True if the arc exists
4312
4313        """
4314        return _pyAgrum.MixedGraph_existsEdge(self, n1, n2)
4315
4316    def sizeEdges(self) -> int:
4317        r"""
4318
4319        Returns
4320        -------
4321        int
4322            the number of edges in the graph
4323
4324        """
4325        return _pyAgrum.MixedGraph_sizeEdges(self)
4326
4327    def emptyEdges(self) -> bool:
4328        r"""
4329
4330        Check if the graph doesn't contains edges.
4331
4332        Returns
4333        -------
4334        bool
4335            True if the graph doesn't contains edges
4336
4337        """
4338        return _pyAgrum.MixedGraph_emptyEdges(self)
4339
4340    def eraseNeighbours(self, n: int) -> None:
4341        r"""
4342
4343        Erase all the edges adjacent to a given node.
4344
4345        Parameters
4346        ----------
4347        n : int
4348          the id of the node
4349
4350        """
4351        return _pyAgrum.MixedGraph_eraseNeighbours(self, n)
4352
4353    def addArc(self, n1: int, n2: int) -> None:
4354        r"""
4355
4356        Add an arc from tail to head.
4357
4358        Parameters
4359        ----------
4360        tail : int
4361          the id of the tail node
4362        head : int
4363          the id of the head node
4364
4365        Raises
4366        ------
4367        pyAgrum.InvalidNode
4368          If head or tail does not belong to the graph nodes.
4369
4370        """
4371        return _pyAgrum.MixedGraph_addArc(self, n1, n2)
4372
4373    def eraseArc(self, n1: int, n2: int) -> None:
4374        r"""
4375
4376        Erase the arc between n1 and n2.
4377
4378        Parameters
4379        ----------
4380        n1 : int
4381        	the id of the tail node
4382        n2 : int
4383        	the id of the head node
4384
4385        """
4386        return _pyAgrum.MixedGraph_eraseArc(self, n1, n2)
4387
4388    def existsArc(self, n1: int, n2: int) -> bool:
4389        r"""
4390
4391        Check if an arc exists bewteen n1 and n2.
4392
4393        Parameters
4394        ----------
4395        n1 : int
4396        	the id of the tail node
4397        n2 : int
4398        	the id of the head node
4399
4400        Returns
4401        -------
4402        bool
4403            True if the arc exists
4404
4405        """
4406        return _pyAgrum.MixedGraph_existsArc(self, n1, n2)
4407
4408    def eraseParents(self, n: int) -> None:
4409        r"""
4410
4411        Erase the arcs coming to the node.
4412
4413        Parameters
4414        ----------
4415        n : int
4416        	the id of the child node
4417
4418        """
4419        return _pyAgrum.MixedGraph_eraseParents(self, n)
4420
4421    def eraseChildren(self, n: int) -> None:
4422        r"""
4423
4424        Erase the arcs heading through the node's children.
4425
4426        Parameters
4427        ----------
4428        n : int
4429        	the id of the parent node
4430
4431        """
4432        return _pyAgrum.MixedGraph_eraseChildren(self, n)
4433
4434    def sizeArcs(self) -> int:
4435        r"""
4436
4437        Returns
4438        -------
4439        int
4440            the number of arcs in the graph
4441
4442        """
4443        return _pyAgrum.MixedGraph_sizeArcs(self)
4444
4445    def emptyArcs(self) -> bool:
4446        r"""
4447
4448        Check if the graph doesn't contains arcs.
4449
4450        Returns
4451        -------
4452        bool
4453            True if the graph doesn't contains arcs
4454
4455        """
4456        return _pyAgrum.MixedGraph_emptyArcs(self)
4457
4458# Register MixedGraph in _pyAgrum:
4459_pyAgrum.MixedGraph_swigregister(MixedGraph)
4460
4461class CliqueGraph(UndiGraph):
4462    r"""
4463
4464    CliqueGraph represents a Clique Graph.
4465
4466    CliqueGraph() -> CliqueGraph
4467        default constructor
4468
4469    CliqueGraph(src) -> CliqueGraph
4470        Parameter
4471            * **src** (*pyAgrum.CliqueGraph*) -- the CliqueGraph to copy
4472
4473    """
4474
4475    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
4476    __repr__ = _swig_repr
4477
4478    def __init__(self, *args):
4479        _pyAgrum.CliqueGraph_swiginit(self, _pyAgrum.new_CliqueGraph(*args))
4480    __swig_destroy__ = _pyAgrum.delete_CliqueGraph
4481
4482    def addEdge(self, first: int, second: int) -> None:
4483        r"""
4484
4485        Insert a new edge into the graph.
4486
4487        Parameters
4488        ----------
4489        n1 : int
4490          the id of one node of the new inserted edge
4491        n2 : int
4492          the id of the other node of the new inserted edge
4493
4494        Raises
4495        ------
4496        pyAgrum.InvalidNode
4497          If n1 or n2 does not belong to the graph nodes.
4498
4499        """
4500        return _pyAgrum.CliqueGraph_addEdge(self, first, second)
4501
4502    def eraseEdge(self, edge: "pyAgrum.Edge") -> None:
4503        r"""
4504
4505        Erase the edge between n1 and n2.
4506
4507        Parameters
4508        ----------
4509        n1 : int
4510          the id of the tail node
4511        n2 : int
4512          the id of the head node
4513
4514        """
4515        return _pyAgrum.CliqueGraph_eraseEdge(self, edge)
4516
4517    def clearEdges(self) -> None:
4518        r"""
4519
4520        Remove all edges and their separators
4521
4522        """
4523        return _pyAgrum.CliqueGraph_clearEdges(self)
4524
4525    def addNode(self, *args) -> None:
4526        r"""
4527
4528        Returns
4529        -------
4530        int
4531          the new NodeId
4532
4533        """
4534        return _pyAgrum.CliqueGraph_addNode(self, *args)
4535
4536    def eraseNode(self, node: int) -> None:
4537        r"""
4538
4539        Erase the node and all the adjacent edges.
4540
4541        Parameters
4542        ----------
4543        id : int
4544          the id of the node
4545
4546        """
4547        return _pyAgrum.CliqueGraph_eraseNode(self, node)
4548
4549    def clear(self) -> None:
4550        r"""
4551
4552        Remove all the nodes and edges from the graph.
4553
4554        """
4555        return _pyAgrum.CliqueGraph_clear(self)
4556
4557    def container(self, idNode: int) -> int:
4558        r"""
4559
4560        Parameters
4561        ----------
4562        idNode : int
4563          the id of the node
4564
4565        Returns
4566        -------
4567        int
4568          the id of a clique containing the node
4569
4570        Raises
4571        ------
4572        pyAgrum.NotFound
4573          If no clique contains idNode
4574
4575        """
4576        return _pyAgrum.CliqueGraph_container(self, idNode)
4577
4578    def setClique(self, idClique: int, new_clique: List[int]) -> None:
4579        r"""
4580
4581        changes the set of nodes included into a given clique
4582
4583        Parameters
4584        ----------
4585        idClique : int
4586          the id of the clique
4587        new_clique : Set
4588          the new set of nodes to be included in the clique
4589
4590        Raises
4591        ------
4592        pyAgrum.NotFound
4593          If idClique is not a clique of the graph
4594
4595        """
4596        return _pyAgrum.CliqueGraph_setClique(self, idClique, new_clique)
4597
4598    def addToClique(self, clique_id: int, node_id: int) -> None:
4599        r"""
4600
4601        Change the set of nodes included into a given clique and returns the new set
4602
4603        Parameters
4604        ----------
4605        clique_id : int
4606          the id of the clique
4607        node_id : int
4608          the id of the node
4609
4610        Raises
4611        ------
4612        pyAgrum.NotFound
4613          If clique_id does not exist
4614        pyAgrum.DuplicateElement
4615          If clique_id set already contains the ndoe
4616
4617        """
4618        return _pyAgrum.CliqueGraph_addToClique(self, clique_id, node_id)
4619
4620    def eraseFromClique(self, clique_id: int, node_id: int) -> None:
4621        r"""
4622
4623        Remove a node from a clique
4624
4625        Parameters
4626        ----------
4627        clique_id : int
4628          the id of the clique
4629        node_id : int
4630          the id of the node
4631
4632        Raises
4633        ------
4634        pyAgrum.NotFound
4635          If clique_id does not exist
4636
4637        """
4638        return _pyAgrum.CliqueGraph_eraseFromClique(self, clique_id, node_id)
4639
4640    def containerPath(self, node1: int, node2: int) -> "pyAgrum.YetUnWrapped":
4641        r"""
4642
4643        Parameters
4644        ----------
4645        node1 : int
4646          the id of one node
4647        node2 : int
4648          the id of the other node
4649
4650        Returns
4651        -------
4652        List
4653          a path from a clique containing node1 to a clique containing node2
4654
4655        Raises
4656        ------
4657        pyAgrum.NotFound
4658          If such path cannot be found
4659
4660        """
4661        return _pyAgrum.CliqueGraph_containerPath(self, node1, node2)
4662
4663    def hasRunningIntersection(self) -> bool:
4664        r"""
4665
4666        Returns
4667        -------
4668        bool
4669          True if the running intersection property holds
4670
4671        """
4672        return _pyAgrum.CliqueGraph_hasRunningIntersection(self)
4673
4674    def isJoinTree(self) -> bool:
4675        r"""
4676
4677        Returns
4678        -------
4679        bool
4680          True if the graph is a join tree
4681
4682        """
4683        return _pyAgrum.CliqueGraph_isJoinTree(self)
4684
4685    def toDot(self) -> str:
4686        r"""
4687
4688        Returns
4689        -------
4690        str
4691            a friendly display of the graph in DOT format
4692
4693        """
4694        return _pyAgrum.CliqueGraph_toDot(self)
4695
4696    def __ne__(self, _from: "CliqueGraph") -> bool:
4697        return _pyAgrum.CliqueGraph___ne__(self, _from)
4698
4699    def __eq__(self, _from: "CliqueGraph") -> bool:
4700        return _pyAgrum.CliqueGraph___eq__(self, _from)
4701
4702    def clique(self, clique: int) -> object:
4703        r"""
4704
4705        Parameters
4706        ----------
4707        idClique : int
4708          the id of the clique
4709
4710        Returns
4711        -------
4712        Set
4713          The set of nodes included in the clique
4714
4715        Raises
4716        ------
4717        pyAgrum.NotFound
4718          If the clique does not belong to the clique graph
4719
4720        """
4721        return _pyAgrum.CliqueGraph_clique(self, clique)
4722
4723    def separator(self, cliq1: int, cliq2: int) -> object:
4724        r"""
4725
4726        Parameters
4727        ----------
4728        edge : pyAgrum.Edge
4729          the edge to be checked
4730        clique1 : int
4731          one extremity of the edge
4732        clique : int
4733          the other extremity of the edge
4734
4735        Returns
4736        -------
4737        Set
4738          the separator included in a given edge
4739
4740        Raises
4741        ------
4742        pyAgrum.NotFound
4743          If the edge does not belong to the clique graph
4744
4745        """
4746        return _pyAgrum.CliqueGraph_separator(self, cliq1, cliq2)
4747
4748    def toDotWithNames(self,bn):
4749        """
4750        Parameters
4751        ----------
4752        bn : pyAgrum.BayesNet
4753        a Bayesian network
4754
4755        Returns
4756        -------
4757        str
4758          a friendly display of the graph in DOT format where ids have been changed according to their correspondance in the BN
4759        """
4760        def nameFromId(m):
4761          return " ".join([bn.variable(int(n)).name()
4762                           for n in m.group().split("-")])
4763        import re
4764        m = re.compile('(?<=label=\")\d+[\-\d+]*')
4765        return m.sub(nameFromId,self.toDot())
4766
4767
4768# Register CliqueGraph in _pyAgrum:
4769_pyAgrum.CliqueGraph_swigregister(CliqueGraph)
4770
4771class Instantiation(object):
4772    r"""
4773
4774    Class for assigning/browsing values to tuples of discrete variables.
4775
4776    Instantiation is designed to assign values to tuples of variables and to efficiently loop over values of subsets of variables.
4777
4778    Instantiation() -> Instantiation
4779        default constructor
4780
4781    Instantiation(aI) -> Instantiation
4782        Parameters:
4783          * **aI** (*pyAgrum.Instantiation*) -- the Instantiation we copy
4784
4785    Returns
4786    -------
4787    pyAgrum.Instantiation
4788    	An empty tuple or a copy of the one in parameters
4789
4790    Instantiation is subscriptable therefore values can be easily accessed/modified.
4791
4792    Examples
4793    --------
4794    >>> ## Access the value of A in an instantiation aI
4795    >>> valueOfA = aI['A']
4796    >>> ## Modify the value
4797    >>> aI['A'] = newValueOfA
4798
4799    """
4800
4801    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
4802
4803    def __init__(self, *args):
4804        _pyAgrum.Instantiation_swiginit(self, _pyAgrum.new_Instantiation(*args))
4805    __swig_destroy__ = _pyAgrum.delete_Instantiation
4806
4807    def nbrDim(self) -> int:
4808        r"""
4809
4810        Returns
4811        -------
4812        int
4813            The number of variables in the Instantiation.
4814
4815        """
4816        return _pyAgrum.Instantiation_nbrDim(self)
4817
4818    def add(self, v: "pyAgrum.DiscreteVariable") -> None:
4819        r"""
4820
4821        Adds a new variable in the Instantiation.
4822
4823        Parameters
4824        ----------
4825        v : pyAgrum.DiscreteVariable
4826          The new variable added to the Instantiation
4827
4828        Raises
4829        ------
4830        DuplicateElement
4831          If the variable is already in this Instantiation
4832
4833
4834        """
4835        val = _pyAgrum.Instantiation_add(self, v)
4836
4837        return self
4838
4839
4840        return val
4841
4842
4843    def erase(self, *args) -> None:
4844        r"""
4845
4846        Parameters
4847        ----------
4848        v : pyAgrum.DiscreteVariable
4849          The variable to be removed from this Instantiation.
4850
4851        Raises
4852        ------
4853        NotFound
4854          If v does not belong to this Instantiation.
4855
4856        """
4857        return _pyAgrum.Instantiation_erase(self, *args)
4858
4859    def clear(self) -> None:
4860        r"""
4861
4862        Erase all variables from an Instantiation.
4863
4864        """
4865        return _pyAgrum.Instantiation_clear(self)
4866
4867    def domainSize(self) -> int:
4868        r"""
4869
4870        Returns
4871        -------
4872        int
4873            The product of the variable's domain size in the Instantiation.
4874
4875        """
4876        return _pyAgrum.Instantiation_domainSize(self)
4877
4878    def pos(self, v: "pyAgrum.DiscreteVariable") -> int:
4879        r"""
4880
4881        Returns
4882        -------
4883        int
4884           the position of the variable v.
4885
4886        Parameters
4887        ----------
4888        v : pyAgrum.DiscreteVariable
4889            the variable for which its position is return.
4890
4891        Raises
4892        ------
4893        NotFound
4894          If v does not belong to the instantiation.
4895
4896        """
4897        return _pyAgrum.Instantiation_pos(self, v)
4898
4899    def val(self, *args) -> int:
4900        r"""
4901
4902        Parameters
4903        ----------
4904        i : int
4905        	The index of the variable.
4906        var : pyAgrum.DiscreteVariable
4907        	The variable the value of which we wish to know
4908
4909        Returns
4910        -------
4911        int
4912        	the current value of the variable.
4913
4914        Raises
4915        ------
4916        NotFound
4917          If the element cannot be found.
4918
4919        """
4920        return _pyAgrum.Instantiation_val(self, *args)
4921
4922    def variable(self, *args) -> "pyAgrum.DiscreteVariable":
4923        r"""
4924
4925        Parameters
4926        ----------
4927        i : int
4928          The index of the variable
4929
4930        Returns
4931        -------
4932        pyAgrum.DiscreteVariable
4933          the variable at position i in the tuple.
4934
4935        Raises
4936        ------
4937        NotFound
4938          If the element cannot be found.
4939
4940        """
4941        return _pyAgrum.Instantiation_variable(self, *args)
4942
4943    def chgVal(self, *args) -> "pyAgrum.Instantiation":
4944        r"""
4945
4946        Assign newval to v (or to the variable at position varPos) in the Instantiation.
4947
4948        Parameters
4949        ----------
4950        v : pyAgrum.DiscreteVariable or string
4951          The variable whose value is assigned (or its name)
4952        varPos : int
4953          The index of the variable whose value is assigned in the tuple of variables of the Instantiation
4954        newval : int or string
4955          The index of the value assigned (or its name)
4956
4957        Returns
4958        -------
4959        pyAgrum.Instantiation
4960            The modified instantiation
4961
4962        Raises
4963        ------
4964        NotFound
4965          If variable v does not belong to the instantiation.
4966        OutOfBound
4967          If newval is not a possible value for the variable.
4968
4969        """
4970        return _pyAgrum.Instantiation_chgVal(self, *args)
4971
4972    def setVals(self, i: "Instantiation") -> "pyAgrum.Instantiation":
4973        r"""
4974
4975        Assign the values from i in the Instantiation.
4976
4977        Parameters
4978        ----------
4979        i : pyAgrum.Instantiation
4980          An Instantiation in which the new values are searched
4981
4982        Returns
4983        -------
4984        pyAgrum.Instantiation
4985          a reference to the instantiation
4986
4987        """
4988        return _pyAgrum.Instantiation_setVals(self, i)
4989
4990    def contains(self, *args) -> bool:
4991        r"""
4992
4993        Indicates whether a given variable belongs to the Instantiation.
4994
4995        Parameters
4996        ----------
4997        v : pyAgrum.DiscreteVariable
4998            The variable for which the test is made.
4999
5000        Returns
5001        -------
5002        bool :
5003            True if the variable is in the Instantiation.
5004
5005        """
5006        return _pyAgrum.Instantiation_contains(self, *args)
5007
5008    def variablesSequence(self) -> List[object]:
5009        r"""
5010
5011        Returns
5012        -------
5013        List
5014            the sequence of DiscreteVariable of this instantiation.
5015
5016        """
5017        return _pyAgrum.Instantiation_variablesSequence(self)
5018
5019    def empty(self) -> bool:
5020        r"""
5021
5022        Returns
5023        -------
5024        bool
5025            True if the instantiation is empty.
5026
5027        """
5028        return _pyAgrum.Instantiation_empty(self)
5029
5030    def inOverflow(self) -> bool:
5031        r"""
5032
5033        Returns
5034        -------
5035        bool
5036          True if the current value of the tuple is correct
5037
5038        """
5039        return _pyAgrum.Instantiation_inOverflow(self)
5040
5041    def unsetOverflow(self) -> None:
5042        r"""
5043
5044        Removes the flag overflow.
5045
5046        """
5047        return _pyAgrum.Instantiation_unsetOverflow(self)
5048
5049    def unsetEnd(self) -> None:
5050        r"""
5051
5052        Alias for unsetOverflow().
5053
5054        """
5055        return _pyAgrum.Instantiation_unsetEnd(self)
5056
5057    def end(self) -> bool:
5058        r"""
5059
5060        Returns
5061        -------
5062        bool
5063            True if the Instantiation reached the end.
5064
5065        """
5066        return _pyAgrum.Instantiation_end(self)
5067
5068    def rend(self) -> bool:
5069        r"""
5070
5071        Returns
5072        -------
5073        bool:
5074          True if the Instantiation reached the rend.
5075
5076        """
5077        return _pyAgrum.Instantiation_rend(self)
5078
5079    def inc(self) -> None:
5080        r"""
5081
5082        Operator ++.
5083
5084        """
5085        return _pyAgrum.Instantiation_inc(self)
5086
5087    def dec(self) -> None:
5088        r"""
5089
5090        Operator --.
5091
5092        """
5093        return _pyAgrum.Instantiation_dec(self)
5094
5095    def incIn(self, i: "Instantiation") -> None:
5096        r"""
5097
5098        Operator ++ for the variables in i.
5099
5100        Parameters
5101        ----------
5102        i : pyAgrum.Instantiation
5103            The set of variables to increment in this Instantiation.
5104
5105        """
5106        return _pyAgrum.Instantiation_incIn(self, i)
5107
5108    def decIn(self, i: "Instantiation") -> None:
5109        r"""
5110
5111        Operator -- for the variables in i.
5112
5113        Parameters
5114        ----------
5115        i : pyAgrum.Instantiation
5116          The set of variables to decrement in this Instantiation
5117
5118        """
5119        return _pyAgrum.Instantiation_decIn(self, i)
5120
5121    def incOut(self, i: "Instantiation") -> None:
5122        r"""
5123
5124        Operator ++ for the variables not in i.
5125
5126        Parameters
5127        ----------
5128        i : Instantiation
5129            The set of variable to not increment in this Instantiation.
5130
5131        """
5132        return _pyAgrum.Instantiation_incOut(self, i)
5133
5134    def decOut(self, i: "Instantiation") -> None:
5135        r"""
5136
5137        Operator -- for the variables not in i.
5138
5139        Parameters
5140        ----------
5141        i : pyAgrum.Instantiation
5142          The set of variables to not decrement in this Instantiation.
5143
5144        """
5145        return _pyAgrum.Instantiation_decOut(self, i)
5146
5147    def incNotVar(self, v: "pyAgrum.DiscreteVariable") -> None:
5148        r"""
5149
5150        Operator ++ for vars which are not v.
5151
5152        Parameters
5153        ----------
5154        v : pyAgrum.DiscreteVariable
5155            The variable not to increment in this Instantiation.
5156
5157        """
5158        return _pyAgrum.Instantiation_incNotVar(self, v)
5159
5160    def decNotVar(self, v: "pyAgrum.DiscreteVariable") -> None:
5161        r"""
5162
5163        Operator -- for vars which are not v.
5164
5165        Parameters
5166        ----------
5167        v : pyAgrum.DiscreteVariable
5168          The variable not to decrement in this Instantiation.
5169
5170        """
5171        return _pyAgrum.Instantiation_decNotVar(self, v)
5172
5173    def incVar(self, v: "pyAgrum.DiscreteVariable") -> None:
5174        r"""
5175
5176        Operator ++ for variable v only.
5177
5178        Parameters
5179        ----------
5180        v : pyAgrum.DiscreteVariable
5181            The variable to increment in this Instantiation.
5182
5183        Raises
5184        ------
5185        NotFound
5186          If variable v does not belong to the Instantiation.
5187
5188        """
5189        return _pyAgrum.Instantiation_incVar(self, v)
5190
5191    def decVar(self, v: "pyAgrum.DiscreteVariable") -> None:
5192        r"""
5193
5194        Operator -- for variable v only.
5195
5196        Parameters
5197        ----------
5198        v : pyAgrum.DiscreteVariable
5199         The variable to decrement in this Instantiation.
5200
5201        Raises
5202        ------
5203        NotFound
5204          If variable v does not belong to the Instantiation.
5205
5206        """
5207        return _pyAgrum.Instantiation_decVar(self, v)
5208
5209    def setFirst(self) -> None:
5210        r"""
5211
5212        Assign the first values to the tuple of the Instantiation.
5213
5214        """
5215        return _pyAgrum.Instantiation_setFirst(self)
5216
5217    def setLast(self) -> None:
5218        r"""
5219
5220        Assign the last values in the Instantiation.
5221
5222        """
5223        return _pyAgrum.Instantiation_setLast(self)
5224
5225    def setFirstIn(self, i: "Instantiation") -> None:
5226        r"""
5227
5228        Assign the first values in the Instantiation for the variables in i.
5229
5230        Parameters
5231        ----------
5232        i : pyAgrum.Instantiation
5233          The variables to which their first value is assigned in this Instantiation.
5234
5235        """
5236        return _pyAgrum.Instantiation_setFirstIn(self, i)
5237
5238    def setLastIn(self, i: "Instantiation") -> None:
5239        r"""
5240
5241        Assign the last values in the Instantiation for the variables in i.
5242
5243        Parameters
5244        ----------
5245        i : pyAgrum.Instantiation
5246            The variables to which their last value is assigned in this Instantiation.
5247
5248        """
5249        return _pyAgrum.Instantiation_setLastIn(self, i)
5250
5251    def setFirstOut(self, i: "Instantiation") -> None:
5252        r"""
5253
5254        Assign the first values in the Instantiation for the variables not in i.
5255
5256        Parameters
5257        ----------
5258        i : pyAgrum.Instantiation
5259            The variable that will not be set to their first value in this Instantiation.
5260
5261        """
5262        return _pyAgrum.Instantiation_setFirstOut(self, i)
5263
5264    def setLastOut(self, i: "Instantiation") -> None:
5265        r"""
5266
5267        Assign the last values in the Instantiation for the variables not in i.
5268
5269        Parameters
5270        ----------
5271        i : pyAgrum.Instantiation
5272            The variables that will not be set to their last value in this Instantiation.
5273
5274        """
5275        return _pyAgrum.Instantiation_setLastOut(self, i)
5276
5277    def setFirstNotVar(self, v: "pyAgrum.DiscreteVariable") -> None:
5278        r"""
5279
5280        Assign the first values to variables different of v.
5281
5282        Parameters
5283        ----------
5284        v : pyAgrum.DiscreteVariable
5285          The variable that will not be set to its first value in this Instantiation.
5286
5287        """
5288        return _pyAgrum.Instantiation_setFirstNotVar(self, v)
5289
5290    def setLastNotVar(self, v: "pyAgrum.DiscreteVariable") -> None:
5291        r"""
5292
5293        Assign the last values to variables different of v.
5294
5295        Parameters
5296        ----------
5297        v : pyAgrum.DiscreteVariable
5298            The variable that will not be set to its last value in this Instantiation.
5299
5300        """
5301        return _pyAgrum.Instantiation_setLastNotVar(self, v)
5302
5303    def setFirstVar(self, v: "pyAgrum.DiscreteVariable") -> None:
5304        r"""
5305
5306        Assign the first value in the Instantiation for var v.
5307
5308        Parameters
5309        ----------
5310        v : pyAgrum.DiscreteVariable
5311            The variable that will be set to its first value in this Instantiation.
5312
5313        """
5314        return _pyAgrum.Instantiation_setFirstVar(self, v)
5315
5316    def setLastVar(self, v: "pyAgrum.DiscreteVariable") -> None:
5317        r"""
5318
5319        Assign the last value in the Instantiation for var v.
5320
5321        Parameters
5322        ----------
5323        v : pyAgrum.DiscreteVariable
5324          The variable that will be set to its last value in this Instantiation.
5325
5326        """
5327        return _pyAgrum.Instantiation_setLastVar(self, v)
5328
5329    def __eq__(self, other: "Instantiation") -> bool:
5330        return _pyAgrum.Instantiation___eq__(self, other)
5331
5332    def __iadd__(self, depl: int) -> "pyAgrum.Instantiation":
5333        return _pyAgrum.Instantiation___iadd__(self, depl)
5334
5335    def __isub__(self, depl: int) -> "pyAgrum.Instantiation":
5336        return _pyAgrum.Instantiation___isub__(self, depl)
5337
5338    def hamming(self) -> int:
5339        r"""
5340
5341        Returns
5342        -------
5343        int
5344          the hamming distance of this instantiation.
5345
5346        """
5347        return _pyAgrum.Instantiation_hamming(self)
5348
5349    def reorder(self, *args) -> None:
5350        r"""
5351
5352        Reorder vars of this instantiation giving the order in v (or i).
5353
5354        Parameters
5355        ----------
5356        i : pyAgrum.Instantiation
5357          The sequence of variables with which to reorder this Instantiation.
5358        v : list
5359            The new order of variables for this Instantiation.
5360
5361        """
5362        return _pyAgrum.Instantiation_reorder(self, *args)
5363
5364    def __repr__(self) -> str:
5365        return _pyAgrum.Instantiation___repr__(self)
5366
5367    def __str__(self) -> str:
5368        return _pyAgrum.Instantiation___str__(self)
5369
5370    def setMutable(self) -> None:
5371        return _pyAgrum.Instantiation_setMutable(self)
5372
5373    def isMutable(self) -> bool:
5374        return _pyAgrum.Instantiation_isMutable(self)
5375
5376    def todict(self, withLabels: bool=False) -> object:
5377        r"""
5378
5379        Create a dictionary `{variable_name:value}` from an instantiation
5380
5381        Parameters
5382        ----------
5383        withLabels : boolean
5384        	The value will be a label (string) if True. It will be a position (int) if False.
5385
5386        Returns
5387        -------
5388        Dict[str,int]
5389            The dictionary
5390
5391        """
5392        return _pyAgrum.Instantiation_todict(self, withLabels)
5393
5394    def fromdict(self, dict: object) -> None:
5395        r"""
5396
5397        Change the values in an instantiation from a dictionary `{variable_name:value}` where value can be a position (int) or a label (string).
5398
5399        If a variable_name does not occur in the instantiation, nothing is done.
5400
5401        Warnings
5402        --------
5403            OutOfBounds raised if a value cannot be found.
5404
5405        """
5406        return _pyAgrum.Instantiation_fromdict(self, dict)
5407
5408    def __setitem__(self,key,item):
5409      self.chgVal(key,item)
5410
5411    def __getitem__(self,key):
5412      return self.val(self.variable(key))
5413
5414    def addVarsFromModel(self,model,names):
5415      r"""
5416      From a graphical model, add all the variable whose names are in the iterable
5417
5418      Parameters
5419      ----------
5420      model : pyAgrum.GraphicalModel
5421      a (discrete) graphical model such as Bayesian network, Markov network, Influence Diagram, etc.
5422
5423      names : iterable of strings
5424      a list/set/etc of names of variables (as string)
5425
5426      Returns
5427      -------
5428      pyAgrum.Instantiation
5429      the current instantiation (self) in order to chain methods.
5430      """
5431      for name in names:
5432        self.add(model.variable(name))
5433      return self
5434
5435
5436
5437# Register Instantiation in _pyAgrum:
5438_pyAgrum.Instantiation_swigregister(Instantiation)
5439
5440GUM_DEFAULT_ITERATOR_NUMBER = _pyAgrum.GUM_DEFAULT_ITERATOR_NUMBER
5441class GraphicalModel(object):
5442    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
5443
5444    def __init__(self, *args, **kwargs):
5445        raise AttributeError("No constructor defined - class is abstract")
5446    __repr__ = _swig_repr
5447    __swig_destroy__ = _pyAgrum.delete_GraphicalModel
5448
5449    def property(self, name: str) -> str:
5450        return _pyAgrum.GraphicalModel_property(self, name)
5451
5452    def propertyWithDefault(self, name: str, byDefault: str) -> str:
5453        return _pyAgrum.GraphicalModel_propertyWithDefault(self, name, byDefault)
5454
5455    def setProperty(self, name: str, value: str) -> None:
5456        return _pyAgrum.GraphicalModel_setProperty(self, name, value)
5457
5458    def variableNodeMap(self) -> "pyAgrum.VariableNodeMap":
5459        return _pyAgrum.GraphicalModel_variableNodeMap(self)
5460
5461    def size(self) -> int:
5462        return _pyAgrum.GraphicalModel_size(self)
5463
5464    def empty(self) -> bool:
5465        return _pyAgrum.GraphicalModel_empty(self)
5466
5467    def exists(self, *args) -> bool:
5468        return _pyAgrum.GraphicalModel_exists(self, *args)
5469
5470    def names(self, *args) -> List[str]:
5471        return _pyAgrum.GraphicalModel_names(self, *args)
5472
5473    def ids(self, names: "Vector_string") -> "pyAgrum.YetUnWrapped":
5474        return _pyAgrum.GraphicalModel_ids(self, names)
5475
5476    def nodeset(self, names: "Vector_string") -> List[int]:
5477        return _pyAgrum.GraphicalModel_nodeset(self, names)
5478
5479    def nodes(self) -> Set[int]:
5480        return _pyAgrum.GraphicalModel_nodes(self)
5481
5482    def completeInstantiation(self) -> "pyAgrum.Instantiation":
5483        return _pyAgrum.GraphicalModel_completeInstantiation(self)
5484
5485    def variable(self, id: int) -> "pyAgrum.DiscreteVariable":
5486        return _pyAgrum.GraphicalModel_variable(self, id)
5487
5488    def nodeId(self, var: "pyAgrum.DiscreteVariable") -> int:
5489        return _pyAgrum.GraphicalModel_nodeId(self, var)
5490
5491    def idFromName(self, name: str) -> int:
5492        return _pyAgrum.GraphicalModel_idFromName(self, name)
5493
5494    def variableFromName(self, name: str) -> "pyAgrum.DiscreteVariable":
5495        return _pyAgrum.GraphicalModel_variableFromName(self, name)
5496
5497    def log10DomainSize(self) -> float:
5498        return _pyAgrum.GraphicalModel_log10DomainSize(self)
5499
5500    def isIndependent(self, *args) -> bool:
5501        return _pyAgrum.GraphicalModel_isIndependent(self, *args)
5502
5503# Register GraphicalModel in _pyAgrum:
5504_pyAgrum.GraphicalModel_swigregister(GraphicalModel)
5505cvar = _pyAgrum.cvar
5506_list_end_safe_ = cvar._list_end_safe_
5507_list_end_ = cvar._list_end_
5508
5509class DAGmodel(GraphicalModel):
5510    r"""
5511
5512    Abstract class used by IBayesNet and InfluenceDiagram.
5513
5514    """
5515
5516    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
5517
5518    def __init__(self, *args, **kwargs):
5519        raise AttributeError("No constructor defined - class is abstract")
5520    __repr__ = _swig_repr
5521    __swig_destroy__ = _pyAgrum.delete_DAGmodel
5522
5523    def dag(self) -> "pyAgrum.DAG":
5524        r"""
5525
5526        Returns
5527        -------
5528        pyAgrum.DAG
5529        	a constant reference to the dag of this BayesNet.
5530
5531        """
5532        val = _pyAgrum.DAGmodel_dag(self)
5533
5534        val = DAG(val) # copying the DAG
5535
5536
5537        return val
5538
5539
5540    def size(self) -> int:
5541        r"""
5542
5543        Returns
5544        -------
5545        int
5546            the number of nodes in the graph
5547
5548        """
5549        return _pyAgrum.DAGmodel_size(self)
5550
5551    def sizeArcs(self) -> int:
5552        r"""
5553
5554        Returns
5555        -------
5556        int
5557            the number of arcs in the graph
5558
5559        """
5560        return _pyAgrum.DAGmodel_sizeArcs(self)
5561
5562    def nodes(self) -> Set[int]:
5563        r"""
5564
5565        Returns
5566        -------
5567        set
5568            the set of ids
5569
5570        """
5571        return _pyAgrum.DAGmodel_nodes(self)
5572
5573    def exists(self, node: int) -> bool:
5574        return _pyAgrum.DAGmodel_exists(self, node)
5575
5576    def arcs(self) -> Set[Tuple[int,int]]:
5577        r"""
5578
5579        Returns
5580        -------
5581        list
5582        	The lisf of arcs in the graph
5583
5584        """
5585        return _pyAgrum.DAGmodel_arcs(self)
5586
5587    def existsArc(self, *args) -> bool:
5588        return _pyAgrum.DAGmodel_existsArc(self, *args)
5589
5590    def parents(self, *args) -> List[int]:
5591        return _pyAgrum.DAGmodel_parents(self, *args)
5592
5593    def family(self, *args) -> List[int]:
5594        return _pyAgrum.DAGmodel_family(self, *args)
5595
5596    def children(self, *args) -> List[int]:
5597        return _pyAgrum.DAGmodel_children(self, *args)
5598
5599    def descendants(self, *args) -> List[int]:
5600        return _pyAgrum.DAGmodel_descendants(self, *args)
5601
5602    def ancestors(self, *args) -> List[int]:
5603        return _pyAgrum.DAGmodel_ancestors(self, *args)
5604
5605    def moralizedAncestralGraph(self, *args) -> "pyAgrum.UndiGraph":
5606        return _pyAgrum.DAGmodel_moralizedAncestralGraph(self, *args)
5607
5608    def isIndependent(self, *args) -> bool:
5609        return _pyAgrum.DAGmodel_isIndependent(self, *args)
5610
5611    def moralGraph(self, clear: bool=True) -> "pyAgrum.UndiGraph":
5612        r"""
5613
5614        Returns the moral graph of the BayesNet, formed by adding edges between all pairs of nodes that have a common child, and then making all edges in the graph undirected.
5615
5616        Returns
5617        -------
5618        pyAgrum.UndiGraph
5619        	The moral graph
5620
5621        """
5622        return _pyAgrum.DAGmodel_moralGraph(self, clear)
5623
5624    def topologicalOrder(self, clear: bool=True) -> List[int]:
5625        r"""
5626
5627        Returns
5628        -------
5629        List
5630            the list of the nodes Ids in a topological order
5631
5632        Raises
5633        ------
5634        pyAgrum.InvalidDirectedCycle
5635        	If this graph contains cycles
5636
5637        """
5638        return _pyAgrum.DAGmodel_topologicalOrder(self, clear)
5639
5640    def hasSameStructure(self, other: "pyAgrum.DAGmodel") -> bool:
5641        r"""
5642
5643        Parameters
5644        ----------
5645        pyAgrum.DAGmodel
5646        	a direct acyclic model
5647
5648        Returns
5649        -------
5650        bool
5651            True if all the named node are the same and all the named arcs are the same
5652
5653        """
5654        return _pyAgrum.DAGmodel_hasSameStructure(self, other)
5655
5656# Register DAGmodel in _pyAgrum:
5657_pyAgrum.DAGmodel_swigregister(DAGmodel)
5658
5659class UGmodel(GraphicalModel):
5660    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
5661
5662    def __init__(self, *args, **kwargs):
5663        raise AttributeError("No constructor defined - class is abstract")
5664    __repr__ = _swig_repr
5665    __swig_destroy__ = _pyAgrum.delete_UGmodel
5666
5667    def graph(self) -> "pyAgrum.UndiGraph":
5668        return _pyAgrum.UGmodel_graph(self)
5669
5670    def size(self) -> int:
5671        return _pyAgrum.UGmodel_size(self)
5672
5673    def sizeEdges(self) -> int:
5674        return _pyAgrum.UGmodel_sizeEdges(self)
5675
5676    def nodes(self) -> Set[int]:
5677        return _pyAgrum.UGmodel_nodes(self)
5678
5679    def exists(self, node: int) -> bool:
5680        return _pyAgrum.UGmodel_exists(self, node)
5681
5682    def edges(self) -> Set[Tuple[int,int]]:
5683        return _pyAgrum.UGmodel_edges(self)
5684
5685    def existsEdge(self, *args) -> bool:
5686        return _pyAgrum.UGmodel_existsEdge(self, *args)
5687
5688    def neighbours(self, *args) -> List[int]:
5689        return _pyAgrum.UGmodel_neighbours(self, *args)
5690
5691    def isIndependent(self, *args) -> bool:
5692        return _pyAgrum.UGmodel_isIndependent(self, *args)
5693
5694    def hasSameStructure(self, other: "pyAgrum.UGmodel") -> bool:
5695        return _pyAgrum.UGmodel_hasSameStructure(self, other)
5696
5697# Register UGmodel in _pyAgrum:
5698_pyAgrum.UGmodel_swigregister(UGmodel)
5699
5700class EssentialGraph(object):
5701    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
5702    __repr__ = _swig_repr
5703
5704    def __init__(self, *args):
5705        _pyAgrum.EssentialGraph_swiginit(self, _pyAgrum.new_EssentialGraph(*args))
5706    __swig_destroy__ = _pyAgrum.delete_EssentialGraph
5707
5708    def mixedGraph(self) -> "pyAgrum.MixedGraph":
5709        r"""
5710
5711        Returns
5712        -------
5713        pyAgrum.MixedGraph
5714        	the mixed graph
5715
5716        """
5717        return _pyAgrum.EssentialGraph_mixedGraph(self)
5718
5719    def toDot(self) -> str:
5720        r"""
5721
5722        Returns
5723        -------
5724        str
5725            a friendly display of the graph in DOT format
5726
5727        """
5728        return _pyAgrum.EssentialGraph_toDot(self)
5729
5730    def sizeArcs(self) -> int:
5731        r"""
5732
5733        Returns
5734        -------
5735        int
5736            the number of arcs in the graph
5737
5738        """
5739        return _pyAgrum.EssentialGraph_sizeArcs(self)
5740
5741    def sizeEdges(self) -> int:
5742        r"""
5743
5744        Returns
5745        -------
5746        int
5747            the number of edges in the graph
5748
5749        """
5750        return _pyAgrum.EssentialGraph_sizeEdges(self)
5751
5752    def sizeNodes(self) -> int:
5753        r"""
5754
5755        Returns
5756        -------
5757        int
5758        	the number of nodes in the graph
5759
5760        """
5761        return _pyAgrum.EssentialGraph_sizeNodes(self)
5762
5763    def size(self) -> int:
5764        r"""
5765
5766        Returns
5767        -------
5768        int
5769        	the number of nodes in the graph
5770
5771        """
5772        return _pyAgrum.EssentialGraph_size(self)
5773
5774    def skeleton(self) -> "pyAgrum.UndiGraph":
5775        return _pyAgrum.EssentialGraph_skeleton(self)
5776
5777    def nodes(self) -> object:
5778        return _pyAgrum.EssentialGraph_nodes(self)
5779
5780    def connectedComponents(self):
5781      """ connected components from a graph/BN
5782
5783      Compute the connected components of a pyAgrum's graph or Bayesian Network
5784      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
5785
5786      The firstly visited node for each component is called a 'root' and is used as a key for the component.
5787      This root has been arbitrarily chosen during the algorithm.
5788
5789      Returns
5790      -------
5791      dict(int,Set[int])
5792        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
5793
5794      """
5795      nodes=self.nodes()
5796      connected_components=dict()
5797
5798      def parcours(node,orig):
5799          cc={node}
5800          nodes.discard(node)
5801          if hasattr(self,'children'):
5802              for chi in self.children(node):
5803                  if chi!=orig:
5804                      if chi in nodes:
5805                          cc|=parcours(chi,node)
5806
5807          if hasattr(self,'parents'):
5808              for par in self.parents(node):
5809                  if par!=orig:
5810                      if par in nodes:
5811                          cc|=parcours(par,node)
5812
5813          if hasattr(self,'neighbours'):
5814              for nei in self.neighbours(node):
5815                  if nei!=orig:
5816                      if nei in nodes:
5817                          cc|=parcours(nei,node)
5818          return cc
5819
5820      while (len(nodes)>0):
5821          root=nodes.pop()
5822          connected_components[root]=parcours(root,None)
5823      return connected_components
5824
5825
5826    def arcs(self) -> object:
5827        r"""
5828
5829        Returns
5830        -------
5831        list
5832        	The lisf of arcs in the EssentialGraph
5833
5834        """
5835        return _pyAgrum.EssentialGraph_arcs(self)
5836
5837    def parents(self, id: int) -> object:
5838        r"""
5839
5840        Parameters
5841        ----------
5842        id :
5843        	The id of the child node
5844
5845        Returns
5846        -------
5847        Set
5848            the set of the parents ids.
5849
5850        """
5851        return _pyAgrum.EssentialGraph_parents(self, id)
5852
5853    def children(self, id: int) -> object:
5854        r"""
5855
5856        Parameters
5857        ----------
5858        id : int
5859          the id of the parent
5860
5861        Returns
5862        -------
5863        Set
5864        	the set of all the children
5865
5866        """
5867        return _pyAgrum.EssentialGraph_children(self, id)
5868
5869    def edges(self) -> object:
5870        r"""
5871
5872        Returns
5873        -------
5874        List
5875          the list of the edges
5876
5877        """
5878        return _pyAgrum.EssentialGraph_edges(self)
5879
5880    def neighbours(self, id: int) -> object:
5881        r"""
5882
5883        Parameters
5884        ----------
5885        id : int
5886            the id of the checked node
5887
5888        Returns
5889        -------
5890        Set
5891            The set of edges adjacent to the given node
5892
5893        """
5894        return _pyAgrum.EssentialGraph_neighbours(self, id)
5895
5896# Register EssentialGraph in _pyAgrum:
5897_pyAgrum.EssentialGraph_swigregister(EssentialGraph)
5898
5899class MarkovBlanket(object):
5900    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
5901    __repr__ = _swig_repr
5902
5903    def __init__(self, *args):
5904        _pyAgrum.MarkovBlanket_swiginit(self, _pyAgrum.new_MarkovBlanket(*args))
5905    __swig_destroy__ = _pyAgrum.delete_MarkovBlanket
5906
5907    def dag(self) -> "pyAgrum.DAG":
5908        r"""
5909
5910        Returns
5911        -------
5912        pyAgrum.DAG
5913          a copy of the DAG
5914
5915        """
5916        return _pyAgrum.MarkovBlanket_dag(self)
5917
5918    def toDot(self) -> str:
5919        r"""
5920
5921        Returns
5922        -------
5923        str
5924            a friendly display of the graph in DOT format
5925
5926        """
5927        return _pyAgrum.MarkovBlanket_toDot(self)
5928
5929    def sizeArcs(self) -> int:
5930        r"""
5931
5932        Returns
5933        -------
5934        int
5935            the number of arcs in the graph
5936
5937        """
5938        return _pyAgrum.MarkovBlanket_sizeArcs(self)
5939
5940    def sizeNodes(self) -> int:
5941        r"""
5942
5943        Returns
5944        -------
5945        int
5946        	the number of nodes in the graph
5947
5948        """
5949        return _pyAgrum.MarkovBlanket_sizeNodes(self)
5950
5951    def size(self) -> int:
5952        r"""
5953
5954        Returns
5955        -------
5956        int
5957            the number of nodes in the graph
5958
5959        """
5960        return _pyAgrum.MarkovBlanket_size(self)
5961
5962    def hasSameStructure(self, other: "pyAgrum.DAGmodel") -> bool:
5963        r"""
5964
5965        Parameters
5966        ----------
5967        pyAgrum.DAGmodel
5968        	a direct acyclic model
5969
5970        Returns
5971        -------
5972        bool
5973            True if all the named node are the same and all the named arcs are the same
5974
5975        """
5976        return _pyAgrum.MarkovBlanket_hasSameStructure(self, other)
5977
5978    def nodes(self) -> object:
5979        r"""
5980
5981        Returns
5982        -------
5983        set
5984            the set of ids
5985
5986        """
5987        return _pyAgrum.MarkovBlanket_nodes(self)
5988
5989    def connectedComponents(self):
5990      """ connected components from a graph/BN
5991
5992      Compute the connected components of a pyAgrum's graph or Bayesian Network
5993      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
5994
5995      The firstly visited node for each component is called a 'root' and is used as a key for the component.
5996      This root has been arbitrarily chosen during the algorithm.
5997
5998      Returns
5999      -------
6000      dict(int,Set[int])
6001        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
6002
6003      """
6004      nodes=self.nodes()
6005      connected_components=dict()
6006
6007      def parcours(node,orig):
6008          cc={node}
6009          nodes.discard(node)
6010          if hasattr(self,'children'):
6011              for chi in self.children(node):
6012                  if chi!=orig:
6013                      if chi in nodes:
6014                          cc|=parcours(chi,node)
6015
6016          if hasattr(self,'parents'):
6017              for par in self.parents(node):
6018                  if par!=orig:
6019                      if par in nodes:
6020                          cc|=parcours(par,node)
6021
6022          if hasattr(self,'neighbours'):
6023              for nei in self.neighbours(node):
6024                  if nei!=orig:
6025                      if nei in nodes:
6026                          cc|=parcours(nei,node)
6027          return cc
6028
6029      while (len(nodes)>0):
6030          root=nodes.pop()
6031          connected_components[root]=parcours(root,None)
6032      return connected_components
6033
6034
6035    def arcs(self) -> object:
6036        r"""
6037
6038        Returns
6039        -------
6040        List
6041        	the list of the arcs
6042
6043        """
6044        return _pyAgrum.MarkovBlanket_arcs(self)
6045
6046    def parents(self, id: int) -> object:
6047        r"""
6048
6049        Parameters
6050        ----------
6051        id :
6052        	The id of the child node
6053
6054        Returns
6055        -------
6056        Set
6057            the set of the parents ids.
6058
6059        """
6060        return _pyAgrum.MarkovBlanket_parents(self, id)
6061
6062    def children(self, id: int) -> object:
6063        r"""
6064
6065        Parameters
6066        ----------
6067        id : int
6068          the id of the parent
6069
6070        Returns
6071        -------
6072        Set
6073        	the set of all the children
6074
6075        """
6076        return _pyAgrum.MarkovBlanket_children(self, id)
6077
6078# Register MarkovBlanket in _pyAgrum:
6079_pyAgrum.MarkovBlanket_swigregister(MarkovBlanket)
6080
6081class StructuralComparator(object):
6082    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
6083    __repr__ = _swig_repr
6084
6085    def __init__(self):
6086        _pyAgrum.StructuralComparator_swiginit(self, _pyAgrum.new_StructuralComparator())
6087    __swig_destroy__ = _pyAgrum.delete_StructuralComparator
6088
6089    def compare(self, *args) -> None:
6090        r"""
6091
6092        Use to compare the edges/arcs of two structure of the same type and same sizes (either DiGraph, UndiGraph or MixedGraph).
6093
6094        Could be use to compare a BN and its learned version.
6095
6096        Parameters
6097        ----------
6098        ref :
6099        	the structure of reference
6100        test :
6101        	the structure we want to test
6102
6103        """
6104        return _pyAgrum.StructuralComparator_compare(self, *args)
6105
6106    def precision_skeleton(self) -> float:
6107        r"""
6108
6109        Rate of true postive over labelized edges.
6110
6111        Returns
6112        -------
6113        float
6114        	the precision of the tested graph skeleton
6115
6116        """
6117        return _pyAgrum.StructuralComparator_precision_skeleton(self)
6118
6119    def recall_skeleton(self) -> float:
6120        r"""
6121
6122        Rate of true postive over labelized edges.
6123
6124        Returns
6125        -------
6126        float
6127        	the recall of the tested graph skeleton
6128
6129        """
6130        return _pyAgrum.StructuralComparator_recall_skeleton(self)
6131
6132    def f_score_skeleton(self) -> float:
6133        r"""
6134
6135        Harmonic mean between recall and precision.
6136
6137        Returns
6138        -------
6139        float
6140        	the tarmonic mean of the tested graph skeleton
6141
6142        """
6143        return _pyAgrum.StructuralComparator_f_score_skeleton(self)
6144
6145    def precision(self) -> float:
6146        r"""
6147
6148        Rate of true postive over postively labelized arcs/edges.
6149
6150        Returns
6151        -------
6152        float
6153        	the precision of the tested graph
6154
6155        """
6156        return _pyAgrum.StructuralComparator_precision(self)
6157
6158    def recall(self) -> float:
6159        r"""
6160
6161        Rate of true postive over labelized arcs/edges.
6162
6163        Returns
6164        -------
6165        float
6166        	the recall of the tested graph
6167
6168        """
6169        return _pyAgrum.StructuralComparator_recall(self)
6170
6171    def f_score(self) -> float:
6172        r"""
6173
6174        Harmonic mean between recall and precision.
6175
6176        Returns
6177        -------
6178        float
6179        	the harmonic mean of the tested graph
6180
6181        """
6182        return _pyAgrum.StructuralComparator_f_score(self)
6183
6184# Register StructuralComparator in _pyAgrum:
6185_pyAgrum.StructuralComparator_swigregister(StructuralComparator)
6186
6187class ApproximationScheme(object):
6188    r"""
6189
6190    Used to parametrize stopping criteria in approximate inference or learning algorithm.
6191
6192    ApproximationScheme(verbosity=False) -> ApproximationScheme
6193        Parameters:
6194          * **verbosity** (*bool) -- to keep (or not) tracks of the learning process (history of epsilons)
6195
6196    """
6197
6198    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
6199    __repr__ = _swig_repr
6200
6201    def __init__(self, verbosity: bool=False):
6202        _pyAgrum.ApproximationScheme_swiginit(self, _pyAgrum.new_ApproximationScheme(verbosity))
6203    __swig_destroy__ = _pyAgrum.delete_ApproximationScheme
6204
6205    def setEpsilon(self, eps: float) -> None:
6206        r"""
6207
6208        Parameters
6209        ----------
6210        eps : float
6211        	the epsilon we want to use
6212
6213        Raises
6214        ------
6215        pyAgrum.OutOfBounds
6216        	If eps<0
6217
6218        """
6219        return _pyAgrum.ApproximationScheme_setEpsilon(self, eps)
6220
6221    def epsilon(self) -> float:
6222        r"""
6223
6224        Returns
6225        -------
6226        float
6227        	the value of epsilon
6228
6229        """
6230        return _pyAgrum.ApproximationScheme_epsilon(self)
6231
6232    def disableEpsilon(self) -> None:
6233        r"""
6234
6235        Disable epsilon as a stopping criterion.
6236
6237        """
6238        return _pyAgrum.ApproximationScheme_disableEpsilon(self)
6239
6240    def enableEpsilon(self) -> None:
6241        r"""
6242
6243        Enable epsilon as a stopping criterion.
6244
6245        """
6246        return _pyAgrum.ApproximationScheme_enableEpsilon(self)
6247
6248    def isEnabledEpsilon(self) -> bool:
6249        r"""
6250
6251        Returns
6252        -------
6253        bool
6254          True if epsilon is used as a stopping criterion.
6255
6256        """
6257        return _pyAgrum.ApproximationScheme_isEnabledEpsilon(self)
6258
6259    def setMinEpsilonRate(self, rate: float) -> None:
6260        r"""
6261
6262        Parameters
6263        ----------
6264        rate : float
6265        	the minimal epsilon rate
6266
6267        """
6268        return _pyAgrum.ApproximationScheme_setMinEpsilonRate(self, rate)
6269
6270    def minEpsilonRate(self) -> float:
6271        r"""
6272
6273        Returns
6274        -------
6275        float
6276        	the value of the minimal epsilon rate
6277
6278        """
6279        return _pyAgrum.ApproximationScheme_minEpsilonRate(self)
6280
6281    def disableMinEpsilonRate(self) -> None:
6282        r"""
6283
6284        Disable a min epsilon rate as a stopping criterion.
6285
6286        """
6287        return _pyAgrum.ApproximationScheme_disableMinEpsilonRate(self)
6288
6289    def enableMinEpsilonRate(self) -> None:
6290        r"""
6291
6292        Enable a min epsilon rate as a stopping criterion.
6293
6294        """
6295        return _pyAgrum.ApproximationScheme_enableMinEpsilonRate(self)
6296
6297    def isEnabledMinEpsilonRate(self) -> bool:
6298        r"""
6299
6300        Returns
6301        -------
6302        bool
6303          True if epsilon rate is used as a stopping criterion
6304
6305        """
6306        return _pyAgrum.ApproximationScheme_isEnabledMinEpsilonRate(self)
6307
6308    def setMaxIter(self, max: int) -> None:
6309        r"""
6310
6311        Parameters
6312        ----------
6313        max : int
6314        	the maximum number of iteration
6315
6316        Raises
6317        ------
6318        pyAgrum.OutOfBounds
6319        	If max <= 1
6320
6321        """
6322        return _pyAgrum.ApproximationScheme_setMaxIter(self, max)
6323
6324    def maxIter(self) -> int:
6325        r"""
6326
6327        Returns
6328        -------
6329        int
6330        	the criterion on number of iterations
6331
6332        """
6333        return _pyAgrum.ApproximationScheme_maxIter(self)
6334
6335    def disableMaxIter(self) -> None:
6336        r"""
6337
6338        Disable max iterations as a stopping criterion.
6339
6340        """
6341        return _pyAgrum.ApproximationScheme_disableMaxIter(self)
6342
6343    def enableMaxIter(self) -> None:
6344        r"""
6345
6346        Enable max iterations as a stopping criterion.
6347
6348        """
6349        return _pyAgrum.ApproximationScheme_enableMaxIter(self)
6350
6351    def isEnabledMaxIter(self) -> bool:
6352        r"""
6353
6354        Returns
6355        -------
6356        bool
6357          True if max iterations is used as a stopping criterion
6358
6359        """
6360        return _pyAgrum.ApproximationScheme_isEnabledMaxIter(self)
6361
6362    def setMaxTime(self, timeout: float) -> None:
6363        r"""
6364
6365        Parameters
6366        ----------
6367        tiemout : float
6368        	stopping criterion on timeout (in seconds)
6369
6370        Raises
6371        ------
6372        pyAgrum.OutOfBounds
6373        	If timeout<=0.0
6374
6375        """
6376        return _pyAgrum.ApproximationScheme_setMaxTime(self, timeout)
6377
6378    def maxTime(self) -> float:
6379        r"""
6380
6381        Returns
6382        -------
6383        float
6384        	the timeout(in seconds)
6385
6386        """
6387        return _pyAgrum.ApproximationScheme_maxTime(self)
6388
6389    def currentTime(self) -> float:
6390        r"""
6391
6392        Returns
6393        -------
6394        float
6395        	get the current running time in second (float)
6396
6397        """
6398        return _pyAgrum.ApproximationScheme_currentTime(self)
6399
6400    def disableMaxTime(self) -> None:
6401        r"""
6402
6403        Disable max time as a stopping criterion.
6404
6405        """
6406        return _pyAgrum.ApproximationScheme_disableMaxTime(self)
6407
6408    def enableMaxTime(self) -> None:
6409        r"""
6410
6411        Enable max time as a stopping criterion.
6412
6413        """
6414        return _pyAgrum.ApproximationScheme_enableMaxTime(self)
6415
6416    def isEnabledMaxTime(self) -> bool:
6417        r"""
6418
6419        Returns
6420        -------
6421        bool
6422          True if max time is used as a stopping criterion
6423
6424        """
6425        return _pyAgrum.ApproximationScheme_isEnabledMaxTime(self)
6426
6427    def setPeriodSize(self, p: int) -> None:
6428        r"""
6429
6430        Parameters
6431        ----------
6432        p : int
6433        	number of samples between 2 stopping
6434
6435        Raises
6436        ------
6437        pyAgrum.OutOfBounds
6438        	If p<1
6439
6440        """
6441        return _pyAgrum.ApproximationScheme_setPeriodSize(self, p)
6442
6443    def periodSize(self) -> int:
6444        r"""
6445
6446        Returns
6447        -------
6448        int
6449        	the number of samples between 2 stopping
6450
6451        Raises
6452        ------
6453        pyAgrum.OutOfBounds
6454        	If p<1
6455
6456        """
6457        return _pyAgrum.ApproximationScheme_periodSize(self)
6458
6459    def setVerbosity(self, v: bool) -> None:
6460        r"""
6461
6462        Parameters
6463        ----------
6464        v : bool
6465                verbosity
6466
6467        """
6468        return _pyAgrum.ApproximationScheme_setVerbosity(self, v)
6469
6470    def verbosity(self) -> bool:
6471        r"""
6472
6473        Returns
6474        -------
6475        bool
6476        	True if the verbosity is enabled
6477
6478        """
6479        return _pyAgrum.ApproximationScheme_verbosity(self)
6480
6481    def stateApproximationScheme(self) -> int:
6482        r"""
6483
6484        Returns
6485        -------
6486        int
6487          the state of the approximation scheme
6488
6489        """
6490        return _pyAgrum.ApproximationScheme_stateApproximationScheme(self)
6491
6492    def nbrIterations(self) -> int:
6493        r"""
6494
6495        Returns
6496        -------
6497        int
6498        	the number of iterations
6499
6500        """
6501        return _pyAgrum.ApproximationScheme_nbrIterations(self)
6502
6503    def history(self) -> List[float]:
6504        r"""
6505
6506        Returns
6507        -------
6508        tuple
6509        	the scheme history
6510
6511        Raises
6512        ------
6513        pyAgrum.OperationNotAllowed
6514        	If the scheme did not performed or if verbosity is set to false
6515
6516        """
6517        return _pyAgrum.ApproximationScheme_history(self)
6518
6519    def initApproximationScheme(self) -> None:
6520        r"""
6521
6522        Initiate the approximation scheme.
6523
6524        """
6525        return _pyAgrum.ApproximationScheme_initApproximationScheme(self)
6526
6527    def startOfPeriod(self) -> bool:
6528        r"""
6529
6530        Returns
6531        -------
6532        bool
6533          True if it is a start of a period
6534
6535        """
6536        return _pyAgrum.ApproximationScheme_startOfPeriod(self)
6537
6538    def updateApproximationScheme(self, incr: int=1) -> None:
6539        r"""
6540
6541        Update the approximation scheme.
6542
6543        """
6544        return _pyAgrum.ApproximationScheme_updateApproximationScheme(self, incr)
6545
6546    def remainingBurnIn(self) -> int:
6547        r"""
6548
6549        Returns
6550        -------
6551        int
6552          the number of remaining burn in
6553
6554        """
6555        return _pyAgrum.ApproximationScheme_remainingBurnIn(self)
6556
6557    def stopApproximationScheme(self) -> None:
6558        r"""
6559
6560        Stop the approximation scheme.
6561
6562        """
6563        return _pyAgrum.ApproximationScheme_stopApproximationScheme(self)
6564
6565    def continueApproximationScheme(self, error: float) -> bool:
6566        r"""
6567
6568        Continue the approximation scheme.
6569
6570        Parameters
6571        ----------
6572        error : float
6573
6574        """
6575        return _pyAgrum.ApproximationScheme_continueApproximationScheme(self, error)
6576
6577# Register ApproximationScheme in _pyAgrum:
6578_pyAgrum.ApproximationScheme_swigregister(ApproximationScheme)
6579
6580FindBarrenNodesType_FIND_NO_BARREN_NODES = _pyAgrum.FindBarrenNodesType_FIND_NO_BARREN_NODES
6581FindBarrenNodesType_FIND_BARREN_NODES = _pyAgrum.FindBarrenNodesType_FIND_BARREN_NODES
6582
6583def randomDistribution(n: int) -> List[float]:
6584    r"""
6585
6586    Parameters
6587    ----------
6588    n : int
6589      The number of modalities for the ditribution.
6590
6591    Returns
6592    -------
6593    a random discrete distribution.
6594
6595    """
6596    return _pyAgrum.randomDistribution(n)
6597class DiscretizedVariable(IDiscretizedVariable):
6598    r"""
6599
6600    DiscretizedVariable is a discrete random variable with a set of ``ticks`` defining intervalls.
6601
6602    DiscretizedVariable(aName, aDesc='') -> DiscretizedVariable`
6603        Parameters:
6604            * **aName** (*str*) -- the name of the variable
6605            * **aDesc** (*str*) -- the (optional) description of the variable
6606
6607    DiscretizedVariable(aDDRV) -> DiscretizedVariable
6608        Parameters:
6609            * **aDDRV** (*pyAgrum.DiscretizedVariable*) -- the pyAgrum.DiscretizedVariable that will be copied
6610
6611    Examples
6612    --------
6613    >>> import pyAgrum as gum
6614    >>> vX=gum.DiscretizedVariable('X','X has been discretized').addTick(1).addTick(2).addTick(3).addTick(3.1415)
6615    >>> print(vX)
6616    X:Discretized(<[1;2[,[2;3[,[3;3.1415]>)
6617    >>> vX.isTick(4)
6618    False
6619    >>> vX.labels()
6620    ('[1;2[', '[2;3[', '[3;3.1415]')
6621    >>> # where is the real value 2.5 ?
6622    >>> vX.index('2.5')
6623    1
6624
6625    """
6626
6627    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
6628
6629    def __init__(self, *args):
6630        _pyAgrum.DiscretizedVariable_swiginit(self, _pyAgrum.new_DiscretizedVariable(*args))
6631    __swig_destroy__ = _pyAgrum.delete_DiscretizedVariable
6632
6633    def clone(self) -> "pyAgrum.DiscretizedVariable":
6634        r"""
6635
6636        Returns
6637        -------
6638        pyAgrum.DiscretizedVariable
6639        	a copy of the DiscretizedVariable
6640
6641        """
6642        return _pyAgrum.DiscretizedVariable_clone(self)
6643
6644    def varType(self) -> int:
6645        r"""
6646
6647        returns the type of variable
6648
6649        Returns
6650        -------
6651        int :
6652        	the type of the variable, 0: DiscretizedVariable, 1: LabelizedVariable, 2: RangeVariable
6653
6654        """
6655        return _pyAgrum.DiscretizedVariable_varType(self)
6656
6657    def isTick(self, aTick: float) -> bool:
6658        r"""
6659
6660        Parameters
6661        ----------
6662        aTick : float
6663        	the Tick to be tested
6664
6665        Returns
6666        -------
6667        bool :
6668        	True if the Tick already exists
6669
6670        """
6671        return _pyAgrum.DiscretizedVariable_isTick(self, aTick)
6672
6673    def addTick(self,*args):
6674        """
6675        Parameters
6676        ----------
6677        aTick : float
6678            the Tick to be added
6679
6680        Returns
6681        -------
6682        pyAgrum.DiscretizedVariable
6683            the discretized variable
6684
6685        Raises
6686        ------
6687        gum.DefaultInLabel
6688            If the tick is already defined
6689        """
6690        _pyAgrum.DiscretizedVariable_addTick(self,*args)
6691        return self
6692
6693
6694
6695    def eraseTicks(self) -> None:
6696        r"""
6697
6698        erase all the Ticks
6699
6700        """
6701        return _pyAgrum.DiscretizedVariable_eraseTicks(self)
6702
6703    def label(self, i: int) -> str:
6704        r"""
6705
6706        Parameters
6707        ----------
6708        i : int
6709        	the index of the label we wish to return
6710
6711        Returns
6712        -------
6713        str
6714        	the indice-th label
6715
6716        Raises
6717        ------
6718        pyAgrum.OutOfBound
6719        	If the variable does not contain the label
6720
6721        """
6722        return _pyAgrum.DiscretizedVariable_label(self, i)
6723
6724    def numerical(self, indice: int) -> float:
6725        r"""
6726
6727        Parameters
6728        ----------
6729        indice : int
6730        	an index
6731
6732        Returns
6733        -------
6734        float
6735        	the numerical representation of the indice-th value
6736
6737        """
6738        return _pyAgrum.DiscretizedVariable_numerical(self, indice)
6739
6740    def index(self, label: str) -> int:
6741        r"""
6742
6743        Parameters
6744        ----------
6745        label : str
6746        	a label
6747
6748        Returns
6749        -------
6750        int
6751        	the indice of the label
6752
6753        """
6754        return _pyAgrum.DiscretizedVariable_index(self, label)
6755
6756    def domainSize(self) -> int:
6757        r"""
6758
6759        Returns
6760        -------
6761        int
6762        	the number of modalities in the variable domain
6763
6764        """
6765        return _pyAgrum.DiscretizedVariable_domainSize(self)
6766
6767    def domain(self) -> str:
6768        r"""
6769
6770        Returns
6771        -------
6772        str
6773            the domain of the variable as a string
6774
6775        """
6776        return _pyAgrum.DiscretizedVariable_domain(self)
6777
6778    def stype(self) -> str:
6779        return _pyAgrum.DiscretizedVariable_stype(self)
6780
6781    def tick(self, i: int) -> float:
6782        r"""
6783
6784        Indicate the index of the Tick
6785
6786        Parameters
6787        ----------
6788        i : int
6789        	the index of the Tick
6790
6791        Returns
6792        -------
6793        aTick : float
6794        	the index-th Tick
6795
6796        Raises
6797        ------
6798        pyAgrum.NotFound
6799        	If the index is greater than the number of Ticks
6800
6801        """
6802        return _pyAgrum.DiscretizedVariable_tick(self, i)
6803
6804    def ticks(self) -> List[float]:
6805        r"""
6806
6807        Returns
6808        -------
6809        tuple :
6810        	a tuple containing all the Ticks
6811
6812        """
6813        return _pyAgrum.DiscretizedVariable_ticks(self)
6814
6815    def __repr__(self) -> str:
6816        return _pyAgrum.DiscretizedVariable___repr__(self)
6817
6818    def __str__(self) -> str:
6819        return _pyAgrum.DiscretizedVariable___str__(self)
6820
6821# Register DiscretizedVariable in _pyAgrum:
6822_pyAgrum.DiscretizedVariable_swigregister(DiscretizedVariable)
6823
6824class MultiDimContainer(object):
6825    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
6826
6827    def __init__(self, *args, **kwargs):
6828        raise AttributeError("No constructor defined - class is abstract")
6829    __repr__ = _swig_repr
6830    __swig_destroy__ = _pyAgrum.delete_MultiDimContainer
6831
6832    def set(self, i: "Instantiation", value: float) -> None:
6833        return _pyAgrum.MultiDimContainer_set(self, i, value)
6834
6835    def get(self, i: "Instantiation") -> float:
6836        return _pyAgrum.MultiDimContainer_get(self, i)
6837
6838    def fill(self, d: float) -> None:
6839        return _pyAgrum.MultiDimContainer_fill(self, d)
6840
6841    def populate(self, *args) -> None:
6842        return _pyAgrum.MultiDimContainer_populate(self, *args)
6843
6844    def copyFrom(self, *args) -> None:
6845        return _pyAgrum.MultiDimContainer_copyFrom(self, *args)
6846
6847    def extractFrom(self, src: "pyAgrum.Potential", mask: "Instantiation") -> None:
6848        return _pyAgrum.MultiDimContainer_extractFrom(self, src, mask)
6849
6850    def content(self, *args) -> "pyAgrum.Potential":
6851        return _pyAgrum.MultiDimContainer_content(self, *args)
6852
6853    def getMasterRef(self, *args) -> "pyAgrum.Potential":
6854        return _pyAgrum.MultiDimContainer_getMasterRef(self, *args)
6855
6856    def copy(self, src: "pyAgrum.Potential") -> None:
6857        return _pyAgrum.MultiDimContainer_copy(self, src)
6858
6859    def newFactory(self) -> "pyAgrum.Potential":
6860        return _pyAgrum.MultiDimContainer_newFactory(self)
6861
6862    def toString(self, *args) -> str:
6863        return _pyAgrum.MultiDimContainer_toString(self, *args)
6864
6865    def __eq__(self, p: "pyAgrum.Potential") -> bool:
6866        return _pyAgrum.MultiDimContainer___eq__(self, p)
6867
6868    def __ne__(self, p: "pyAgrum.Potential") -> bool:
6869        return _pyAgrum.MultiDimContainer___ne__(self, p)
6870
6871    def apply(self, f: "std::function< float (float) >") -> None:
6872        return _pyAgrum.MultiDimContainer_apply(self, f)
6873
6874    def reduce(self, f: "std::function< float (float,float) >", base: float) -> float:
6875        return _pyAgrum.MultiDimContainer_reduce(self, f, base)
6876
6877    def beginMultipleChanges(self) -> None:
6878        return _pyAgrum.MultiDimContainer_beginMultipleChanges(self)
6879
6880    def endMultipleChanges(self, *args) -> None:
6881        return _pyAgrum.MultiDimContainer_endMultipleChanges(self, *args)
6882
6883# Register MultiDimContainer in _pyAgrum:
6884_pyAgrum.MultiDimContainer_swigregister(MultiDimContainer)
6885
6886class Potential(object):
6887    r"""
6888
6889    Class representing a potential.
6890
6891    Potential() -> Potential
6892        default constructor
6893
6894    Potential(src) -> Potential
6895        Parameters:
6896            * **src** (*pyAgrum.Potential*) -- the Potential to copy
6897
6898    """
6899
6900    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
6901
6902    def __init__(self, *args):
6903        _pyAgrum.Potential_swiginit(self, _pyAgrum.new_Potential(*args))
6904
6905        self._list_vars=list()
6906
6907
6908
6909    __swig_destroy__ = _pyAgrum.delete_Potential
6910
6911    def newFactory(self) -> "pyAgrum.Potential":
6912        r"""
6913
6914        Erase the Potential content and create a new empty one.
6915
6916        Returns
6917        -------
6918        pyAgrum.Potential
6919         a reference to the new Potential
6920
6921        """
6922        return _pyAgrum.Potential_newFactory(self)
6923
6924    def random(self) -> "pyAgrum.Potential":
6925        return _pyAgrum.Potential_random(self)
6926
6927    def randomDistribution(self) -> "pyAgrum.Potential":
6928        return _pyAgrum.Potential_randomDistribution(self)
6929
6930    def randomCPT(self) -> "pyAgrum.Potential":
6931        return _pyAgrum.Potential_randomCPT(self)
6932
6933    def noising(self, alpha: float) -> "pyAgrum.Potential":
6934        return _pyAgrum.Potential_noising(self, alpha)
6935
6936    def isNonZeroMap(self) -> "pyAgrum.Potential":
6937        r"""
6938
6939        Returns
6940        -------
6941        pyAgrum.Potential
6942          a boolean-like potential using the predicate isNonZero
6943
6944        """
6945        return _pyAgrum.Potential_isNonZeroMap(self)
6946
6947    def sum(self) -> float:
6948        r"""
6949
6950        Returns
6951        -------
6952        float :
6953          the sum of all elements in the Potential
6954
6955        """
6956        return _pyAgrum.Potential_sum(self)
6957
6958    def product(self) -> float:
6959        r"""
6960
6961        Returns
6962        -------
6963        float
6964          the product of all elements in the Potential
6965
6966        """
6967        return _pyAgrum.Potential_product(self)
6968
6969    def max(self) -> float:
6970        r"""
6971
6972        Returns
6973        -------
6974        float
6975          the maximum of all elements in the Potential
6976
6977        """
6978        return _pyAgrum.Potential_max(self)
6979
6980    def min(self) -> float:
6981        r"""
6982
6983        Returns
6984        -------
6985        float
6986          the min of all elements in the Potential
6987
6988        """
6989        return _pyAgrum.Potential_min(self)
6990
6991    def maxNonOne(self) -> float:
6992        r"""
6993
6994        Returns
6995        -------
6996        float
6997          the maximum of non one elements in the Potential
6998
6999        Raises
7000        ------
7001        pyAgrum.NotFound
7002          If all value == 1.0
7003
7004        """
7005        return _pyAgrum.Potential_maxNonOne(self)
7006
7007    def minNonZero(self) -> float:
7008        r"""
7009
7010        Returns
7011        -------
7012        float
7013          the min of non zero elements in the Potential
7014
7015        Raises
7016        ------
7017        pyAgrum.NotFound
7018          If all value == 0.0
7019
7020        """
7021        return _pyAgrum.Potential_minNonZero(self)
7022
7023    def findAll(self, v: float) -> List[Dict[str,int]]:
7024        return _pyAgrum.Potential_findAll(self, v)
7025
7026    def argmax(self) -> List[Dict[str,int]]:
7027        return _pyAgrum.Potential_argmax(self)
7028
7029    def argmin(self) -> List[Dict[str,int]]:
7030        return _pyAgrum.Potential_argmin(self)
7031
7032    def entropy(self) -> float:
7033        r"""
7034
7035        Returns
7036        -------
7037        float
7038          the entropy of the potential
7039
7040        """
7041        return _pyAgrum.Potential_entropy(self)
7042
7043    def reorganize(self, *args) -> "pyAgrum.Potential":
7044        r"""
7045
7046        Create a new Potential with another order.
7047
7048        Returns
7049        -------
7050        varnames : list
7051          a list of the var names in the new order
7052
7053        Returns
7054        -------
7055        pyAgrum.Potential
7056          a reference to the modified potential
7057
7058        """
7059        return _pyAgrum.Potential_reorganize(self, *args)
7060
7061    def putFirst(self, varname: str) -> "pyAgrum.Potential":
7062        r"""
7063
7064        Parameters
7065        ----------
7066        v : pyAgrum.DiscreteVariable
7067            The variable for which the index should be 0.
7068
7069        Returns
7070        -------
7071        pyAgrum.Potential
7072          a reference to the modified potential
7073
7074        Raises
7075        ------
7076        pyAgrum.InvalidArgument
7077          If the var is not in the potential
7078
7079        """
7080        return _pyAgrum.Potential_putFirst(self, varname)
7081
7082    def fillWith(self, *args) -> "pyAgrum.Potential":
7083        r"""
7084
7085        Automatically fills the potential with v.
7086
7087        Parameters
7088        ----------
7089        v : number or list or pyAgrum.Potential the number of parameters of the Potential
7090            a value or a list/pyAgrum.Potential containing the values to fill the Potential with.
7091
7092        Warning
7093        -------
7094            if v is a list, the size of the list must be the
7095            if v is a pyAgrum.Potential. It must to contain variables with exactly the same names and labels but not necessarily the same variables.
7096
7097        Returns
7098        -------
7099        pyAgrum.Potential
7100              a reference to the modified potentia
7101
7102        Raises
7103        ------
7104        pyAgrum.SizeError
7105          If v size's does not matches the domain size.
7106
7107        """
7108        val = _pyAgrum.Potential_fillWith(self, *args)
7109
7110        return self
7111
7112
7113        return val
7114
7115
7116    def abs(self) -> "pyAgrum.Potential":
7117        r"""
7118
7119        Apply abs on every element of the container
7120
7121        Returns
7122        -------
7123        pyAgrum.Potential
7124            a reference to the modified potential.
7125
7126        """
7127        val = _pyAgrum.Potential_abs(self)
7128
7129        return self
7130
7131
7132        return val
7133
7134
7135    def sq(self) -> "pyAgrum.Potential":
7136        r"""
7137
7138        Square all the values in the Potential
7139
7140        """
7141        val = _pyAgrum.Potential_sq(self)
7142
7143        return self
7144
7145
7146        return val
7147
7148
7149    def log2(self) -> "pyAgrum.Potential":
7150        r"""
7151
7152        log2 all the values in the Potential
7153
7154        Warning
7155        -------
7156        When the Potential contains 0 or negative values, no exception are raised but `-inf` or `nan` values are assigned.
7157
7158        """
7159        val = _pyAgrum.Potential_log2(self)
7160
7161        return self
7162
7163
7164        return val
7165
7166
7167    def new_abs(self) -> "pyAgrum.Potential":
7168        return _pyAgrum.Potential_new_abs(self)
7169
7170    def new_sq(self) -> "pyAgrum.Potential":
7171        return _pyAgrum.Potential_new_sq(self)
7172
7173    def new_log2(self) -> "pyAgrum.Potential":
7174        return _pyAgrum.Potential_new_log2(self)
7175
7176    def normalize(self) -> "pyAgrum.Potential":
7177        r"""
7178
7179        Normalize the Potential (do nothing if sum is 0)
7180
7181        Returns
7182        -------
7183        pyAgrum.Potential
7184          a reference to the normalized Potential
7185
7186        """
7187        val = _pyAgrum.Potential_normalize(self)
7188
7189        return self
7190
7191
7192        return val
7193
7194
7195    def KL(self, p: "Potential") -> float:
7196        r"""
7197
7198        Check the compatibility and compute the Kullback-Leibler divergence between the potential and.
7199
7200        Parameters
7201        ----------
7202        p : pyAgrum.Potential
7203          the potential from which we want to calculate the divergence.
7204
7205        Returns
7206        -------
7207        float
7208          The value of the divergence
7209
7210        Raises
7211        ------
7212        pyAgrum.InvalidArgument
7213          If p is not compatible with the potential (dimension, variables)
7214        pyAgrum.FatalError
7215          If a zero is found in p or the potential and not in the other.
7216
7217        """
7218        return _pyAgrum.Potential_KL(self, p)
7219
7220    def normalizeAsCPT(self, varId: int=0) -> "pyAgrum.Potential":
7221        r"""
7222
7223        Normalize the Potential as a CPT
7224
7225        Returns
7226        -------
7227        pyAgrum.Potential
7228          a reference to the normalized Potential
7229
7230        Raises
7231        ------
7232        pyAgrum.FatalError
7233          If some distribution sums to 0
7234
7235        """
7236        val = _pyAgrum.Potential_normalizeAsCPT(self, varId)
7237
7238        return self
7239
7240
7241        return val
7242
7243
7244    def scale(self, v: float) -> "pyAgrum.Potential":
7245        r"""
7246
7247        Create a new potential multiplied by v.
7248
7249        Parameters
7250        ----------
7251        v : float
7252          a multiplier
7253
7254        Returns
7255        -------
7256          a reference to the modified potential
7257
7258        """
7259        val = _pyAgrum.Potential_scale(self, v)
7260
7261        return self
7262
7263
7264        return val
7265
7266
7267    def translate(self, v: float) -> "pyAgrum.Potential":
7268        r"""
7269
7270        Create a new potential added with v.
7271
7272        Parameters
7273        ----------
7274        v : float
7275          The value to be added
7276
7277        Returns
7278        -------
7279          a reference to the modified potential
7280
7281        """
7282        val = _pyAgrum.Potential_translate(self, v)
7283
7284        return self
7285
7286
7287        return val
7288
7289
7290    def inverse(self) -> "pyAgrum.Potential":
7291        val = _pyAgrum.Potential_inverse(self)
7292
7293        return self
7294
7295
7296        return val
7297
7298
7299    def draw(self) -> int:
7300        r"""
7301
7302        draw a value using the potential as a probability table.
7303
7304        Returns
7305        -------
7306        int
7307          the index of the drawn value
7308
7309        """
7310        return _pyAgrum.Potential_draw(self)
7311
7312    def __add__(self, *args) -> "pyAgrum.Potential":
7313        return _pyAgrum.Potential___add__(self, *args)
7314
7315    def __sub__(self, *args) -> "pyAgrum.Potential":
7316        return _pyAgrum.Potential___sub__(self, *args)
7317
7318    def __mul__(self, *args) -> "pyAgrum.Potential":
7319        return _pyAgrum.Potential___mul__(self, *args)
7320
7321    def __truediv__(self, *args):
7322        return _pyAgrum.Potential___truediv__(self, *args)
7323    __div__ = __truediv__
7324
7325
7326
7327    def __iadd__(self, *args) -> "pyAgrum.Potential":
7328        return _pyAgrum.Potential___iadd__(self, *args)
7329
7330    def __imul__(self, *args) -> "pyAgrum.Potential":
7331        return _pyAgrum.Potential___imul__(self, *args)
7332
7333    def __isub__(self, *args) -> "pyAgrum.Potential":
7334        return _pyAgrum.Potential___isub__(self, *args)
7335
7336    def __itruediv__(self, *args):
7337        return _pyAgrum.Potential___itruediv__(self, *args)
7338    __idiv__ = __itruediv__
7339
7340
7341
7342    def __repr__(self) -> str:
7343        return _pyAgrum.Potential___repr__(self)
7344
7345    def __str__(self) -> str:
7346        return _pyAgrum.Potential___str__(self)
7347
7348    def extract(self, *args) -> "pyAgrum.Potential":
7349        r"""
7350
7351        create a new Potential extracted from self given a partial instantiation.
7352
7353        Parameters
7354        ----------
7355        inst : pyAgrum.instantiation
7356          a partial instantiation
7357        dict : Dict[str,str|int]
7358          a dictionnary containing values for some discrete variables.
7359
7360        Returns
7361        -------
7362        pyAgrum.Potential
7363          the new Potential
7364
7365        """
7366        return _pyAgrum.Potential_extract(self, *args)
7367
7368    def margSumOut(self, varnames: object) -> "pyAgrum.Potential":
7369        r"""
7370
7371        Projection using sum as operation.
7372
7373        Parameters
7374        ----------
7375        varnames : set
7376          the set of vars to eliminate
7377
7378        Returns
7379        -------
7380        pyAgrum.Potential
7381          the projected Potential
7382
7383        Raises
7384        ------
7385        pyAgrum.InvalidArgument
7386          If varnames contains only one variable that does not exist in the Potential
7387
7388        """
7389        return _pyAgrum.Potential_margSumOut(self, varnames)
7390
7391    def margProdOut(self, varnames: object) -> "pyAgrum.Potential":
7392        r"""
7393
7394        Projection using multiplication as operation.
7395
7396        Parameters
7397        ----------
7398        varnames : set
7399          the set of vars to eliminate
7400
7401        Returns
7402        -------
7403        pyAgrum.Potential
7404          the projected Potential
7405
7406        Raises
7407        ------
7408        pyAgrum.InvalidArgument
7409          If varnames contains only one variable that does not exist in the Potential
7410
7411        """
7412        return _pyAgrum.Potential_margProdOut(self, varnames)
7413
7414    def margMaxOut(self, varnames: object) -> "pyAgrum.Potential":
7415        r"""
7416
7417        Projection using max as operation.
7418
7419        Parameters
7420        ----------
7421        varnames : set
7422          the set of vars to eliminate
7423
7424        Returns
7425        -------
7426        pyAgrum.Potential
7427          the projected Potential
7428
7429        Raises
7430        ------
7431        pyAgrum.InvalidArgument
7432          If varnames contains only one variable that does not exist in the Potential
7433
7434        """
7435        return _pyAgrum.Potential_margMaxOut(self, varnames)
7436
7437    def margMinOut(self, varnames: object) -> "pyAgrum.Potential":
7438        r"""
7439
7440        Projection using min as operation.
7441
7442        Parameters
7443        ----------
7444        varnames : set
7445          the set of vars to eliminate
7446
7447        Returns
7448        -------
7449        pyAgrum.Potential
7450          the projected Potential
7451
7452        Warnings
7453        --------
7454        InvalidArgument raised if varnames contains only one variable that does not exist in the Potential
7455
7456        """
7457        return _pyAgrum.Potential_margMinOut(self, varnames)
7458
7459    def margSumIn(self, varnames: object) -> "pyAgrum.Potential":
7460        r"""
7461
7462        Projection using sum as operation.
7463
7464        Parameters
7465        ----------
7466        varnames : set
7467          the set of vars to keep
7468
7469        Returns
7470        -------
7471        pyAgrum.Potential
7472          the projected Potential
7473
7474        """
7475        return _pyAgrum.Potential_margSumIn(self, varnames)
7476
7477    def margProdIn(self, varnames: object) -> "pyAgrum.Potential":
7478        r"""
7479
7480        Projection using multiplication as operation.
7481
7482        Parameters
7483        ----------
7484        varnames : set
7485          the set of vars to keep
7486
7487        Returns
7488        -------
7489        pyAgrum.Potential
7490          the projected Potential
7491
7492        """
7493        return _pyAgrum.Potential_margProdIn(self, varnames)
7494
7495    def margMaxIn(self, varnames: object) -> "pyAgrum.Potential":
7496        r"""
7497
7498        Projection using max as operation.
7499
7500        Parameters
7501        ----------
7502        varnames : set
7503          the set of vars to keep
7504
7505        Returns
7506        -------
7507        pyAgrum.Potential
7508          the projected Potential
7509
7510        """
7511        return _pyAgrum.Potential_margMaxIn(self, varnames)
7512
7513    def margMinIn(self, varnames: object) -> "pyAgrum.Potential":
7514        r"""
7515
7516        Projection using min as operation.
7517
7518        Parameters
7519        ----------
7520        varnames : set
7521          the set of vars to keep
7522
7523        Returns
7524        -------
7525        pyAgrum.Potential
7526          the projected Potential
7527
7528        """
7529        return _pyAgrum.Potential_margMinIn(self, varnames)
7530
7531    def __eq__(self, *args) -> bool:
7532        return _pyAgrum.Potential___eq__(self, *args)
7533
7534    def __ne__(self, *args) -> bool:
7535        return _pyAgrum.Potential___ne__(self, *args)
7536
7537    def __radd__(self,other):
7538      return self.__add__(other)
7539
7540    def __rmul__(self,other):
7541      return self.__mul__(other)
7542
7543    def __rsub__(self,other):
7544      return (self*-1)+other
7545
7546    def __rfloordiv__(self,other):
7547      return Potential(self).inverse().scale(other)
7548
7549    def __rtruediv__(self,other):
7550      return Potential(self).inverse().scale(other)
7551
7552    def __rdiv__(self,other):
7553      return Potential(self).inverse().scale(other)
7554
7555    def __neg__(self):
7556      return -1*self
7557
7558    def __abs__(self):
7559      return Potential(self).abs()
7560
7561    def loopIn(self):
7562      """
7563      Generator to iterate inside a Potential.
7564
7565      Yield an gum.Instantiation that iterates over all the possible values for the gum.Potential
7566
7567      Examples
7568      --------
7569      >>> import pyAgrum as gum
7570      >>> bn=gum.fastBN("A[3]->B[3]<-C[3]")
7571      >>> for i in bn.cpt("B").loopIn():
7572            print(i)
7573            print(bn.cpt("B").get(i))
7574            bn.cpt("B").set(i,0.3)
7575      """
7576      i=Instantiation(self)
7577      i.setFirst()
7578      while not i.end():
7579        yield i
7580        i.inc()
7581      return
7582
7583    def fillWithFunction(self,s,noise=None):
7584      """
7585      Automatically fills the potential as a (quasi) deterministic CPT with the evaluation of the expression s.
7586
7587      The expression s gives a value for the first variable using the names of the last variables.
7588      The computed CPT is deterministic unless noise is used to add a 'probabilistic' noise around the exact value given by the expression.
7589
7590
7591      Examples
7592      --------
7593      >>> import pyAgrum as gum
7594      >>> bn=gum.fastBN("A[3]->B[3]<-C[3]")
7595      >>> bn.cpt("B").fillWithFunction("(A+C)/2")
7596
7597      Parameters
7598      ----------
7599      s : str
7600          an expression using the name of the last variables of the Potential and giving a value to the first variable of the Potential
7601      noise : list
7602          an (odd) list of numerics giving a pattern of 'probabilistic noise' around the value.
7603
7604      Warning
7605      -------
7606          The expression may have any numerical values, but will be then transformed to the closest correct value for the range of the variable.
7607
7608      Returns
7609      -------
7610      pyAgrum.Potential
7611            a reference to the modified potential
7612
7613      Raises
7614      ------
7615      gum.InvalidArgument
7616        If the first variable is Labelized or Integer, or if the len of the noise is not odd.
7617      """
7618      if self.variable(0).varType()==VarType_Labelized:
7619        raise InvalidArgument("[pyAgrum] The variable "+self.variable(0).name()+" is a LabelizedVariable")
7620      if self.variable(0).varType()==VarType_Integer:
7621        raise InvalidArgument("[pyAgrum] The variable "+self.variable(0).name()+" is neither Range nor Discretized variable.")
7622
7623      if noise==None:
7624        mid=0
7625      else:
7626        if len(noise)%2==0:
7627          raise InvalidArgument("[pyAgrum] len(noise) must not be even")
7628        mid=int((len(noise)-1)/2)
7629
7630      self.fillWith(0)
7631      mi=self.variable(0).numerical(0)
7632      ma=self.variable(0).numerical(self.variable(0).domainSize()-1)
7633
7634      I=Instantiation(self)
7635
7636      I.setFirst()
7637      while not I.end():
7638        vars={self.variable(i).name():self.variable(i).numerical(I.val(i)) for i in range(1,self.nbrDim())}
7639        res=eval(s,None,vars)
7640        if res<mi:
7641          res=mi
7642        if res>ma:
7643          res=ma
7644        pos=self.variable(0).index(str(res))
7645        if mid==0:
7646          I.chgVal(0,pos)
7647          self.set(I,1)
7648        else:
7649          for i,v in enumerate(noise):
7650            if 0<=pos+i-mid<self.variable(0).domainSize():
7651              I.chgVal(0,pos+i-mid)
7652              self.set(I,v)
7653        I.incNotVar(self.variable(0))
7654      self.normalizeAsCPT()
7655      return self
7656
7657    def variablesSequence(self):
7658        """
7659        Returns
7660        -------
7661        list
7662            a list containing the sequence of variables
7663        """
7664        varlist = []
7665        for i in range(0, self.nbrDim()):
7666            varlist.append(self.variable(i))
7667        return varlist
7668
7669    def __prepareIndices__(self,ind):
7670      """
7671      From an indice (dict or tuple), returns a pair of gum.Instantiation to loop in a part of the Potential.
7672      """
7673      loopvars=Instantiation(self)
7674      loopvars.setMutable()
7675
7676      inst=Instantiation(self)
7677      inst.setFirst()
7678
7679      if isinstance(ind, (Number,slice)):
7680        i = tuple([ind])
7681      else:
7682        i = ind
7683
7684      vn=self.var_names
7685      if isinstance(i,dict):
7686          for nam in vn:
7687              if nam in i:
7688                  inst.chgVal(nam,i[nam])
7689                  loopvars.erase(nam)
7690      elif isinstance(i,tuple):
7691          if len(i)>self.nbrDim():
7692              raise KeyError("Too many values in '"+str(i)+"' for '"+str(self)+"'")
7693          for k,v in enumerate(i):
7694              if not isinstance(v,slice):
7695                  nam=vn[k]
7696                  inst.chgVal(nam,v)
7697                  loopvars.erase(nam)
7698      else:
7699          raise ValueError("No subscript using '"+str(i)+"'")
7700      return inst,loopvars
7701
7702    def __getitem__(self, id):
7703      if isinstance(id,Instantiation):
7704          return self.get(id)
7705
7706      inst,loopvars=self.__prepareIndices__(id)
7707
7708      if loopvars.nbrDim()==0:
7709          return self.get(inst)
7710
7711      if loopvars.nbrDim()==self.nbrDim():
7712        content=[]
7713
7714        inst=Instantiation(self)
7715        while not inst.end():
7716            content.append(self.get(inst))
7717            inst.inc()
7718        tab=numpy.array(content,dtype=numpy.float64)
7719        tab.shape=tuple(self.var_dims)
7720        return tab
7721
7722      names=[loopvars.variable(i-1).name() for i in range(loopvars.nbrDim(),0,-1)]
7723      tab=numpy.zeros(tuple([loopvars.variable(i-1).domainSize() for i in range(loopvars.nbrDim(),0,-1)]))
7724      while not inst.end():
7725          indice=[inst.val(name) for name in names]
7726          tab[tuple(indice)]=self.get(inst)
7727          inst.incIn(loopvars)
7728      return tab
7729
7730    def __setitem__(self, id, value):
7731      if isinstance(id,Instantiation):
7732          self.set(id,value)
7733          return
7734
7735      inst,loopvars=self.__prepareIndices__(id)
7736
7737      if loopvars.nbrDim()==0:
7738          self.set(inst,value)
7739          return
7740
7741      if isinstance(value,Number):
7742        while not inst.end():
7743            self.set(inst,value)
7744            inst.incIn(loopvars)
7745      else:
7746        if isinstance(value,list):
7747            value=numpy.array(value)
7748
7749        shape=tuple([loopvars.variable(i-1).domainSize() for i in range(loopvars.nbrDim(),0,-1)])
7750        if value.shape!=shape:
7751          raise IndexError("Shape of '"+str(value)+"' is not '"+str(shape)+"'")
7752
7753        names = [loopvars.variable(i - 1).name() for i in range(loopvars.nbrDim(), 0, -1)]
7754        while not inst.end():
7755            indice = tuple([inst.val(name) for name in names])
7756            self.set(inst,float(value[indice]))
7757            inst.incIn(loopvars)
7758
7759    def tolist(self):
7760        """
7761        Returns
7762        -------
7763        list
7764            the potential as a list
7765        """
7766        return self.__getitem__({}).tolist()
7767
7768    def toarray(self):
7769        """
7770        Returns
7771        -------
7772        array
7773            the potential as an array
7774        """
7775        return self.__getitem__({})
7776
7777    def topandas(self):
7778        """
7779        Returns
7780        -------
7781        pandas.DataFrame
7782           the potential as an pandas.DataFrame
7783        """
7784        import pandas as pd
7785        varnames = self.var_names
7786        data = []
7787        pname = ""
7788        for inst in self.loopIn():
7789            d = {k:v for k,v in reversed(inst.todict(True).items())}
7790            d[pname] = self.get(inst)
7791            d[pname], d[varnames[-1]] = d[varnames[-1]], d[pname]
7792            data.append(d)
7793        cols = varnames[:-1] + [pname]
7794        return pd.DataFrame(data).set_index(cols).unstack(pname)
7795
7796    def tolatex(self):
7797        """
7798        Render object to a LaTeX tabular.
7799
7800        Requires to include `booktabs` package in the LaTeX document.
7801
7802        Returns
7803        -------
7804        str
7805         the potential as LaTeX string
7806        """
7807        return self.topandas().to_latex()
7808
7809    def toclipboard(self,**kwargs):
7810        """
7811        Write a text representation of object to the system clipboard. This can be pasted into spreadsheet, for instance.
7812        """
7813        return self.topandas().to_clipboard()
7814
7815    @property
7816    def var_names(self):
7817        """
7818        Returns
7819        -------
7820        list
7821            a list containing the name of each variables in the potential
7822
7823        Warnings
7824        --------
7825            listed in the reverse order of the enumeration order of the variables.
7826        """
7827        return [self.variable(i-1).name() for i in range(self.nbrDim(),0,-1)]
7828
7829    @property
7830    def var_dims(self):
7831        """
7832        Returns
7833        -------
7834        list
7835            a list containing the dimensions of each variables in the potential
7836        """
7837        return [self.variable(i-1).domainSize() for i in range(self.nbrDim(),0,-1)]
7838
7839
7840    def get(self, i: "Instantiation") -> float:
7841        r"""
7842
7843        Parameters
7844        ----------
7845        i : pyAgrum.Instantiation
7846          an Instantiation
7847
7848        Returns
7849        -------
7850        float
7851          the value in the Potential at the position given by the instantiation
7852
7853        """
7854        return _pyAgrum.Potential_get(self, i)
7855
7856    def set(self, i: "Instantiation", value: float) -> None:
7857        r"""
7858
7859        Change the value pointed by i
7860
7861        Parameters
7862        ----------
7863        i : pyAgrum.Instantiation
7864          The Instantiation to be changed
7865        value : float
7866          The new value of the Instantiation
7867
7868        """
7869        return _pyAgrum.Potential_set(self, i, value)
7870
7871    def empty(self) -> bool:
7872        r"""
7873
7874        Returns
7875        -------
7876        bool
7877            Returns true if no variable is in the potential.
7878
7879        """
7880        return _pyAgrum.Potential_empty(self)
7881
7882    def pos(self, v: "pyAgrum.DiscreteVariable") -> int:
7883        r"""
7884
7885        Parameters
7886        ----------
7887        v : pyAgrum.DiscreteVariable
7888            The variable for which the index is returned.
7889
7890        Returns
7891        -------
7892            Returns the index of a variable.
7893
7894        Raises
7895        ------
7896        pyAgrum.NotFound
7897          If v is not in this multidimensional matrix.
7898
7899        """
7900        return _pyAgrum.Potential_pos(self, v)
7901
7902    def contains(self, v: "pyAgrum.DiscreteVariable") -> bool:
7903        r"""
7904
7905        Parameters
7906        ----------
7907        v : pyAgrum.Potential
7908            a DiscreteVariable.
7909
7910        Returns
7911        -------
7912        bool
7913            True if the var is in the potential
7914
7915        """
7916        return _pyAgrum.Potential_contains(self, v)
7917
7918    def variable(self, *args) -> "pyAgrum.DiscreteVariable":
7919        r"""
7920
7921        Parameters
7922        ----------
7923        i : int
7924          An index of this multidimensional matrix.
7925
7926        Returns
7927        -------
7928          the varible at the ith index
7929
7930        Raises
7931        ------
7932        pyAgrum.NotFound
7933          If i does not reference a variable in this multidimensional matrix.
7934
7935        """
7936        return _pyAgrum.Potential_variable(self, *args)
7937
7938    def remove(self, var: "pyAgrum.DiscreteVariable") -> None:
7939        r"""
7940
7941        Parameters
7942        ----------
7943        v : pyAgrum.DiscreteVariable
7944            The variable to be removed
7945
7946        Returns
7947        -------
7948        pyAgrum.Potential
7949          a reference to the modified potential
7950
7951        Warnings
7952        --------
7953        IndexError raised if the var is not in the potential
7954
7955        """
7956        val = _pyAgrum.Potential_remove(self, var)
7957
7958        self._list_vars.remove(var)
7959
7960
7961        return val
7962
7963
7964    def add(self, v: "pyAgrum.DiscreteVariable") -> None:
7965        r"""
7966
7967        Add a discrete variable to the potential.
7968
7969        Parameters
7970        ----------
7971        v : pyAgrum.DiscreteVariable
7972          the var to be added
7973
7974        Raises
7975        ------
7976        DuplicateElement
7977          If the variable is already in this Potential.
7978        InvalidArgument
7979          If the variable is empty.
7980
7981        """
7982        val = _pyAgrum.Potential_add(self, v)
7983
7984        self._list_vars.append(v)
7985        return self
7986
7987
7988        return val
7989
7990
7991    def domainSize(self) -> int:
7992        return _pyAgrum.Potential_domainSize(self)
7993
7994    def nbrDim(self, *args) -> int:
7995        r"""
7996
7997        Returns
7998        -------
7999        int
8000          the number of vars in the multidimensional container.
8001
8002        """
8003        return _pyAgrum.Potential_nbrDim(self, *args)
8004
8005# Register Potential in _pyAgrum:
8006_pyAgrum.Potential_swigregister(Potential)
8007
8008class IBayesNet(DAGmodel):
8009    r"""
8010
8011    Abstract class used by BayesNet.
8012
8013    """
8014
8015    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
8016
8017    def __init__(self, *args, **kwargs):
8018        raise AttributeError("No constructor defined - class is abstract")
8019    __swig_destroy__ = _pyAgrum.delete_IBayesNet
8020
8021    def cpt(self, varId: int) -> "pyAgrum.Potential":
8022        r"""
8023
8024        Returns the CPT of a variable.
8025
8026        Parameters
8027        ----------
8028        VarId : int
8029        	A variable's id in the pyAgrum.IBayesNet.
8030        name : str
8031        	A variable's name in the pyAgrum.IBayesNet.
8032
8033        Returns
8034        -------
8035        pyAgrum.Potential
8036        	The variable's CPT.
8037
8038        Raises
8039        ------
8040        pyAgrum.NotFound
8041        	If no variable's id matches varId.
8042
8043        """
8044        return _pyAgrum.IBayesNet_cpt(self, varId)
8045
8046    def variableNodeMap(self) -> "pyAgrum.VariableNodeMap":
8047        r"""
8048
8049        Returns
8050        -------
8051        pyAgrum.variableNodeMap
8052        	the variable node map
8053
8054        """
8055        return _pyAgrum.IBayesNet_variableNodeMap(self)
8056
8057    def variable(self, id: int) -> "pyAgrum.DiscreteVariable":
8058        r"""
8059
8060        Parameters
8061        ----------
8062        id : int
8063        	a variable's id
8064        name : str
8065        	a variable's name
8066
8067        Returns
8068        -------
8069        pyAgrum.DiscreteVariable
8070        	the variable
8071
8072        Raises
8073        ------
8074        pyAgrum.IndexError
8075        	If the graph does not contain the variable
8076
8077        """
8078        return _pyAgrum.IBayesNet_variable(self, id)
8079
8080    def nodeId(self, var: "pyAgrum.DiscreteVariable") -> int:
8081        r"""
8082
8083        Parameters
8084        ----------
8085        var : pyAgrum.DiscreteVariable
8086        	a variable
8087
8088        Returns
8089        -------
8090        int
8091        	the id of the variable
8092
8093        Raises
8094        ------
8095        pyAgrum.IndexError
8096        	If the graph does not contain the variable
8097
8098        """
8099        return _pyAgrum.IBayesNet_nodeId(self, var)
8100
8101    def idFromName(self, name: str) -> int:
8102        r"""
8103
8104        Returns a variable's id given its name in the graph.
8105
8106        Parameters
8107        ----------
8108        name : str
8109        	The variable's name from which the id is returned.
8110
8111        Returns
8112        -------
8113        int :
8114        	The variable's node id.
8115
8116        Raises
8117        ------
8118        pyAgrum.NotFound
8119        	If name does not match a variable in the graph
8120
8121        """
8122        return _pyAgrum.IBayesNet_idFromName(self, name)
8123
8124    def variableFromName(self, name: str) -> "pyAgrum.DiscreteVariable":
8125        r"""
8126
8127        Parameters
8128        ----------
8129        name : str
8130        	a variable's name
8131
8132        Returns
8133        -------
8134        pyAgrum.DiscreteVariable
8135        	the variable
8136
8137        Raises
8138        ------
8139        pyAgrum.IndexError
8140        	If the graph does not contain the variable
8141
8142        """
8143        return _pyAgrum.IBayesNet_variableFromName(self, name)
8144
8145    def jointProbability(self, i: "Instantiation") -> float:
8146        r"""
8147
8148        Parameters
8149        ----------
8150        i : pyAgrum.instantiation
8151        	an instantiation of the variables
8152
8153        Returns
8154        -------
8155        float
8156        	a parameter of the joint probability for the BayesNet
8157
8158        Warnings
8159        --------
8160        a variable not present in the instantiation is assumed to be instantiated to 0
8161
8162        """
8163        return _pyAgrum.IBayesNet_jointProbability(self, i)
8164
8165    def log2JointProbability(self, i: "Instantiation") -> float:
8166        r"""
8167
8168        Parameters
8169        ----------
8170        i : pyAgrum.instantiation
8171        	an instantiation of the variables
8172
8173        Returns
8174        -------
8175        float
8176        	a parameter of the log joint probability for the BayesNet
8177
8178        Warnings
8179        --------
8180        a variable not present in the instantiation is assumed to be instantiated to 0
8181
8182        """
8183        return _pyAgrum.IBayesNet_log2JointProbability(self, i)
8184
8185    def __eq__(self, _from: "IBayesNet") -> bool:
8186        return _pyAgrum.IBayesNet___eq__(self, _from)
8187
8188    def __ne__(self, _from: "IBayesNet") -> bool:
8189        return _pyAgrum.IBayesNet___ne__(self, _from)
8190
8191    def dim(self) -> int:
8192        r"""
8193
8194        Returns the dimension (the number of free parameters) in this BayesNet.
8195
8196        Returns
8197        -------
8198        int
8199        	the dimension of the BayesNet
8200
8201        """
8202        return _pyAgrum.IBayesNet_dim(self)
8203
8204    def maxVarDomainSize(self) -> int:
8205        r"""
8206
8207        Returns
8208        -------
8209        int
8210        	the biggest domain size among the variables of the BayesNet
8211
8212        """
8213        return _pyAgrum.IBayesNet_maxVarDomainSize(self)
8214
8215    def minParam(self) -> float:
8216        r"""
8217
8218        Returns
8219        -------
8220        float
8221            the smallest value in the CPTs of the IBayesNet
8222
8223        """
8224        return _pyAgrum.IBayesNet_minParam(self)
8225
8226    def maxParam(self) -> float:
8227        r"""
8228
8229        Returns
8230        -------
8231        float
8232            the biggest value in the CPTs of the BayesNet
8233
8234        """
8235        return _pyAgrum.IBayesNet_maxParam(self)
8236
8237    def minNonZeroParam(self) -> float:
8238        r"""
8239
8240        Returns
8241        -------
8242        float
8243            the smallest value (not equal to 0) in the CPTs of the IBayesNet
8244
8245        """
8246        return _pyAgrum.IBayesNet_minNonZeroParam(self)
8247
8248    def maxNonOneParam(self) -> float:
8249        r"""
8250
8251        Returns
8252        -------
8253        float
8254        	The biggest value (not equal to 1) in the CPTs of the BayesNet
8255
8256        """
8257        return _pyAgrum.IBayesNet_maxNonOneParam(self)
8258
8259    def toDot(self) -> str:
8260        r"""
8261
8262        Returns
8263        -------
8264        str
8265            a friendly display of the graph in DOT format
8266
8267        """
8268        return _pyAgrum.IBayesNet_toDot(self)
8269
8270    def minimalCondSet(self, *args) -> object:
8271        r"""
8272
8273        Returns, given one or many targets and a list of variables, the minimal set of those needed to calculate the target/targets.
8274
8275        Parameters
8276        ----------
8277        target : int
8278        	The id of the target
8279        targets : list
8280        	The ids of the targets
8281        list : list
8282        	The list of available variables
8283
8284        Returns
8285        -------
8286        Set
8287        	The minimal set of variables
8288
8289        """
8290        return _pyAgrum.IBayesNet_minimalCondSet(self, *args)
8291
8292    def isIndependent(self, *args) -> bool:
8293        return _pyAgrum.IBayesNet_isIndependent(self, *args)
8294
8295    def names(self) -> object:
8296        r"""
8297
8298        Returns
8299        -------
8300        list
8301        	The names of the graph variables
8302
8303        """
8304        return _pyAgrum.IBayesNet_names(self)
8305
8306    def nodes(self) -> object:
8307        r"""
8308
8309        Returns
8310        -------
8311        set
8312            the set of ids
8313
8314        """
8315        return _pyAgrum.IBayesNet_nodes(self)
8316
8317    def connectedComponents(self):
8318      """ connected components from a graph/BN
8319
8320      Compute the connected components of a pyAgrum's graph or Bayesian Network
8321      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
8322
8323      The firstly visited node for each component is called a 'root' and is used as a key for the component.
8324      This root has been arbitrarily chosen during the algorithm.
8325
8326      Returns
8327      -------
8328      dict(int,Set[int])
8329        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
8330
8331      """
8332      nodes=self.nodes()
8333      connected_components=dict()
8334
8335      def parcours(node,orig):
8336          cc={node}
8337          nodes.discard(node)
8338          if hasattr(self,'children'):
8339              for chi in self.children(node):
8340                  if chi!=orig:
8341                      if chi in nodes:
8342                          cc|=parcours(chi,node)
8343
8344          if hasattr(self,'parents'):
8345              for par in self.parents(node):
8346                  if par!=orig:
8347                      if par in nodes:
8348                          cc|=parcours(par,node)
8349
8350          if hasattr(self,'neighbours'):
8351              for nei in self.neighbours(node):
8352                  if nei!=orig:
8353                      if nei in nodes:
8354                          cc|=parcours(nei,node)
8355          return cc
8356
8357      while (len(nodes)>0):
8358          root=nodes.pop()
8359          connected_components[root]=parcours(root,None)
8360      return connected_components
8361
8362
8363    def arcs(self) -> object:
8364        r"""
8365
8366        Returns
8367        -------
8368        list
8369        	The lisf of arcs in the IBayesNet
8370
8371        """
8372        return _pyAgrum.IBayesNet_arcs(self)
8373
8374    def parents(self, norid: object) -> object:
8375        r"""
8376
8377        Parameters
8378        ----------
8379        id :
8380        	The id of the child node
8381
8382        Returns
8383        -------
8384        Set
8385            the set of the parents ids.
8386
8387        """
8388        return _pyAgrum.IBayesNet_parents(self, norid)
8389
8390    def children(self, norid: object) -> object:
8391        r"""
8392
8393        Parameters
8394        ----------
8395        id : int
8396          the id of the parent
8397
8398        Returns
8399        -------
8400        Set
8401        	the set of all the children
8402
8403        """
8404        return _pyAgrum.IBayesNet_children(self, norid)
8405
8406    def family(self, norid: object) -> object:
8407        return _pyAgrum.IBayesNet_family(self, norid)
8408
8409    def descendants(self, norid: object) -> object:
8410        return _pyAgrum.IBayesNet_descendants(self, norid)
8411
8412    def ancestors(self, norid: object) -> object:
8413        return _pyAgrum.IBayesNet_ancestors(self, norid)
8414
8415    def moralizedAncestralGraph(self, nodes: object) -> "pyAgrum.UndiGraph":
8416        return _pyAgrum.IBayesNet_moralizedAncestralGraph(self, nodes)
8417
8418    def __repr__(self) -> str:
8419        return _pyAgrum.IBayesNet___repr__(self)
8420
8421    def __str__(self) -> str:
8422        return _pyAgrum.IBayesNet___str__(self)
8423
8424# Register IBayesNet in _pyAgrum:
8425_pyAgrum.IBayesNet_swigregister(IBayesNet)
8426
8427class BayesNet(IBayesNet):
8428    r"""
8429
8430    BayesNet represents a Bayesian network.
8431
8432    BayesNet(name='') -> BayesNet
8433        Parameters:
8434          * **name** (*str*) -- the name of the Bayes Net
8435
8436    BayesNet(source) -> BayesNet
8437        Parameters:
8438          * **source** (*pyAgrum.BayesNet*) -- the Bayesian network to copy
8439
8440    """
8441
8442    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
8443
8444    @staticmethod
8445    def fastPrototype(dotlike: str, domainSize: int=2) -> "pyAgrum.BayesNet":
8446        r"""
8447
8448        Create a Bayesian network with a dot-like syntax which specifies:
8449            - the structure 'a->b->c;b->d<-e;'.
8450            - the type of the variables with different syntax:
8451
8452              - by default, a variable is a pyAgrum.RangeVariable using the default domain size (second argument)
8453              - with 'a[10]', the variable is a pyAgrum.RangeVariable using 10 as domain size (from 0 to 9)
8454              - with 'a[3,7]', the variable is a pyAgrum.RangeVariable using a domainSize from 3 to 7
8455              - with 'a[1,3.14,5,6.2]', the variable is a pyAgrum.DiscretizedVariable using the given ticks (at least 3 values)
8456              - with 'a{top|middle|bottom}', the variable is a pyAgrum.LabelizedVariable using the given labels.
8457              - with 'a{-1|5|0|3}', the variable is a pyAgrum.IntegerVariable using the sorted given values.
8458
8459        Note
8460        ----
8461          - If the dot-like string contains such a specification more than once for a variable, the first specification will be used.
8462          - the CPTs are randomly generated.
8463          - see also pyAgrum.fastBN.
8464
8465        Examples
8466        --------
8467        >>> import pyAgrum as gum
8468        >>> bn=pyAgrum.BayesNet.fastPrototype('A->B[1,3]<-C{yes|No}->D[2,4]<-E[1,2.5,3.9]',6)
8469
8470        Parameters
8471        ----------
8472        dotlike : str
8473                the string containing the specification
8474        domainSize : int
8475                the default domain size for variables
8476
8477        Returns
8478        -------
8479        pyAgrum.BayesNet
8480                the resulting Bayesian network
8481
8482        """
8483        return _pyAgrum.BayesNet_fastPrototype(dotlike, domainSize)
8484    __swig_destroy__ = _pyAgrum.delete_BayesNet
8485
8486    def __init__(self, *args):
8487        _pyAgrum.BayesNet_swiginit(self, _pyAgrum.new_BayesNet(*args))
8488
8489    def cpt(self, *args) -> "pyAgrum.Potential":
8490        r"""
8491
8492        Returns the CPT of a variable.
8493
8494        Parameters
8495        ----------
8496        VarId : int
8497        	A variable's id in the pyAgrum.BayesNet.
8498        name : str
8499        	A variable's name in the pyAgrum.BayesNet.
8500
8501        Returns
8502        -------
8503        pyAgrum.Potential
8504        	The variable's CPT.
8505
8506        Raises
8507        ------
8508        pyAgrum.NotFound
8509            If no variable's id matches varId.
8510
8511        """
8512        return _pyAgrum.BayesNet_cpt(self, *args)
8513
8514    def variableNodeMap(self) -> "pyAgrum.VariableNodeMap":
8515        r"""
8516
8517        Returns
8518        -------
8519        pyAgrum.variableNodeMap
8520        	the variable node map
8521
8522        """
8523        return _pyAgrum.BayesNet_variableNodeMap(self)
8524
8525    def add(self, *args) -> int:
8526        r"""
8527
8528        Add a variable to the pyAgrum.BayesNet.
8529
8530        Parameters
8531        ----------
8532        variable : pyAgrum.DiscreteVariable
8533        	the variable added
8534        name : str
8535        	the variable name
8536        nbrmod : int
8537        	the number of modalities for the new variable
8538        id : int
8539        	the variable forced id in the pyAgrum.BayesNet
8540
8541        Returns
8542        -------
8543        int
8544        	the id of the new node
8545
8546        Raises
8547        ------
8548        pyAgrum.DuplicateLabel
8549            If variable.name() is already used in this pyAgrum.BayesNet.
8550        pyAgrum.NotAllowed
8551            If nbrmod is less than 2
8552        pyAgrum.DuplicateElement
8553            If id is already used.
8554
8555        """
8556        return _pyAgrum.BayesNet_add(self, *args)
8557
8558    def clear(self) -> None:
8559        r"""
8560
8561        Clear the whole BayesNet
8562
8563        """
8564        return _pyAgrum.BayesNet_clear(self)
8565
8566    def erase(self, *args) -> None:
8567        r"""
8568
8569        Remove a variable from the pyAgrum.BayesNet.
8570
8571        Removes the corresponding variable from the pyAgrum.BayesNet and from all of it's children pyAgrum.Potential.
8572
8573        If no variable matches the given id, then nothing is done.
8574
8575        Parameters
8576        ----------
8577        id : int
8578        	The variable's id to remove.
8579        name : str
8580        	The variable's name to remove.
8581        var : pyAgrum.DiscreteVariable
8582        	A reference on the variable to remove.
8583
8584        """
8585        return _pyAgrum.BayesNet_erase(self, *args)
8586
8587    def variable(self, *args) -> "pyAgrum.DiscreteVariable":
8588        r"""
8589
8590        Parameters
8591        ----------
8592        id : int
8593        	a variable's id
8594        name : str
8595        	a variable's name
8596
8597        Returns
8598        -------
8599        pyAgrum.DiscreteVariable
8600        	the variable
8601
8602        Raises
8603        ------
8604        pyAgrum.IndexError
8605        	If the graph does not contain the variable
8606
8607        """
8608        return _pyAgrum.BayesNet_variable(self, *args)
8609
8610    def changeVariableName(self, *args) -> None:
8611        r"""
8612
8613        Changes a variable's name in the pyAgrum.BayesNet.
8614
8615        This will change the "pyAgrum.DiscreteVariable" names in the pyAgrum.BayesNet.
8616
8617        Parameters
8618        ----------
8619        new_name : str
8620        	the new name of the variable
8621        NodeId : int
8622        	the id of the node
8623        name : str
8624        	the name of the variable
8625
8626        Raises
8627        ------
8628        pyAgrum.DuplicateLabel
8629            If new_name is already used in this BayesNet.
8630        pyAgrum.NotFound
8631            If no variable matches id.
8632
8633        """
8634        return _pyAgrum.BayesNet_changeVariableName(self, *args)
8635
8636    def changeVariableLabel(self, *args) -> None:
8637        r"""
8638
8639        change the label of the variable associated to nodeId to the new value.
8640
8641        Parameters
8642        ----------
8643        id : int
8644        	the id of the node
8645        name : str
8646        	the name of the variable
8647        old_label : str
8648        	the new label
8649        new_label : str
8650        	the new label
8651
8652        Raises
8653        ------
8654        pyAgrum.NotFound
8655            if id/name is not a variable or if old_label does not exist.
8656
8657        """
8658        return _pyAgrum.BayesNet_changeVariableLabel(self, *args)
8659
8660    def nodeId(self, var: "pyAgrum.DiscreteVariable") -> int:
8661        r"""
8662
8663        Parameters
8664        ----------
8665        var : pyAgrum.DiscreteVariable
8666        	a variable
8667
8668        Returns
8669        -------
8670        int
8671        	the id of the variable
8672
8673        Raises
8674        ------
8675        pyAgrum.IndexError
8676        	If the graph does not contain the variable
8677
8678        """
8679        return _pyAgrum.BayesNet_nodeId(self, var)
8680
8681    def idFromName(self, name: str) -> int:
8682        r"""
8683
8684        Returns a variable's id given its name in the graph.
8685
8686        Parameters
8687        ----------
8688        name : str
8689        	The variable's name from which the id is returned.
8690
8691        Returns
8692        -------
8693        int :
8694        	The variable's node id.
8695
8696        Raises
8697        ------
8698        pyAgrum.NotFound
8699        	If name does not match a variable in the graph
8700
8701        """
8702        return _pyAgrum.BayesNet_idFromName(self, name)
8703
8704    def variableFromName(self, name: str) -> "pyAgrum.DiscreteVariable":
8705        r"""
8706
8707        Parameters
8708        ----------
8709        name : str
8710        	a variable's name
8711
8712        Returns
8713        -------
8714        pyAgrum.DiscreteVariable
8715        	the variable
8716
8717        Raises
8718        ------
8719        pyAgrum.IndexError
8720        	If the graph does not contain the variable
8721
8722        """
8723        return _pyAgrum.BayesNet_variableFromName(self, name)
8724
8725    def addArc(self, *args) -> None:
8726        r"""
8727
8728        Add an arc in the BN, and update arc.head's CPT.
8729
8730        Parameters
8731        ----------
8732        head :
8733        	a variable's id (int)
8734        tail :
8735        	a variable's id (int)
8736        head :
8737        	a variable's name (str)
8738        tail :
8739        	a variable's name (str)
8740
8741        Raises
8742        ------
8743        pyAgrum.InvalidEdge
8744            If arc.tail and/or arc.head are not in the BN.
8745        pyAgrum.DuplicateElement
8746            If the arc already exists.
8747
8748        """
8749        return _pyAgrum.BayesNet_addArc(self, *args)
8750
8751    def eraseArc(self, *args) -> None:
8752        r"""
8753
8754        Removes an arc in the BN, and update head's CTP.
8755
8756        If (tail, head) doesn't exist, the nothing happens.
8757
8758        Parameters
8759        ----------
8760        arc : pyAgrum.Arc
8761        	The arc to be removed.
8762        head :
8763        	a variable's id (int)
8764        tail :
8765        	a variable's id (int)
8766        head :
8767        	a variable's name (str)
8768        tail :
8769        	a variable's name (str)
8770
8771        """
8772        return _pyAgrum.BayesNet_eraseArc(self, *args)
8773
8774    def beginTopologyTransformation(self) -> None:
8775        r"""
8776
8777        When inserting/removing arcs, node CPTs change their dimension with a cost in time.
8778        begin Multiple Change for all CPTs
8779        These functions delay the CPTs change to be done just once at the end of a sequence of topology modification, begins a sequence of insertions/deletions of arcs without changing the dimensions of the CPTs.
8780
8781        """
8782        return _pyAgrum.BayesNet_beginTopologyTransformation(self)
8783
8784    def endTopologyTransformation(self) -> None:
8785        r"""
8786
8787        Terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.
8788        End Multiple Change for all CPTs.
8789
8790        Returns
8791        -------
8792        pyAgrum.BayesNet
8793
8794        """
8795        return _pyAgrum.BayesNet_endTopologyTransformation(self)
8796
8797    def reverseArc(self, *args) -> None:
8798        r"""
8799
8800        Reverses an arc while preserving the same joint distribution.
8801
8802        Parameters
8803        ----------
8804        tail
8805        	(int) the id of the tail variable
8806        head
8807        	(int) the id of the head variable
8808        tail
8809        	(str) the name of the tail variable
8810        head
8811        	(str) the name of the head variable
8812        arc : pyAgrum.Arc
8813        	an arc
8814
8815        Raises
8816        ------
8817        pyAgrum.InvalidArc
8818            If the arc does not exsit or if its reversal would induce a directed cycle.
8819
8820        """
8821        return _pyAgrum.BayesNet_reverseArc(self, *args)
8822
8823    def addNoisyOR(self, *args) -> int:
8824        r"""
8825
8826        Add a variable, it's associate node and a noisyOR implementation.
8827
8828        Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the addNoisyOR as an alias for addNoisyORCompound.
8829
8830        (The id of the new variable can be automatically generated.)
8831
8832        Parameters
8833        ----------
8834        variable : pyAgrum.DiscreteVariable
8835        	The variable added by copy
8836        externalWeight : float
8837        	the added external weight
8838        id : int
8839        	The proposed id for the variable.
8840
8841        Returns
8842        -------
8843        int
8844        	the id of the added variable.
8845
8846        Raises
8847        --------
8848        pyAgrum.DuplicateElement
8849            If id is already used
8850
8851        """
8852        return _pyAgrum.BayesNet_addNoisyOR(self, *args)
8853
8854    def addNoisyORNet(self, *args) -> int:
8855        r"""
8856
8857        Add a variable, its associate node and a noisyOR implementation.
8858
8859        Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the addNoisyOR as an alias for addNoisyORCompound.
8860
8861        (The id of the new variable can be automatically generated.)
8862
8863        Parameters
8864        ----------
8865        variable : pyAgrum.DiscreteVariable
8866        	The variable added by copy
8867        externalWeight : float
8868        	the added external weight
8869        id : int
8870        	The proposed id for the variable.
8871
8872        Returns
8873        -------
8874        int
8875        	the id of the added variable.
8876
8877        """
8878        return _pyAgrum.BayesNet_addNoisyORNet(self, *args)
8879
8880    def addNoisyORCompound(self, *args) -> int:
8881        r"""
8882
8883        Add a variable, it's associate node and a noisyOR implementation.
8884
8885        Since it seems that the 'classical' noisyOR is the Compound noisyOR, we keep the addNoisyOR as an alias for addNoisyORCompound.
8886
8887        (The id of the new variable can be automatically generated.)
8888
8889        Parameters
8890        ----------
8891        variable : pyAgrum.DiscreteVariable
8892        	The variable added by copy
8893        externalWeight : float
8894        	the added external weight
8895        id : int
8896        	The proposed id for the variable.
8897
8898        Returns
8899        -------
8900        int
8901        	the id of the added variable.
8902
8903        Raises
8904        --------
8905        pyAgrum.DuplicateElement
8906            If id is already used
8907
8908        """
8909        return _pyAgrum.BayesNet_addNoisyORCompound(self, *args)
8910
8911    def addNoisyAND(self, *args) -> int:
8912        r"""
8913
8914        Add a variable, its associate node and a noisyAND implementation.
8915
8916        (The id of the new variable can be automatically generated.)
8917
8918        Parameters
8919        ----------
8920        variable : pyAgrum.DiscreteVariable
8921        	The variable added by copy
8922        externalWeight : float
8923        	the added external weight
8924        id : int
8925        	The proposed id for the variable.
8926
8927        Returns
8928        -------
8929        int
8930        	the id of the added variable.
8931
8932        Raises
8933        ------
8934        pyAgrum.DuplicateElement
8935            If id is already used
8936
8937        """
8938        return _pyAgrum.BayesNet_addNoisyAND(self, *args)
8939
8940    def addLogit(self, *args) -> int:
8941        r"""
8942
8943        Add a variable, its associate node and a Logit implementation.
8944
8945        (The id of the new variable can be automatically generated.)
8946
8947        Parameters
8948        ----------
8949        variable : pyAgrum.DiscreteVariable
8950        	The variable added by copy
8951        externalWeight : float
8952        	the added external weight
8953        id : int
8954        	The proposed id for the variable.
8955        Returns
8956        -------
8957        int
8958        	the id of the added variable.
8959
8960        Raises
8961        ------
8962        pyAgrum.DuplicateElement
8963            If id is already used
8964
8965        """
8966        return _pyAgrum.BayesNet_addLogit(self, *args)
8967
8968    def addOR(self, var: "pyAgrum.DiscreteVariable") -> int:
8969        r"""
8970
8971        Add a variable, it's associate node and an OR implementation.
8972
8973        The id of the new variable is automatically generated.
8974
8975        Warnings
8976        --------
8977        	If parents are not boolean, all value>1 is True
8978
8979        Parameters
8980        ----------
8981        variable : pyAgrum.DiscreteVariable
8982        	The variable added by copy
8983
8984        Returns
8985        -------
8986        int
8987        	the id of the added variable.
8988
8989        Raises
8990        ------
8991        pyAgrum.SizeError
8992            If variable.domainSize()>2
8993
8994        """
8995        return _pyAgrum.BayesNet_addOR(self, var)
8996
8997    def addAND(self, var: "pyAgrum.DiscreteVariable") -> int:
8998        r"""
8999
9000        Add a variable, it's associate node and an AND implementation.
9001
9002        The id of the new variable is automatically generated.
9003
9004        Parameters
9005        ----------
9006        variable : pyAgrum.DiscreteVariable
9007        	The variable added by copy.
9008
9009        Returns
9010        -------
9011        int
9012        	the id of the added variable.
9013
9014        Raises
9015        ------
9016        pyAgrum.SizeError
9017            If variable.domainSize()>2
9018
9019        """
9020        return _pyAgrum.BayesNet_addAND(self, var)
9021
9022    def addAMPLITUDE(self, var: "pyAgrum.DiscreteVariable") -> int:
9023        r"""
9024
9025        Others aggregators
9026
9027        Parameters
9028        ----------
9029        variable : pyAgrum.DiscreteVariable
9030        	the variable to be added
9031
9032        Returns
9033        -------
9034        int
9035        	the id of the added value
9036
9037        """
9038        return _pyAgrum.BayesNet_addAMPLITUDE(self, var)
9039
9040    def addCOUNT(self, var: "pyAgrum.DiscreteVariable", value: int=1) -> int:
9041        r"""
9042
9043        Others aggregators
9044
9045        Parameters
9046        ----------
9047        variable : pyAgrum.DiscreteVariable
9048        	the variable to be added
9049
9050        Returns
9051        -------
9052        int
9053        	the id of the added value
9054
9055        """
9056        return _pyAgrum.BayesNet_addCOUNT(self, var, value)
9057
9058    def addEXISTS(self, var: "pyAgrum.DiscreteVariable", value: int=1) -> int:
9059        r"""
9060
9061        Others aggregators
9062
9063        Parameters
9064        ----------
9065        variable : pyAgrum.DiscreteVariable
9066        	the variable to be added
9067
9068        Returns
9069        -------
9070        int
9071        	the id of the added value
9072
9073        """
9074        return _pyAgrum.BayesNet_addEXISTS(self, var, value)
9075
9076    def addFORALL(self, var: "pyAgrum.DiscreteVariable", value: int=1) -> int:
9077        r"""
9078
9079        Others aggregators
9080
9081        Parameters
9082        ----------
9083        variable : pyAgrum.DiscreteVariable
9084        	the variable to be added
9085
9086        Returns
9087        -------
9088        int
9089        	the id of the added variable.
9090
9091        """
9092        return _pyAgrum.BayesNet_addFORALL(self, var, value)
9093
9094    def addMAX(self, var: "pyAgrum.DiscreteVariable") -> int:
9095        r"""
9096
9097        Others aggregators
9098
9099        Parameters
9100        ----------
9101        variable : pyAgrum.DiscreteVariable
9102        	the variable to be added
9103
9104        Returns
9105        -------
9106        int
9107        	the id of the added value
9108
9109        """
9110        return _pyAgrum.BayesNet_addMAX(self, var)
9111
9112    def addMEDIAN(self, var: "pyAgrum.DiscreteVariable") -> int:
9113        r"""
9114
9115        Others aggregators
9116
9117        Parameters
9118        ----------
9119        variable : pyAgrum.DiscreteVariable
9120        	the variable to be added
9121
9122        Returns
9123        -------
9124        int
9125        	the id of the added value
9126
9127        """
9128        return _pyAgrum.BayesNet_addMEDIAN(self, var)
9129
9130    def addMIN(self, var: "pyAgrum.DiscreteVariable") -> int:
9131        r"""
9132
9133        Others aggregators
9134
9135        Parameters
9136        ----------
9137        variable : pyAgrum.DiscreteVariable
9138        	the variable to be added
9139
9140        Returns
9141        -------
9142        int
9143        	the id of the added value
9144
9145        """
9146        return _pyAgrum.BayesNet_addMIN(self, var)
9147
9148    def addSUM(self, var: "pyAgrum.DiscreteVariable") -> int:
9149        r"""
9150
9151        Others aggregators
9152
9153        Parameters
9154        ----------
9155        variable : pyAgrum.DiscreteVariable
9156                the variable to be added
9157
9158        Returns
9159        -------
9160        int
9161                the id of the added value
9162
9163        """
9164        return _pyAgrum.BayesNet_addSUM(self, var)
9165
9166    def addWeightedArc(self, *args) -> None:
9167        r"""
9168
9169        Add an arc in the BN, and update arc.head's CPT.
9170
9171        Parameters
9172        ----------
9173        head :
9174        	a variable's id (int)
9175        tail :
9176        	a variable's id (int)
9177        head :
9178        	a variable's name (str)
9179        tail :
9180        	a variable's name (str)
9181        causalWeight : float
9182        	the added causal weight
9183
9184        Raises
9185        ------
9186        pyAgrum.InvalidArc
9187            If arc.tail and/or arc.head are not in the BN.
9188        pyAgrum.InvalidArc
9189            If variable in arc.head is not a NoisyOR variable.
9190
9191        """
9192        return _pyAgrum.BayesNet_addWeightedArc(self, *args)
9193
9194    def generateCPTs(self) -> None:
9195        r"""
9196
9197        Randomly generates CPTs for a given structure.
9198
9199        """
9200        return _pyAgrum.BayesNet_generateCPTs(self)
9201
9202    def generateCPT(self, *args) -> None:
9203        r"""
9204
9205        Randomly generate CPT for a given node in a given structure.
9206
9207        Parameters
9208        ----------
9209        node : int
9210        	The variable's id.
9211        name : str
9212        	The variable's name.
9213
9214        """
9215        return _pyAgrum.BayesNet_generateCPT(self, *args)
9216
9217    def changePotential(self, *args) -> None:
9218        r"""
9219
9220        change the CPT associated to nodeId to newPot delete the old CPT associated to nodeId.
9221
9222        Parameters
9223        ----------
9224        newPot : pyAgrum.Potential
9225        	the new potential
9226        NodeId : int
9227        	the id of the node
9228        name : str
9229        	the name of the variable
9230
9231        Raises
9232        ------
9233        pyAgrum.NotAllowed
9234            If newPot has not the same signature as __probaMap[NodeId]
9235
9236        """
9237        return _pyAgrum.BayesNet_changePotential(self, *args)
9238
9239    def dag(self) -> "pyAgrum.DAG":
9240        r"""
9241
9242        Returns
9243        -------
9244        pyAgrum.DAG
9245        	a constant reference to the dag of this BayesNet.
9246
9247        """
9248        val = _pyAgrum.BayesNet_dag(self)
9249
9250        val = DAG(val) # copying the DAG
9251
9252
9253        return val
9254
9255
9256    def size(self) -> int:
9257        r"""
9258
9259        Returns
9260        -------
9261        int
9262            the number of nodes in the graph
9263
9264        """
9265        return _pyAgrum.BayesNet_size(self)
9266
9267    def log10DomainSize(self) -> float:
9268        return _pyAgrum.BayesNet_log10DomainSize(self)
9269
9270    def minimalCondSet(self, *args) -> object:
9271        r"""
9272
9273        Returns, given one or many targets and a list of variables, the minimal set of those needed to calculate the target/targets.
9274
9275        Parameters
9276        ----------
9277        target : int
9278        	The id of the target
9279        targets : list
9280        	The ids of the targets
9281        list : list
9282        	The list of available variables
9283
9284        Returns
9285        -------
9286        Set
9287        	The minimal set of variables
9288
9289        """
9290        return _pyAgrum.BayesNet_minimalCondSet(self, *args)
9291
9292    def isIndependent(self, *args) -> bool:
9293        return _pyAgrum.BayesNet_isIndependent(self, *args)
9294
9295    def names(self) -> object:
9296        r"""
9297
9298        Returns
9299        -------
9300        list
9301        	The names of the graph variables
9302
9303        """
9304        return _pyAgrum.BayesNet_names(self)
9305
9306    def nodes(self) -> object:
9307        r"""
9308
9309        Returns
9310        -------
9311        set
9312            the set of ids
9313
9314        """
9315        return _pyAgrum.BayesNet_nodes(self)
9316
9317    def connectedComponents(self):
9318      """ connected components from a graph/BN
9319
9320      Compute the connected components of a pyAgrum's graph or Bayesian Network
9321      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
9322
9323      The firstly visited node for each component is called a 'root' and is used as a key for the component.
9324      This root has been arbitrarily chosen during the algorithm.
9325
9326      Returns
9327      -------
9328      dict(int,Set[int])
9329        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
9330
9331      """
9332      nodes=self.nodes()
9333      connected_components=dict()
9334
9335      def parcours(node,orig):
9336          cc={node}
9337          nodes.discard(node)
9338          if hasattr(self,'children'):
9339              for chi in self.children(node):
9340                  if chi!=orig:
9341                      if chi in nodes:
9342                          cc|=parcours(chi,node)
9343
9344          if hasattr(self,'parents'):
9345              for par in self.parents(node):
9346                  if par!=orig:
9347                      if par in nodes:
9348                          cc|=parcours(par,node)
9349
9350          if hasattr(self,'neighbours'):
9351              for nei in self.neighbours(node):
9352                  if nei!=orig:
9353                      if nei in nodes:
9354                          cc|=parcours(nei,node)
9355          return cc
9356
9357      while (len(nodes)>0):
9358          root=nodes.pop()
9359          connected_components[root]=parcours(root,None)
9360      return connected_components
9361
9362
9363    def arcs(self) -> object:
9364        r"""
9365
9366        Returns
9367        -------
9368        list
9369        	The lisf of arcs in the IBayesNet
9370
9371        """
9372        return _pyAgrum.BayesNet_arcs(self)
9373
9374    def parents(self, norid: object) -> object:
9375        r"""
9376
9377        Parameters
9378        ----------
9379        id :
9380        	The id of the child node
9381
9382        Returns
9383        -------
9384        Set
9385            the set of the parents ids.
9386
9387        """
9388        return _pyAgrum.BayesNet_parents(self, norid)
9389
9390    def children(self, norid: object) -> object:
9391        r"""
9392
9393        Parameters
9394        ----------
9395        id : int
9396          the id of the parent
9397
9398        Returns
9399        -------
9400        Set
9401        	the set of all the children
9402
9403        """
9404        return _pyAgrum.BayesNet_children(self, norid)
9405
9406    def family(self, norid: object) -> object:
9407        return _pyAgrum.BayesNet_family(self, norid)
9408
9409    def descendants(self, norid: object) -> object:
9410        return _pyAgrum.BayesNet_descendants(self, norid)
9411
9412    def ancestors(self, norid: object) -> object:
9413        return _pyAgrum.BayesNet_ancestors(self, norid)
9414
9415    def moralizedAncestralGraph(self, nodes: object) -> "pyAgrum.UndiGraph":
9416        return _pyAgrum.BayesNet_moralizedAncestralGraph(self, nodes)
9417
9418    def addStructureListener(self,whenNodeAdded=None,whenNodeDeleted=None,whenArcAdded=None,whenArcDeleted=None):
9419        """
9420        Add the listeners in parameters to the list of existing ones.
9421
9422        Parameters
9423        ----------
9424        whenNodeAdded : lambda expression
9425          a function for when a node is added
9426        whenNodeDeleted : lambda expression
9427          a function for when a node is removed
9428        whenArcAdded : lambda expression
9429          a function for when an arc is added
9430        whenArcDeleted : lambda expression
9431          a function for when an arc is removed
9432        """
9433        if [whenNodeAdded,whenNodeDeleted,whenArcAdded,whenArcDeleted]==[None,None,None,None]:
9434          return
9435
9436        if not hasattr(self,"_listeners"):
9437          self._listeners=[]
9438
9439        nl = PythonBNListener(self, self.variableNodeMap())
9440        if whenNodeAdded is not None:
9441          nl.setWhenNodeAdded(whenNodeAdded)
9442        if whenNodeDeleted is not None:
9443          nl.setWhenNodeDeleted(whenNodeDeleted)
9444        if whenArcAdded is not None:
9445          nl.setWhenArcAdded(whenArcAdded)
9446        if whenArcDeleted is not None:
9447          nl.setWhenArcDeleted(whenArcDeleted)
9448
9449        self._listeners.append(nl)
9450
9451
9452    def loadBIF(self, *args) -> str:
9453        r"""
9454
9455        Load a BIF file.
9456
9457        Parameters
9458        ----------
9459        name : str
9460        	the file's name
9461        l : list
9462        	list of functions to execute
9463
9464        Raises
9465        --------
9466        pyAgrum.IOError
9467            If file not found
9468        pyAgrum.FatalError
9469            If file is not valid
9470
9471        """
9472        return _pyAgrum.BayesNet_loadBIF(self, *args)
9473
9474    def saveBIF(self, name: str) -> None:
9475        r"""
9476
9477        Save the BayesNet in a BIF file.
9478
9479        Parameters
9480        ----------
9481        name : str
9482        	the file's name
9483
9484        """
9485        return _pyAgrum.BayesNet_saveBIF(self, name)
9486
9487    def loadDSL(self, *args) -> str:
9488        r"""
9489
9490        Load a DSL file.
9491
9492        Parameters
9493        ----------
9494        name : str
9495        	the file's name
9496        l : list
9497        	list of functions to execute
9498
9499        Raises
9500        ------
9501        pyAgrum.IOError
9502            If file not found
9503        pyAgrum.FatalError
9504            If file is not valid
9505
9506        """
9507        return _pyAgrum.BayesNet_loadDSL(self, *args)
9508
9509    def saveDSL(self, name: str) -> None:
9510        r"""
9511
9512        Save the BayesNet in a DSL file.
9513
9514        Parameters
9515        ----------
9516        name : str
9517        	the file's name
9518
9519        """
9520        return _pyAgrum.BayesNet_saveDSL(self, name)
9521
9522    def loadNET(self, *args) -> str:
9523        r"""
9524
9525        Load a NET file.
9526
9527        Parameters
9528        ----------
9529        name : str
9530        	the name's file
9531        l : list
9532        	list of functions to execute
9533
9534        Raises
9535        ------
9536        pyAgrum.IOError
9537            If file not found
9538        pyAgrum.FatalError
9539            If file is not valid
9540
9541        """
9542        return _pyAgrum.BayesNet_loadNET(self, *args)
9543
9544    def saveNET(self, name: str) -> None:
9545        r"""
9546
9547        Save the BayesNet in a NET file.
9548
9549        Parameters
9550        ----------
9551        name : str
9552        	the file's name
9553
9554        """
9555        return _pyAgrum.BayesNet_saveNET(self, name)
9556
9557    def loadO3PRM(self, *args) -> str:
9558        r"""
9559
9560        Load an O3PRM file.
9561
9562        Warnings
9563        --------
9564        The O3PRM language is the only language allowing to manipulate not only DiscretizedVariable but also RangeVariable and LabelizedVariable.
9565
9566        Parameters
9567        ----------
9568        name : str
9569        	the file's name
9570        system : str
9571        	the system's name
9572        classpath : str
9573        	the classpath
9574        l : list
9575        	list of functions to execute
9576
9577        Raises
9578        ------
9579        pyAgrum.IOError
9580            If file not found
9581        pyAgrum.FatalError
9582            If file is not valid
9583
9584        """
9585        return _pyAgrum.BayesNet_loadO3PRM(self, *args)
9586
9587    def saveO3PRM(self, name: str) -> None:
9588        r"""
9589
9590        Save the BayesNet in an O3PRM file.
9591
9592        Warnings
9593        --------
9594        The O3PRM language is the only language allowing to manipulate not only DiscretizedVariable but also RangeVariable and LabelizedVariable.
9595
9596        Parameters
9597        ----------
9598        name : str
9599        	the file's name
9600
9601        """
9602        return _pyAgrum.BayesNet_saveO3PRM(self, name)
9603
9604    def loadBIFXML(self, *args) -> str:
9605        r"""
9606
9607        Load a BIFXML file.
9608
9609        Parameters
9610        ----------
9611        name : str
9612        	the name's file
9613        l : list
9614        	list of functions to execute
9615
9616        Raises
9617        ------
9618        pyAgrum.IOError
9619            If file not found
9620        pyAgrum.FatalError
9621            If file is not valid
9622
9623        """
9624        return _pyAgrum.BayesNet_loadBIFXML(self, *args)
9625
9626    def saveBIFXML(self, name: str) -> None:
9627        r"""
9628
9629        Save the BayesNet in a BIFXML file.
9630
9631        Parameters
9632        ----------
9633        name : str
9634        	the file's name
9635
9636        """
9637        return _pyAgrum.BayesNet_saveBIFXML(self, name)
9638
9639    def loadUAI(self, *args) -> str:
9640        r"""
9641
9642        Load an UAI file.
9643
9644        Parameters
9645        ----------
9646        name : str
9647        	the name's file
9648        l : list
9649        	list of functions to execute
9650
9651        Raises
9652        ------
9653        pyAgrum.IOError
9654            If file not found
9655        pyAgrum.FatalError
9656            If file is not valid
9657
9658        """
9659        return _pyAgrum.BayesNet_loadUAI(self, *args)
9660
9661    def saveUAI(self, name: str) -> None:
9662        r"""
9663
9664        Save the BayesNet in an UAI file.
9665
9666        Parameters
9667        ----------
9668        name : str
9669        	the file's name
9670
9671        """
9672        return _pyAgrum.BayesNet_saveUAI(self, name)
9673
9674    def __repr__(self) -> str:
9675        return _pyAgrum.BayesNet___repr__(self)
9676
9677    def __str__(self) -> str:
9678        return _pyAgrum.BayesNet___str__(self)
9679
9680# Register BayesNet in _pyAgrum:
9681_pyAgrum.BayesNet_swigregister(BayesNet)
9682
9683def BayesNet_fastPrototype(dotlike: str, domainSize: int=2) -> "pyAgrum.BayesNet":
9684    r"""
9685
9686    Create a Bayesian network with a dot-like syntax which specifies:
9687        - the structure 'a->b->c;b->d<-e;'.
9688        - the type of the variables with different syntax:
9689
9690          - by default, a variable is a pyAgrum.RangeVariable using the default domain size (second argument)
9691          - with 'a[10]', the variable is a pyAgrum.RangeVariable using 10 as domain size (from 0 to 9)
9692          - with 'a[3,7]', the variable is a pyAgrum.RangeVariable using a domainSize from 3 to 7
9693          - with 'a[1,3.14,5,6.2]', the variable is a pyAgrum.DiscretizedVariable using the given ticks (at least 3 values)
9694          - with 'a{top|middle|bottom}', the variable is a pyAgrum.LabelizedVariable using the given labels.
9695          - with 'a{-1|5|0|3}', the variable is a pyAgrum.IntegerVariable using the sorted given values.
9696
9697    Note
9698    ----
9699      - If the dot-like string contains such a specification more than once for a variable, the first specification will be used.
9700      - the CPTs are randomly generated.
9701      - see also pyAgrum.fastBN.
9702
9703    Examples
9704    --------
9705    >>> import pyAgrum as gum
9706    >>> bn=pyAgrum.BayesNet.fastPrototype('A->B[1,3]<-C{yes|No}->D[2,4]<-E[1,2.5,3.9]',6)
9707
9708    Parameters
9709    ----------
9710    dotlike : str
9711            the string containing the specification
9712    domainSize : int
9713            the default domain size for variables
9714
9715    Returns
9716    -------
9717    pyAgrum.BayesNet
9718            the resulting Bayesian network
9719
9720    """
9721    return _pyAgrum.BayesNet_fastPrototype(dotlike, domainSize)
9722
9723class BayesNetFragment(IBayesNet, ):
9724    r"""
9725
9726    BayesNetFragment represents a part of a Bayesian network (subset of nodes). By default, the arcs and the CPTs are the same as the BN but local CPTs can be build to express different local dependencies. All the non local CPTs are not copied. Therefore a BayesNetFragment is a light object.
9727
9728    BayesNetFragment(BayesNet bn) -> BayesNetFragment
9729        Parameters:
9730          * **bn** (*pyAgrum.BayesNet*) -- the bn refered by the fragment
9731
9732    """
9733
9734    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
9735    __repr__ = _swig_repr
9736
9737    def __init__(self, bn: "IBayesNet"):
9738        _pyAgrum.BayesNetFragment_swiginit(self, _pyAgrum.new_BayesNetFragment(bn))
9739    __swig_destroy__ = _pyAgrum.delete_BayesNetFragment
9740
9741    def whenNodeAdded(self, src: object, id: int) -> None:
9742        return _pyAgrum.BayesNetFragment_whenNodeAdded(self, src, id)
9743
9744    def whenNodeDeleted(self, src: object, id: int) -> None:
9745        return _pyAgrum.BayesNetFragment_whenNodeDeleted(self, src, id)
9746
9747    def whenArcAdded(self, src: object, _from: int, to: int) -> None:
9748        return _pyAgrum.BayesNetFragment_whenArcAdded(self, src, _from, to)
9749
9750    def whenArcDeleted(self, src: object, _from: int, to: int) -> None:
9751        return _pyAgrum.BayesNetFragment_whenArcDeleted(self, src, _from, to)
9752
9753    def cpt(self, *args) -> "pyAgrum.Potential":
9754        r"""
9755
9756        Returns the CPT of a variable.
9757
9758        Parameters
9759        ----------
9760        VarId : int
9761        	A variable's id in the pyAgrum.IBayesNet.
9762        name : str
9763        	A variable's name in the pyAgrum.IBayesNet.
9764
9765        Returns
9766        -------
9767        pyAgrum.Potential
9768        	The variable's CPT.
9769
9770        Raises
9771        ------
9772        pyAgrum.NotFound
9773        	If no variable's id matches varId.
9774
9775        """
9776        return _pyAgrum.BayesNetFragment_cpt(self, *args)
9777
9778    def variableNodeMap(self) -> "pyAgrum.VariableNodeMap":
9779        r"""
9780
9781        Returns
9782        -------
9783        pyAgrum.variableNodeMap
9784        	the variable node map
9785
9786        """
9787        return _pyAgrum.BayesNetFragment_variableNodeMap(self)
9788
9789    def variable(self, *args) -> "pyAgrum.DiscreteVariable":
9790        r"""
9791
9792        Parameters
9793        ----------
9794        id : int
9795        	a variable's id
9796        name : str
9797        	a variable's name
9798
9799        Returns
9800        -------
9801        pyAgrum.DiscreteVariable
9802        	the variable
9803
9804        Raises
9805        ------
9806        pyAgrum.IndexError
9807        	If the graph does not contain the variable
9808
9809        """
9810        return _pyAgrum.BayesNetFragment_variable(self, *args)
9811
9812    def nodeId(self, var: "pyAgrum.DiscreteVariable") -> int:
9813        r"""
9814
9815        Parameters
9816        ----------
9817        var : pyAgrum.DiscreteVariable
9818        	a variable
9819
9820        Returns
9821        -------
9822        int
9823        	the id of the variable
9824
9825        Raises
9826        ------
9827        pyAgrum.IndexError
9828        	If the graph does not contain the variable
9829
9830        """
9831        return _pyAgrum.BayesNetFragment_nodeId(self, var)
9832
9833    def idFromName(self, name: str) -> int:
9834        r"""
9835
9836        Returns a variable's id given its name in the graph.
9837
9838        Parameters
9839        ----------
9840        name : str
9841        	The variable's name from which the id is returned.
9842
9843        Returns
9844        -------
9845        int :
9846        	The variable's node id.
9847
9848        Raises
9849        ------
9850        pyAgrum.NotFound
9851        	If name does not match a variable in the graph
9852
9853        """
9854        return _pyAgrum.BayesNetFragment_idFromName(self, name)
9855
9856    def variableFromName(self, name: str) -> "pyAgrum.DiscreteVariable":
9857        r"""
9858
9859        Parameters
9860        ----------
9861        name : str
9862        	a variable's name
9863
9864        Returns
9865        -------
9866        pyAgrum.DiscreteVariable
9867        	the variable
9868
9869        Raises
9870        ------
9871        pyAgrum.IndexError
9872        	If the graph does not contain the variable
9873
9874        """
9875        return _pyAgrum.BayesNetFragment_variableFromName(self, name)
9876
9877    def toDot(self) -> str:
9878        r"""
9879
9880        Returns
9881        -------
9882        str
9883            a friendly display of the graph in DOT format
9884
9885        """
9886        return _pyAgrum.BayesNetFragment_toDot(self)
9887
9888    def isInstalledNode(self, *args) -> bool:
9889        r"""
9890
9891        Check if a node is in the fragment
9892
9893        Parameters
9894        ----------
9895        n : int, str
9896        	the id or the name of the variable.
9897
9898        """
9899        return _pyAgrum.BayesNetFragment_isInstalledNode(self, *args)
9900
9901    def installNode(self, *args) -> None:
9902        r"""
9903
9904        Add a node to the fragment. The arcs that can be added between installed nodes are created.
9905        No specific CPT are created. Then either the parents of the node are already in the fragment
9906        and the node is consistant, or the parents are not in the fragment and the node is not consistant.
9907
9908        Parameters
9909        ----------
9910        n : int, str
9911        	the id or the name of the variable.
9912
9913        Raises
9914        ------
9915        pyAgrum.NotFound
9916          if the node is not found.
9917
9918        """
9919        return _pyAgrum.BayesNetFragment_installNode(self, *args)
9920
9921    def installAscendants(self, *args) -> None:
9922        r"""
9923
9924        Add the variable and all its ascendants in the fragment. No inconsistant node are created.
9925
9926        Parameters
9927        ----------
9928        n : int, str
9929        	the id or the name of the variable.
9930
9931        Raises
9932        ------
9933        pyAgrum.NotFound
9934          if the node is not found.
9935
9936        """
9937        return _pyAgrum.BayesNetFragment_installAscendants(self, *args)
9938
9939    def uninstallNode(self, *args) -> None:
9940        r"""
9941
9942        Remove a node from the fragment. The fragment can become inconsistant.
9943
9944        Parameters
9945        ----------
9946        n : int, str
9947        	the id or the name of the variable.
9948
9949        Raises
9950        ------
9951        pyAgrum.NotFound
9952          if the node is not found.
9953
9954        """
9955        return _pyAgrum.BayesNetFragment_uninstallNode(self, *args)
9956
9957    def installMarginal(self, *args) -> None:
9958        r"""
9959
9960        Install a local marginal for a node. Doing so, it removes the parents of the node in the fragment.
9961
9962        Parameters
9963        ----------
9964        n : int, str
9965        	the id or the name of the variable.
9966        pot : Potential
9967          the Potential (marginal) to install
9968
9969        Raises
9970        ------
9971        pyAgrum.NotFound
9972          if the node is not found.
9973
9974        """
9975        return _pyAgrum.BayesNetFragment_installMarginal(self, *args)
9976
9977    def installCPT(self, *args) -> None:
9978        r"""
9979
9980        Install a local CPT for a node. Doing so, it changes the parents of the node in the fragment.
9981
9982        Parameters
9983        ----------
9984        n : int, str
9985        	the id or the name of the variable.
9986        pot : Potential
9987          the Potential to install
9988
9989        Raises
9990        ------
9991        pyAgrum.NotFound
9992          if the node is not found.
9993
9994        """
9995        return _pyAgrum.BayesNetFragment_installCPT(self, *args)
9996
9997    def uninstallCPT(self, *args) -> None:
9998        r"""
9999
10000        Remove a local CPT. The fragment can become inconsistant.
10001
10002        Parameters
10003        ----------
10004        n : int, str
10005        	the id or the name of the variable.
10006
10007        Raises
10008        ------
10009        pyAgrum.NotFound
10010          if the node is not found.
10011
10012        """
10013        return _pyAgrum.BayesNetFragment_uninstallCPT(self, *args)
10014
10015    def checkConsistency(self, *args) -> bool:
10016        r"""
10017
10018        If a variable is added to the fragment but not its parents, there is no CPT consistant for this variable. This function checks the consistency for a variable of for all.
10019
10020        Parameters
10021        ----------
10022
10023        n : int, str (optional)
10024        	the id or the name of the variable. If no argument, the function checks all the variables.
10025
10026        Returns
10027        -------
10028        boolean
10029        	True if the variable(s) is consistant.
10030
10031        Raises
10032        ------
10033        pyAgrum.NotFound
10034          if the node is not found.
10035
10036        """
10037        return _pyAgrum.BayesNetFragment_checkConsistency(self, *args)
10038
10039    def toBN(self) -> "pyAgrum.BayesNet":
10040        r"""
10041
10042        Create a BayesNet from a fragment.
10043
10044        Raises
10045        ------
10046        pyAgrum.OperationNotAllowed
10047          if the fragment is not consistent.
10048
10049        """
10050        return _pyAgrum.BayesNetFragment_toBN(self)
10051
10052    def dag(self) -> "pyAgrum.DAG":
10053        r"""
10054
10055        Returns
10056        -------
10057        pyAgrum.DAG
10058        	a constant reference to the dag of this BayesNet.
10059
10060        """
10061        val = _pyAgrum.BayesNetFragment_dag(self)
10062
10063        val = DAG(val) # copying the DAG
10064
10065
10066        return val
10067
10068
10069    def minimalCondSet(self, *args) -> object:
10070        r"""
10071
10072        Returns, given one or many targets and a list of variables, the minimal set of those needed to calculate the target/targets.
10073
10074        Parameters
10075        ----------
10076        target : int
10077        	The id of the target
10078        targets : list
10079        	The ids of the targets
10080        list : list
10081        	The list of available variables
10082
10083        Returns
10084        -------
10085        Set
10086        	The minimal set of variables
10087
10088        """
10089        return _pyAgrum.BayesNetFragment_minimalCondSet(self, *args)
10090
10091    def isIndependent(self, *args) -> bool:
10092        return _pyAgrum.BayesNetFragment_isIndependent(self, *args)
10093
10094    def names(self) -> object:
10095        r"""
10096
10097        Returns
10098        -------
10099        list
10100        	The names of the graph variables
10101
10102        """
10103        return _pyAgrum.BayesNetFragment_names(self)
10104
10105    def nodes(self) -> object:
10106        r"""
10107
10108        Returns
10109        -------
10110        set
10111            the set of ids
10112
10113        """
10114        return _pyAgrum.BayesNetFragment_nodes(self)
10115
10116    def connectedComponents(self):
10117      """ connected components from a graph/BN
10118
10119      Compute the connected components of a pyAgrum's graph or Bayesian Network
10120      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
10121
10122      The firstly visited node for each component is called a 'root' and is used as a key for the component.
10123      This root has been arbitrarily chosen during the algorithm.
10124
10125      Returns
10126      -------
10127      dict(int,Set[int])
10128        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
10129
10130      """
10131      nodes=self.nodes()
10132      connected_components=dict()
10133
10134      def parcours(node,orig):
10135          cc={node}
10136          nodes.discard(node)
10137          if hasattr(self,'children'):
10138              for chi in self.children(node):
10139                  if chi!=orig:
10140                      if chi in nodes:
10141                          cc|=parcours(chi,node)
10142
10143          if hasattr(self,'parents'):
10144              for par in self.parents(node):
10145                  if par!=orig:
10146                      if par in nodes:
10147                          cc|=parcours(par,node)
10148
10149          if hasattr(self,'neighbours'):
10150              for nei in self.neighbours(node):
10151                  if nei!=orig:
10152                      if nei in nodes:
10153                          cc|=parcours(nei,node)
10154          return cc
10155
10156      while (len(nodes)>0):
10157          root=nodes.pop()
10158          connected_components[root]=parcours(root,None)
10159      return connected_components
10160
10161
10162    def arcs(self) -> object:
10163        r"""
10164
10165        Returns
10166        -------
10167        list
10168        	The lisf of arcs in the IBayesNet
10169
10170        """
10171        return _pyAgrum.BayesNetFragment_arcs(self)
10172
10173    def parents(self, norid: object) -> object:
10174        r"""
10175
10176        Parameters
10177        ----------
10178        id :
10179        	The id of the child node
10180
10181        Returns
10182        -------
10183        Set
10184            the set of the parents ids.
10185
10186        """
10187        return _pyAgrum.BayesNetFragment_parents(self, norid)
10188
10189    def children(self, norid: object) -> object:
10190        r"""
10191
10192        Parameters
10193        ----------
10194        id : int
10195          the id of the parent
10196
10197        Returns
10198        -------
10199        Set
10200        	the set of all the children
10201
10202        """
10203        return _pyAgrum.BayesNetFragment_children(self, norid)
10204
10205    def family(self, norid: object) -> object:
10206        return _pyAgrum.BayesNetFragment_family(self, norid)
10207
10208    def descendants(self, norid: object) -> object:
10209        return _pyAgrum.BayesNetFragment_descendants(self, norid)
10210
10211    def ancestors(self, norid: object) -> object:
10212        return _pyAgrum.BayesNetFragment_ancestors(self, norid)
10213
10214    def moralizedAncestralGraph(self, nodes: object) -> "pyAgrum.UndiGraph":
10215        return _pyAgrum.BayesNetFragment_moralizedAncestralGraph(self, nodes)
10216
10217    def addStructureListener(self,whenNodeAdded=None,whenNodeDeleted=None,whenArcAdded=None,whenArcDeleted=None):
10218        """
10219        Add the listeners in parameters to the list of existing ones.
10220
10221        Parameters
10222        ----------
10223        whenNodeAdded : lambda expression
10224          a function for when a node is added
10225        whenNodeDeleted : lambda expression
10226          a function for when a node is removed
10227        whenArcAdded : lambda expression
10228          a function for when an arc is added
10229        whenArcDeleted : lambda expression
10230          a function for when an arc is removed
10231        """
10232        if [whenNodeAdded,whenNodeDeleted,whenArcAdded,whenArcDeleted]==[None,None,None,None]:
10233          return
10234
10235        if not hasattr(self,"_listeners"):
10236          self._listeners=[]
10237
10238        nl = PythonBNListener(self, self.variableNodeMap())
10239        if whenNodeAdded is not None:
10240          nl.setWhenNodeAdded(whenNodeAdded)
10241        if whenNodeDeleted is not None:
10242          nl.setWhenNodeDeleted(whenNodeDeleted)
10243        if whenArcAdded is not None:
10244          nl.setWhenArcAdded(whenArcAdded)
10245        if whenArcDeleted is not None:
10246          nl.setWhenArcDeleted(whenArcDeleted)
10247
10248        self._listeners.append(nl)
10249
10250
10251# Register BayesNetFragment in _pyAgrum:
10252_pyAgrum.BayesNetFragment_swigregister(BayesNetFragment)
10253
10254class IMarkovNet(UGmodel):
10255    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
10256
10257    def __init__(self, *args, **kwargs):
10258        raise AttributeError("No constructor defined - class is abstract")
10259    __swig_destroy__ = _pyAgrum.delete_IMarkovNet
10260
10261    def smallestFactorFromNode(self, *args) -> List[int]:
10262        return _pyAgrum.IMarkovNet_smallestFactorFromNode(self, *args)
10263
10264    def factors(self) -> List[Set[int]]:
10265        return _pyAgrum.IMarkovNet_factors(self)
10266
10267    def variableNodeMap(self) -> "pyAgrum.VariableNodeMap":
10268        return _pyAgrum.IMarkovNet_variableNodeMap(self)
10269
10270    def variable(self, id: int) -> "pyAgrum.DiscreteVariable":
10271        return _pyAgrum.IMarkovNet_variable(self, id)
10272
10273    def nodeId(self, var: "pyAgrum.DiscreteVariable") -> int:
10274        return _pyAgrum.IMarkovNet_nodeId(self, var)
10275
10276    def idFromName(self, name: str) -> int:
10277        return _pyAgrum.IMarkovNet_idFromName(self, name)
10278
10279    def variableFromName(self, name: str) -> "pyAgrum.DiscreteVariable":
10280        return _pyAgrum.IMarkovNet_variableFromName(self, name)
10281
10282    def __eq__(self, _from: "IMarkovNet") -> bool:
10283        return _pyAgrum.IMarkovNet___eq__(self, _from)
10284
10285    def __ne__(self, _from: "IMarkovNet") -> bool:
10286        return _pyAgrum.IMarkovNet___ne__(self, _from)
10287
10288    def dim(self) -> int:
10289        return _pyAgrum.IMarkovNet_dim(self)
10290
10291    def maxVarDomainSize(self) -> int:
10292        return _pyAgrum.IMarkovNet_maxVarDomainSize(self)
10293
10294    def minParam(self) -> float:
10295        return _pyAgrum.IMarkovNet_minParam(self)
10296
10297    def maxParam(self) -> float:
10298        return _pyAgrum.IMarkovNet_maxParam(self)
10299
10300    def minNonZeroParam(self) -> float:
10301        return _pyAgrum.IMarkovNet_minNonZeroParam(self)
10302
10303    def maxNonOneParam(self) -> float:
10304        return _pyAgrum.IMarkovNet_maxNonOneParam(self)
10305
10306    def toDot(self) -> str:
10307        return _pyAgrum.IMarkovNet_toDot(self)
10308
10309    def toDotAsFactorGraph(self) -> str:
10310        return _pyAgrum.IMarkovNet_toDotAsFactorGraph(self)
10311
10312    def names(self) -> object:
10313        return _pyAgrum.IMarkovNet_names(self)
10314
10315    def nodes(self) -> object:
10316        return _pyAgrum.IMarkovNet_nodes(self)
10317
10318    def connectedComponents(self):
10319      """ connected components from a graph/BN
10320
10321      Compute the connected components of a pyAgrum's graph or Bayesian Network
10322      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
10323
10324      The firstly visited node for each component is called a 'root' and is used as a key for the component.
10325      This root has been arbitrarily chosen during the algorithm.
10326
10327      Returns
10328      -------
10329      dict(int,Set[int])
10330        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
10331
10332      """
10333      nodes=self.nodes()
10334      connected_components=dict()
10335
10336      def parcours(node,orig):
10337          cc={node}
10338          nodes.discard(node)
10339          if hasattr(self,'children'):
10340              for chi in self.children(node):
10341                  if chi!=orig:
10342                      if chi in nodes:
10343                          cc|=parcours(chi,node)
10344
10345          if hasattr(self,'parents'):
10346              for par in self.parents(node):
10347                  if par!=orig:
10348                      if par in nodes:
10349                          cc|=parcours(par,node)
10350
10351          if hasattr(self,'neighbours'):
10352              for nei in self.neighbours(node):
10353                  if nei!=orig:
10354                      if nei in nodes:
10355                          cc|=parcours(nei,node)
10356          return cc
10357
10358      while (len(nodes)>0):
10359          root=nodes.pop()
10360          connected_components[root]=parcours(root,None)
10361      return connected_components
10362
10363
10364    def neighbours(self, norid: object) -> object:
10365        return _pyAgrum.IMarkovNet_neighbours(self, norid)
10366
10367    def edges(self) -> object:
10368        return _pyAgrum.IMarkovNet_edges(self)
10369
10370    def minimalCondSet(self, *args) -> object:
10371        return _pyAgrum.IMarkovNet_minimalCondSet(self, *args)
10372
10373    def factor(self, *args) -> "pyAgrum.Potential":
10374        return _pyAgrum.IMarkovNet_factor(self, *args)
10375
10376    def isIndependent(self, *args) -> bool:
10377        return _pyAgrum.IMarkovNet_isIndependent(self, *args)
10378
10379    def __repr__(self) -> str:
10380        return _pyAgrum.IMarkovNet___repr__(self)
10381
10382    def __str__(self) -> str:
10383        return _pyAgrum.IMarkovNet___str__(self)
10384
10385# Register IMarkovNet in _pyAgrum:
10386_pyAgrum.IMarkovNet_swigregister(IMarkovNet)
10387
10388class MarkovNet(IMarkovNet):
10389    r"""
10390
10391    MarkovNet represents a Markov Network.
10392
10393    MarkovNet(name='') -> MarkovNet
10394        Parameters:
10395          * **name** (*str*) -- the name of the Bayes Net
10396
10397    MarkovNet(source) -> MarkovNet
10398        Parameters:
10399          * **source** (*pyAgrum.MarkovNet*) -- the Markov network to copy
10400
10401    """
10402
10403    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
10404
10405    @staticmethod
10406    def fastPrototype(dotlike: str, domainSize: int=2) -> "pyAgrum.MarkovNet":
10407        r"""
10408
10409        Create a Markov network with a modified dot-like syntax which specifies:
10410            - the structure ``a-b-c;b-d-e;``. The substring ``a-b-c`` indicates a factor with the scope (a,b,c).
10411            - the type of the variables with different syntax (cf documentation).
10412
10413        Examples
10414        --------
10415        >>> import pyAgrum as gum
10416        >>> bn=pyAgrum.MarkovNet.fastPrototype('A--B[1,3]-C{yes|No}--D[2,4]--E[1,2.5,3.9]',6)
10417
10418        Parameters
10419        ----------
10420        dotlike : str
10421                the string containing the specification
10422        domainSize : int
10423                the default domain size for variables
10424
10425        Returns
10426        -------
10427        pyAgrum.MarkovNet
10428                the resulting Markov network
10429
10430        """
10431        return _pyAgrum.MarkovNet_fastPrototype(dotlike, domainSize)
10432
10433    @staticmethod
10434    def fromBN(bn: "pyAgrum.BayesNet") -> "pyAgrum.MarkovNet":
10435        return _pyAgrum.MarkovNet_fromBN(bn)
10436    __swig_destroy__ = _pyAgrum.delete_MarkovNet
10437
10438    def __init__(self, *args):
10439        _pyAgrum.MarkovNet_swiginit(self, _pyAgrum.new_MarkovNet(*args))
10440
10441    def smallestFactorFromNode(self, node: int) -> List[int]:
10442        return _pyAgrum.MarkovNet_smallestFactorFromNode(self, node)
10443
10444    def factors(self) -> List[Set[int]]:
10445        return _pyAgrum.MarkovNet_factors(self)
10446
10447    def variableNodeMap(self) -> "pyAgrum.VariableNodeMap":
10448        return _pyAgrum.MarkovNet_variableNodeMap(self)
10449
10450    def add(self, *args) -> int:
10451        r"""
10452
10453        Add a variable to the pyAgrum.MarkovNet.
10454
10455        Parameters
10456        ----------
10457        variable : pyAgrum.DiscreteVariable
10458        	the variable added
10459        name : str
10460        	the variable name
10461        nbrmod : int
10462        	the number of modalities for the new variable
10463        id : int
10464        	the variable forced id in the pyAgrum.MarkovNet
10465
10466        Returns
10467        -------
10468        int
10469        	the id of the new node
10470
10471        Raises
10472        ------
10473        pyAgrum.DuplicateLabel
10474            If variable.name() is already used in this pyAgrum.MarkovNet.
10475        pyAgrum.NotAllowed
10476            If nbrmod is less than 2
10477        pyAgrum.DuplicateElement
10478            If id is already used.
10479
10480        """
10481        return _pyAgrum.MarkovNet_add(self, *args)
10482
10483    def clear(self) -> None:
10484        r"""
10485
10486        Clear the whole MarkovNet
10487
10488        """
10489        return _pyAgrum.MarkovNet_clear(self)
10490
10491    def erase(self, *args) -> None:
10492        r"""
10493
10494        Remove a variable from the pyAgrum.MarkovNet.
10495
10496        Removes the corresponding variable from the pyAgrum.MarkovNet and from all of it's children pyAgrum.Potential.
10497
10498        If no variable matches the given id, then nothing is done.
10499
10500        Parameters
10501        ----------
10502        id : int
10503        	The variable's id to remove.
10504        name : str
10505        	The variable's name to remove.
10506        var : pyAgrum.DiscreteVariable
10507        	A reference on the variable to remove.
10508
10509        """
10510        return _pyAgrum.MarkovNet_erase(self, *args)
10511
10512    def variable(self, *args) -> "pyAgrum.DiscreteVariable":
10513        return _pyAgrum.MarkovNet_variable(self, *args)
10514
10515    def changeVariableName(self, *args) -> None:
10516        r"""
10517
10518        Changes a variable's name in the pyAgrum.MarkovNet.
10519
10520        This will change the "pyAgrum.DiscreteVariable" names in the pyAgrum.MarkovNet.
10521
10522        Parameters
10523        ----------
10524        new_name : str
10525        	the new name of the variable
10526        NodeId : int
10527        	the id of the node
10528        name : str
10529        	the name of the variable
10530
10531        Raises
10532        ------
10533        pyAgrum.DuplicateLabel
10534            If new_name is already used in this MarkovNet.
10535        pyAgrum.NotFound
10536            If no variable matches id.
10537
10538        """
10539        return _pyAgrum.MarkovNet_changeVariableName(self, *args)
10540
10541    def changeVariableLabel(self, *args) -> None:
10542        r"""
10543
10544        change the label of the variable associated to nodeId to the new value.
10545
10546        Parameters
10547        ----------
10548        id : int
10549        	the id of the node
10550        name : str
10551        	the name of the variable
10552        old_label : str
10553        	the new label
10554        new_label : str
10555        	the new label
10556
10557        Raises
10558        ------
10559        pyAgrum.NotFound
10560            if id/name is not a variable or if old_label does not exist.
10561
10562        """
10563        return _pyAgrum.MarkovNet_changeVariableLabel(self, *args)
10564
10565    def nodeId(self, var: "pyAgrum.DiscreteVariable") -> int:
10566        return _pyAgrum.MarkovNet_nodeId(self, var)
10567
10568    def idFromName(self, name: str) -> int:
10569        return _pyAgrum.MarkovNet_idFromName(self, name)
10570
10571    def variableFromName(self, name: str) -> "pyAgrum.DiscreteVariable":
10572        return _pyAgrum.MarkovNet_variableFromName(self, name)
10573
10574    def generateFactors(self) -> None:
10575        r"""
10576
10577        Randomly generates factors parameters for a given structure.
10578
10579        """
10580        return _pyAgrum.MarkovNet_generateFactors(self)
10581
10582    def generateFactor(self, vars: List[int]) -> None:
10583        r"""
10584
10585        Randomly generate factor parameters for a given factor in a given structure.
10586
10587        Parameters
10588        ----------
10589        node : int
10590        	The variable's id.
10591        name : str
10592        	The variable's name.
10593
10594        """
10595        return _pyAgrum.MarkovNet_generateFactor(self, vars)
10596
10597    def beginTopologyTransformation(self) -> None:
10598        return _pyAgrum.MarkovNet_beginTopologyTransformation(self)
10599
10600    def endTopologyTransformation(self) -> None:
10601        r"""
10602
10603        Terminates a sequence of insertions/deletions of arcs by adjusting all CPTs dimensions.
10604        End Multiple Change for all CPTs.
10605
10606        Returns
10607        -------
10608        pyAgrum.MarkovNet
10609
10610        """
10611        return _pyAgrum.MarkovNet_endTopologyTransformation(self)
10612
10613    def graph(self) -> "pyAgrum.UndiGraph":
10614        return _pyAgrum.MarkovNet_graph(self)
10615
10616    def size(self) -> int:
10617        return _pyAgrum.MarkovNet_size(self)
10618
10619    def log10DomainSize(self) -> float:
10620        return _pyAgrum.MarkovNet_log10DomainSize(self)
10621
10622    def names(self) -> object:
10623        return _pyAgrum.MarkovNet_names(self)
10624
10625    def nodes(self) -> object:
10626        return _pyAgrum.MarkovNet_nodes(self)
10627
10628    def connectedComponents(self):
10629      """ connected components from a graph/BN
10630
10631      Compute the connected components of a pyAgrum's graph or Bayesian Network
10632      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
10633
10634      The firstly visited node for each component is called a 'root' and is used as a key for the component.
10635      This root has been arbitrarily chosen during the algorithm.
10636
10637      Returns
10638      -------
10639      dict(int,Set[int])
10640        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
10641
10642      """
10643      nodes=self.nodes()
10644      connected_components=dict()
10645
10646      def parcours(node,orig):
10647          cc={node}
10648          nodes.discard(node)
10649          if hasattr(self,'children'):
10650              for chi in self.children(node):
10651                  if chi!=orig:
10652                      if chi in nodes:
10653                          cc|=parcours(chi,node)
10654
10655          if hasattr(self,'parents'):
10656              for par in self.parents(node):
10657                  if par!=orig:
10658                      if par in nodes:
10659                          cc|=parcours(par,node)
10660
10661          if hasattr(self,'neighbours'):
10662              for nei in self.neighbours(node):
10663                  if nei!=orig:
10664                      if nei in nodes:
10665                          cc|=parcours(nei,node)
10666          return cc
10667
10668      while (len(nodes)>0):
10669          root=nodes.pop()
10670          connected_components[root]=parcours(root,None)
10671      return connected_components
10672
10673
10674    def neighbours(self, norid: object) -> object:
10675        return _pyAgrum.MarkovNet_neighbours(self, norid)
10676
10677    def edges(self) -> object:
10678        return _pyAgrum.MarkovNet_edges(self)
10679
10680    def minimalCondSet(self, *args) -> object:
10681        return _pyAgrum.MarkovNet_minimalCondSet(self, *args)
10682
10683    def factor(self, *args) -> "pyAgrum.Potential":
10684        r"""
10685
10686        Returns the factor of a set of variables (if existing).
10687
10688        Parameters
10689        ----------
10690        VarId : Set[int]
10691        	A variable's id in the pyAgrum.MarkovNet.
10692        name : Set[str]
10693        	A variable's name in the pyAgrum.MarkovNet.
10694
10695        Returns
10696        -------
10697        pyAgrum.Potential
10698        	The factor of the set of nodes.
10699
10700        Raises
10701        ------
10702        pyAgrum.NotFound
10703            If no variable's id matches varId.
10704
10705        """
10706        return _pyAgrum.MarkovNet_factor(self, *args)
10707
10708    def isIndependent(self, *args) -> bool:
10709        return _pyAgrum.MarkovNet_isIndependent(self, *args)
10710
10711    def loadUAI(self, *args) -> str:
10712        r"""
10713
10714        Load an UAI file.
10715
10716        Parameters
10717        ----------
10718        name : str
10719        	the name's file
10720        l : list
10721        	list of functions to execute
10722
10723        Raises
10724        ------
10725        pyAgrum.IOError
10726            If file not found
10727        pyAgrum.FatalError
10728            If file is not valid
10729
10730        """
10731        return _pyAgrum.MarkovNet_loadUAI(self, *args)
10732
10733    def saveUAI(self, name: str) -> None:
10734        r"""
10735
10736        Save the MarkovNet in an UAI file.
10737
10738        Parameters
10739        ----------
10740        name : str
10741        	the file's name
10742
10743        """
10744        return _pyAgrum.MarkovNet_saveUAI(self, name)
10745
10746    def __repr__(self) -> str:
10747        return _pyAgrum.MarkovNet___repr__(self)
10748
10749    def __str__(self) -> str:
10750        return _pyAgrum.MarkovNet___str__(self)
10751
10752    def addFactor(self, *args) -> "pyAgrum.Potential":
10753        return _pyAgrum.MarkovNet_addFactor(self, *args)
10754
10755    def eraseFactor(self, *args) -> None:
10756        return _pyAgrum.MarkovNet_eraseFactor(self, *args)
10757
10758    def addStructureListener(self,whenNodeAdded=None,whenNodeDeleted=None,whenEdgeAdded=None,whenedgeDeleted=None):
10759        """
10760        Add the listeners in parameters to the list of existing ones.
10761
10762        Parameters
10763        ----------
10764        whenNodeAdded : lambda expression
10765          a function for when a node is added
10766        whenNodeDeleted : lambda expression
10767          a function for when a node is removed
10768        whenEdgeAdded : lambda expression
10769          a function for when an edge is added
10770        whenEdgeDeleted : lambda expression
10771          a function for when an edge is removed
10772        """
10773        if [whenNodeAdded,whenNodeDeleted,whenEdgeAdded,whenEdgeDeleted]==[None,None,None,None]:
10774          return
10775
10776        if not hasattr(self,"_listeners"):
10777          self._listeners=[]
10778
10779        nl = PythonMNListener(self, self.variableNodeMap())
10780        if whenNodeAdded is not None:
10781          nl.setWhenNodeAdded(whenNodeAdded)
10782        if whenNodeDeleted is not None:
10783          nl.setWhenNodeDeleted(whenNodeDeleted)
10784        if whenEdgeAdded is not None:
10785          nl.setWhenEdgeAdded(whenEdgeAdded)
10786        if whenEdgeDeleted is not None:
10787          nl.setWhenArcDeleted(whenEdgeDeleted)
10788
10789        self._listeners.append(nl)
10790
10791
10792# Register MarkovNet in _pyAgrum:
10793_pyAgrum.MarkovNet_swigregister(MarkovNet)
10794
10795def MarkovNet_fastPrototype(dotlike: str, domainSize: int=2) -> "pyAgrum.MarkovNet":
10796    r"""
10797
10798    Create a Markov network with a modified dot-like syntax which specifies:
10799        - the structure ``a-b-c;b-d-e;``. The substring ``a-b-c`` indicates a factor with the scope (a,b,c).
10800        - the type of the variables with different syntax (cf documentation).
10801
10802    Examples
10803    --------
10804    >>> import pyAgrum as gum
10805    >>> bn=pyAgrum.MarkovNet.fastPrototype('A--B[1,3]-C{yes|No}--D[2,4]--E[1,2.5,3.9]',6)
10806
10807    Parameters
10808    ----------
10809    dotlike : str
10810            the string containing the specification
10811    domainSize : int
10812            the default domain size for variables
10813
10814    Returns
10815    -------
10816    pyAgrum.MarkovNet
10817            the resulting Markov network
10818
10819    """
10820    return _pyAgrum.MarkovNet_fastPrototype(dotlike, domainSize)
10821
10822def MarkovNet_fromBN(bn: "pyAgrum.BayesNet") -> "pyAgrum.MarkovNet":
10823    return _pyAgrum.MarkovNet_fromBN(bn)
10824
10825class ShaferShenoyMNInference(object):
10826    r"""
10827
10828    Class used for Shafer-Shenoy inferences for Markov network.
10829
10830    ShaferShenoyInference(bn) -> ShaferShenoyInference
10831        Parameters:
10832            * **mn** (*pyAgrum.MarkovNet*) -- a Markov network
10833
10834    """
10835
10836    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
10837    __repr__ = _swig_repr
10838
10839    def __init__(self, MN: "IMarkovNet", use_binary_join_tree: bool=True):
10840        _pyAgrum.ShaferShenoyMNInference_swiginit(self, _pyAgrum.new_ShaferShenoyMNInference(MN, use_binary_join_tree))
10841
10842        self._model=MN#first arg of the constructor
10843
10844
10845
10846    __swig_destroy__ = _pyAgrum.delete_ShaferShenoyMNInference
10847
10848    def setTriangulation(self, new_triangulation: "pyAgrum.Triangulation") -> None:
10849        return _pyAgrum.ShaferShenoyMNInference_setTriangulation(self, new_triangulation)
10850
10851    def joinTree(self) -> "pyAgrum.CliqueGraph":
10852        r"""
10853
10854        Returns
10855        -------
10856        pyAgrum.CliqueGraph
10857          the current join tree used
10858
10859        """
10860        return _pyAgrum.ShaferShenoyMNInference_joinTree(self)
10861
10862    def junctionTree(self) -> "pyAgrum.JunctionTree":
10863        r"""
10864
10865        Returns
10866        -------
10867        pyAgrum.CliqueGraph
10868          the current junction tree
10869
10870        """
10871        val = _pyAgrum.ShaferShenoyMNInference_junctionTree(self)
10872
10873        val._engine=self
10874
10875
10876        return val
10877
10878
10879    def evidenceProbability(self) -> float:
10880        r"""
10881
10882        Returns
10883        -------
10884        float
10885          the probability of evidence
10886
10887        """
10888        return _pyAgrum.ShaferShenoyMNInference_evidenceProbability(self)
10889
10890    def setEvidence(self, evidces):
10891        """
10892        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
10893
10894        Parameters
10895        ----------
10896        evidces : dict
10897          a dict of evidences
10898
10899        Raises
10900        ------
10901        gum.InvalidArgument
10902            If one value is not a value for the node
10903        gum.InvalidArgument
10904            If the size of a value is different from the domain side of the node
10905        gum.FatalError
10906            If one value is a vector of 0s
10907        gum.UndefinedElement
10908            If one node does not belong to the Bayesian network
10909        """
10910        if not isinstance(evidces, dict):
10911            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
10912        self.eraseAllEvidence()
10913        for k,v in evidces.items():
10914            self.addEvidence(k,v)
10915
10916
10917
10918    def updateEvidence(self, evidces):
10919        """
10920        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
10921
10922        Parameters
10923        ----------
10924        evidces : dict
10925          a dict of evidences
10926
10927        Raises
10928        ------
10929        gum.InvalidArgument
10930            If one value is not a value for the node
10931        gum.InvalidArgument
10932            If the size of a value is different from the domain side of the node
10933        gum.FatalError
10934            If one value is a vector of 0s
10935        gum.UndefinedElement
10936            If one node does not belong to the Bayesian network
10937        """
10938        if not isinstance(evidces, dict):
10939            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
10940
10941        for k,v in evidces.items():
10942            if self.hasEvidence(k):
10943                self.chgEvidence(k,v)
10944            else:
10945                self.addEvidence(k,v)
10946
10947
10948
10949    def setTargets(self, targets):
10950        """
10951        Remove all the targets and add the ones in parameter.
10952
10953        Parameters
10954        ----------
10955        targets : set
10956          a set of targets
10957
10958        Raises
10959        ------
10960        gum.UndefinedElement
10961            If one target is not in the Bayes net
10962        """
10963        if not isinstance(targets, set):
10964            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
10965
10966        self.eraseAllTargets()
10967        for k in targets:
10968            self.addTarget(k)
10969
10970
10971
10972    def hardEvidenceNodes(self) -> object:
10973        r"""
10974
10975        Returns
10976        -------
10977        set
10978          the set of nodes with hard evidence
10979
10980        """
10981        return _pyAgrum.ShaferShenoyMNInference_hardEvidenceNodes(self)
10982
10983    def softEvidenceNodes(self) -> object:
10984        r"""
10985
10986        Returns
10987        -------
10988        set
10989          the set of nodes with soft evidence
10990
10991        """
10992        return _pyAgrum.ShaferShenoyMNInference_softEvidenceNodes(self)
10993
10994    def targets(self) -> object:
10995        r"""
10996
10997        Returns
10998        -------
10999        list
11000          the list of marginal targets
11001
11002        """
11003        return _pyAgrum.ShaferShenoyMNInference_targets(self)
11004
11005    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
11006        r"""
11007
11008        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
11009
11010        Parameters
11011        ----------
11012        target : set
11013          a set of targets ids or names.
11014        evs : set
11015          a set of nodes ids or names.
11016
11017        Warnings
11018        --------
11019        if some evs are d-separated, they are not included in the Potential.
11020
11021        Returns
11022        -------
11023        pyAgrum.Potential
11024          a Potential for P(targets|evs)
11025
11026        """
11027        return _pyAgrum.ShaferShenoyMNInference_evidenceImpact(self, target, evs)
11028
11029    def jointMutualInformation(self, targets: object) -> float:
11030        return _pyAgrum.ShaferShenoyMNInference_jointMutualInformation(self, targets)
11031
11032    def jointPosterior(self, targets: object) -> "pyAgrum.Potential":
11033        r"""
11034
11035        Compute the joint posterior of a set of nodes.
11036
11037        Parameters
11038        ----------
11039        list :
11040          the list of nodes whose posterior joint probability is wanted
11041
11042
11043        Warnings
11044        --------
11045        The order of the variables given by the list here or when the jointTarget is declared can not be assumed to be used bu the Potential.
11046
11047        Returns
11048        -------
11049        pyAgrum.Potential
11050          a const ref to the posterior joint probability of the set of nodes.
11051
11052        Raises
11053        ------
11054        pyAgrum.UndefinedElement
11055          If an element of nodes is not in targets
11056
11057        """
11058        return _pyAgrum.ShaferShenoyMNInference_jointPosterior(self, targets)
11059
11060    def addJointTarget(self, targets: object) -> None:
11061        r"""
11062
11063        Add a list of nodes as a new joint target. As a collateral effect, every node is added as a marginal target.
11064
11065        Parameters
11066        ----------
11067        list
11068          a list of names of nodes
11069
11070        Raises
11071        ------
11072        pyAgrum.UndefinedElement
11073          If some node(s) do not belong to the Bayesian network
11074
11075        """
11076        return _pyAgrum.ShaferShenoyMNInference_addJointTarget(self, targets)
11077
11078    def eraseJointTarget(self, targets: object) -> None:
11079        r"""
11080
11081        Remove, if existing, the joint target.
11082
11083        Parameters
11084        ----------
11085        list
11086          a list of names or Ids of nodes
11087
11088        Raises
11089        ------
11090        pyAgrum.IndexError
11091          If one of the node does not belong to the Bayesian network
11092        pyAgrum.UndefinedElement
11093          If node Id is not in the Bayesian network
11094
11095        """
11096        return _pyAgrum.ShaferShenoyMNInference_eraseJointTarget(self, targets)
11097
11098    def isJointTarget(self, targets: object) -> bool:
11099        r"""
11100
11101        Parameters
11102        ----------
11103        list
11104          a list of nodes ids or names.
11105
11106        Returns
11107        -------
11108        bool
11109          True if target is a joint target.
11110
11111        Raises
11112        ------
11113        pyAgrum.IndexError
11114          If the node does not belong to the Bayesian network
11115        pyAgrum.UndefinedElement
11116          If node Id is not in the Bayesian network
11117
11118        """
11119        return _pyAgrum.ShaferShenoyMNInference_isJointTarget(self, targets)
11120
11121    def jointTargets(self) -> object:
11122        r"""
11123
11124        Returns
11125        -------
11126        list
11127          the list of target sets
11128
11129        """
11130        return _pyAgrum.ShaferShenoyMNInference_jointTargets(self)
11131
11132    def makeInference(self) -> None:
11133        r"""
11134
11135        Perform the heavy computations needed to compute the targets' posteriors
11136
11137        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
11138        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
11139
11140        """
11141        return _pyAgrum.ShaferShenoyMNInference_makeInference(self)
11142
11143    def addEvidence(self, *args) -> None:
11144        r"""
11145
11146        Adds a new evidence on a node (might be soft or hard).
11147
11148        Parameters
11149        ----------
11150        id : int
11151          a node Id
11152        nodeName : int
11153          a node name
11154        val :
11155          (int) a node value
11156        val :
11157          (str) the label of the node value
11158        vals : list
11159          a list of values
11160
11161        Raises
11162        ------
11163        pyAgrum.InvalidArgument
11164          If the node already has an evidence
11165        pyAgrum.InvalidArgument
11166          If val is not a value for the node
11167        pyAgrum.InvalidArgument
11168          If the size of vals is different from the domain side of the node
11169        pyAgrum.FatalError
11170          If vals is a vector of 0s
11171        pyAgrum.UndefinedElement
11172          If the node does not belong to the Bayesian network
11173
11174        """
11175        return _pyAgrum.ShaferShenoyMNInference_addEvidence(self, *args)
11176
11177    def chgEvidence(self, *args) -> None:
11178        r"""
11179
11180        Change the value of an already existing evidence on a node (might be soft or hard).
11181
11182        Parameters
11183        ----------
11184        id : int
11185          a node Id
11186        nodeName : int
11187          a node name
11188        val :
11189          (int) a node value
11190        val :
11191          (str) the label of the node value
11192        vals : list
11193          a list of values
11194
11195        Raises
11196        ------
11197        pyAgrum.InvalidArgument
11198          If the node does not already have an evidence
11199        pyAgrum.InvalidArgument
11200          If val is not a value for the node
11201        pyAgrum.InvalidArgument
11202          If the size of vals is different from the domain side of the node
11203        pyAgrum.FatalError
11204          If vals is a vector of 0s
11205        pyAgrum.UndefinedElement
11206          If the node does not belong to the Bayesian network
11207
11208        """
11209        return _pyAgrum.ShaferShenoyMNInference_chgEvidence(self, *args)
11210
11211    def hasEvidence(self, *args) -> bool:
11212        r"""
11213
11214        Parameters
11215        ----------
11216        id : int
11217          a node Id
11218        nodeName : str
11219          a node name
11220
11221        Returns
11222        -------
11223        bool
11224          True if some node(s) (or the one in parameters) have received evidence
11225
11226        Raises
11227        ------
11228        pyAgrum.IndexError
11229          If the node does not belong to the Bayesian network
11230
11231        """
11232        return _pyAgrum.ShaferShenoyMNInference_hasEvidence(self, *args)
11233
11234    def eraseAllEvidence(self) -> None:
11235        r"""
11236
11237        Removes all the evidence entered into the network.
11238
11239        """
11240        return _pyAgrum.ShaferShenoyMNInference_eraseAllEvidence(self)
11241
11242    def eraseEvidence(self, *args) -> None:
11243        r"""
11244
11245        Remove the evidence, if any, corresponding to the node Id or name.
11246
11247        Parameters
11248        ----------
11249        id : int
11250          a node Id
11251        nodeName : int
11252          a node name
11253
11254        Raises
11255        ------
11256        pyAgrum.IndexError
11257          If the node does not belong to the Bayesian network
11258
11259        """
11260        return _pyAgrum.ShaferShenoyMNInference_eraseEvidence(self, *args)
11261
11262    def hasHardEvidence(self, nodeName: str) -> bool:
11263        r"""
11264
11265        Parameters
11266        ----------
11267        id : int
11268          a node Id
11269        nodeName : str
11270          a node name
11271
11272        Returns
11273        -------
11274        bool
11275          True if node has received a hard evidence
11276
11277        Raises
11278        ------
11279        pyAgrum.IndexError
11280          If the node does not belong to the Bayesian network
11281
11282        """
11283        return _pyAgrum.ShaferShenoyMNInference_hasHardEvidence(self, nodeName)
11284
11285    def hasSoftEvidence(self, *args) -> bool:
11286        r"""
11287
11288        Parameters
11289        ----------
11290        id : int
11291          a node Id
11292        nodeName : str
11293          a node name
11294
11295        Returns
11296        -------
11297        bool
11298          True if node has received a soft evidence
11299
11300        Raises
11301        ------
11302        pyAgrum.IndexError
11303          If the node does not belong to the Bayesian network
11304
11305        """
11306        return _pyAgrum.ShaferShenoyMNInference_hasSoftEvidence(self, *args)
11307
11308    def nbrEvidence(self) -> int:
11309        r"""
11310
11311        Returns
11312        -------
11313        int
11314          the number of evidence entered into the Bayesian network
11315
11316        """
11317        return _pyAgrum.ShaferShenoyMNInference_nbrEvidence(self)
11318
11319    def nbrHardEvidence(self) -> int:
11320        r"""
11321
11322        Returns
11323        -------
11324        int
11325          the number of hard evidence entered into the Bayesian network
11326
11327        """
11328        return _pyAgrum.ShaferShenoyMNInference_nbrHardEvidence(self)
11329
11330    def nbrSoftEvidence(self) -> int:
11331        r"""
11332
11333        Returns
11334        -------
11335        int
11336          the number of soft evidence entered into the Bayesian network
11337
11338        """
11339        return _pyAgrum.ShaferShenoyMNInference_nbrSoftEvidence(self)
11340
11341    def eraseAllTargets(self) -> None:
11342        r"""
11343
11344        Clear all previously defined targets (marginal and joint targets).
11345
11346        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
11347
11348        """
11349        return _pyAgrum.ShaferShenoyMNInference_eraseAllTargets(self)
11350
11351    def addAllTargets(self) -> None:
11352        r"""
11353
11354        Add all the nodes as targets.
11355
11356        """
11357        return _pyAgrum.ShaferShenoyMNInference_addAllTargets(self)
11358
11359    def addTarget(self, *args) -> None:
11360        r"""
11361
11362        Add a marginal target to the list of targets.
11363
11364        Parameters
11365        ----------
11366        target : int
11367          a node Id
11368        nodeName : str
11369          a node name
11370
11371        Raises
11372        ------
11373        pyAgrum.UndefinedElement
11374          If target is not a NodeId in the Bayes net
11375
11376        """
11377        return _pyAgrum.ShaferShenoyMNInference_addTarget(self, *args)
11378
11379    def eraseTarget(self, *args) -> None:
11380        r"""
11381
11382        Remove, if existing, the marginal target.
11383
11384        Parameters
11385        ----------
11386        target : int
11387          a node Id
11388        nodeName : int
11389          a node name
11390
11391        Raises
11392        ------
11393        pyAgrum.IndexError
11394          If one of the node does not belong to the Bayesian network
11395        pyAgrum.UndefinedElement
11396          If node Id is not in the Bayesian network
11397
11398        """
11399        return _pyAgrum.ShaferShenoyMNInference_eraseTarget(self, *args)
11400
11401    def isTarget(self, *args) -> bool:
11402        r"""
11403
11404        Parameters
11405        ----------
11406        variable : int
11407         a node Id
11408        nodeName : str
11409          a node name
11410
11411        Returns
11412        -------
11413        bool
11414          True if variable is a (marginal) target
11415
11416        Raises
11417        ------
11418        pyAgrum.IndexError
11419          If the node does not belong to the Bayesian network
11420        pyAgrum.UndefinedElement
11421          If node Id is not in the Bayesian network
11422
11423        """
11424        return _pyAgrum.ShaferShenoyMNInference_isTarget(self, *args)
11425
11426    def nbrTargets(self) -> int:
11427        r"""
11428
11429        Returns
11430        -------
11431        int
11432          the number of marginal targets
11433
11434        """
11435        return _pyAgrum.ShaferShenoyMNInference_nbrTargets(self)
11436
11437    def H(self, *args) -> float:
11438        r"""
11439
11440        Parameters
11441        ----------
11442        X : int
11443          a node Id
11444        nodeName : str
11445          a node name
11446
11447        Returns
11448        -------
11449        float
11450          the Shanon's entropy of a node given the observation
11451
11452        """
11453        return _pyAgrum.ShaferShenoyMNInference_H(self, *args)
11454
11455    def MN(self) -> "pyAgrum.IMarkovNet":
11456        return _pyAgrum.ShaferShenoyMNInference_MN(self)
11457
11458    def posterior(self, *args) -> "pyAgrum.Potential":
11459        r"""
11460
11461        Computes and returns the posterior of a node.
11462
11463        Parameters
11464        ----------
11465        var : int
11466          the node Id of the node for which we need a posterior probability
11467        nodeName : str
11468          the node name of the node for which we need a posterior probability
11469
11470        Returns
11471        -------
11472        pyAgrum.Potential
11473          a const ref to the posterior probability of the node
11474
11475        Raises
11476        ------
11477        pyAgrum.UndefinedElement
11478          If an element of nodes is not in targets
11479
11480        """
11481        return _pyAgrum.ShaferShenoyMNInference_posterior(self, *args)
11482
11483    def eraseAllJointTargets(self) -> None:
11484        r"""
11485
11486        Clear all previously defined joint targets.
11487
11488        """
11489        return _pyAgrum.ShaferShenoyMNInference_eraseAllJointTargets(self)
11490
11491    def eraseAllMarginalTargets(self) -> None:
11492        r"""
11493
11494        Clear all the previously defined marginal targets.
11495
11496        """
11497        return _pyAgrum.ShaferShenoyMNInference_eraseAllMarginalTargets(self)
11498
11499    def nbrJointTargets(self) -> int:
11500        r"""
11501
11502        Returns
11503        -------
11504        int
11505          the number of joint targets
11506
11507        """
11508        return _pyAgrum.ShaferShenoyMNInference_nbrJointTargets(self)
11509
11510    def I(self, X: int, Y: int) -> float:
11511        r"""
11512
11513        Parameters
11514        ----------
11515        X : int or str
11516          a node Id or a node name
11517        Y : int or str
11518          another node Id or node name
11519
11520        Returns
11521        -------
11522        float
11523          the Mutual Information of X and Y given the observation
11524
11525        """
11526        return _pyAgrum.ShaferShenoyMNInference_I(self, X, Y)
11527
11528    def VI(self, X: int, Y: int) -> float:
11529        r"""
11530
11531        Parameters
11532        ----------
11533        X : int or str
11534           a node Id or a node name
11535        Y : int or str
11536           another node Id or node name
11537
11538        Returns
11539        -------
11540        float
11541          variation of information between X and Y
11542
11543        """
11544        return _pyAgrum.ShaferShenoyMNInference_VI(self, X, Y)
11545
11546    def evidenceJointImpact(self, *args) -> "pyAgrum.Potential":
11547        r"""
11548
11549        Create a pyAgrum.Potential for P(joint targets|evs) (for all instanciation of targets and evs)
11550
11551        Parameters
11552        ----------
11553        targets :
11554          (int) a node Id
11555        targets :
11556          (str) a node name
11557        evs : set
11558          a set of nodes ids or names.
11559
11560        Returns
11561        -------
11562        pyAgrum.Potential
11563          a Potential for P(target|evs)
11564
11565        Raises
11566        ------
11567        pyAgrum.Exception
11568          If some evidene entered into the Bayes net are incompatible (their joint proba = 0)
11569
11570        """
11571        return _pyAgrum.ShaferShenoyMNInference_evidenceJointImpact(self, *args)
11572
11573# Register ShaferShenoyMNInference in _pyAgrum:
11574_pyAgrum.ShaferShenoyMNInference_swigregister(ShaferShenoyMNInference)
11575
11576class LazyPropagation(object):
11577    r"""
11578
11579    Class used for Lazy Propagation
11580
11581    LazyPropagation(bn) -> LazyPropagation
11582        Parameters:
11583            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
11584
11585    """
11586
11587    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
11588    __repr__ = _swig_repr
11589
11590    def __init__(self, *args):
11591        _pyAgrum.LazyPropagation_swiginit(self, _pyAgrum.new_LazyPropagation(*args))
11592
11593        self._model=args[0]
11594
11595
11596
11597    __swig_destroy__ = _pyAgrum.delete_LazyPropagation
11598
11599    def setTriangulation(self, new_triangulation: "pyAgrum.Triangulation") -> None:
11600        return _pyAgrum.LazyPropagation_setTriangulation(self, new_triangulation)
11601
11602    def setRelevantPotentialsFinderType(self, type: int) -> None:
11603        r"""
11604
11605        sets how we determine the relevant potentials to combine
11606
11607        When a clique sends a message to a separator, it first constitute the set of the potentials it contains and of the potentials contained in the messages it received. If RelevantPotentialsFinderType = FIND_ALL, all these potentials are combined and projected to produce the message sent to the separator. If RelevantPotentialsFinderType = DSEP_BAYESBALL_NODES, then only the set of potentials d-connected to the variables of the separator are kept for combination and projection.
11608
11609        0 = FIND_ALL
11610        1 = DSEP_BAYESBALL_NODES
11611        2 = DSEP_BAYESBALL_POTENTIALS
11612        3 = DSEP_KOLLER_FRIEDMAN_2009
11613
11614        Parameters
11615        ----------
11616        type : int
11617          the finder type
11618
11619        Raises
11620        ------
11621        pyAgrum.InvalidArgument
11622          If type is not implemented
11623
11624        """
11625        return _pyAgrum.LazyPropagation_setRelevantPotentialsFinderType(self, type)
11626
11627    def setFindBarrenNodesType(self, type: int) -> None:
11628        r"""
11629
11630        sets how we determine barren nodes
11631
11632        Barren nodes are unnecessary for probability inference, so they can be safely discarded in this case (type = FIND_BARREN_NODES). This speeds-up inference. However, there are some cases in which we do not want to remove barren nodes, typically when we want to answer queries such as Most Probable Explanations (MPE).
11633
11634        0 = FIND_NO_BARREN_NODES
11635        1 = FIND_BARREN_NODES
11636
11637        Parameters
11638        ----------
11639        type : int
11640          the finder type
11641
11642        Raises
11643        ------
11644        pyAgrum.InvalidArgument
11645          If type is not implemented
11646
11647        """
11648        return _pyAgrum.LazyPropagation_setFindBarrenNodesType(self, type)
11649
11650    def joinTree(self) -> "pyAgrum.CliqueGraph":
11651        r"""
11652
11653        Returns
11654        -------
11655        pyAgrum.CliqueGraph
11656          the current join tree used
11657
11658        """
11659        return _pyAgrum.LazyPropagation_joinTree(self)
11660
11661    def junctionTree(self) -> "pyAgrum.JunctionTree":
11662        r"""
11663
11664        Returns
11665        -------
11666        pyAgrum.CliqueGraph
11667          the current junction tree
11668
11669        """
11670        val = _pyAgrum.LazyPropagation_junctionTree(self)
11671
11672        val._engine=self
11673
11674
11675        return val
11676
11677
11678    def evidenceProbability(self) -> float:
11679        r"""
11680
11681        Returns
11682        -------
11683        float
11684          the probability of evidence
11685
11686        """
11687        return _pyAgrum.LazyPropagation_evidenceProbability(self)
11688
11689    def setEvidence(self, evidces):
11690        """
11691        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
11692
11693        Parameters
11694        ----------
11695        evidces : dict
11696          a dict of evidences
11697
11698        Raises
11699        ------
11700        gum.InvalidArgument
11701            If one value is not a value for the node
11702        gum.InvalidArgument
11703            If the size of a value is different from the domain side of the node
11704        gum.FatalError
11705            If one value is a vector of 0s
11706        gum.UndefinedElement
11707            If one node does not belong to the Bayesian network
11708        """
11709        if not isinstance(evidces, dict):
11710            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
11711        self.eraseAllEvidence()
11712        for k,v in evidces.items():
11713            self.addEvidence(k,v)
11714
11715
11716
11717    def updateEvidence(self, evidces):
11718        """
11719        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
11720
11721        Parameters
11722        ----------
11723        evidces : dict
11724          a dict of evidences
11725
11726        Raises
11727        ------
11728        gum.InvalidArgument
11729            If one value is not a value for the node
11730        gum.InvalidArgument
11731            If the size of a value is different from the domain side of the node
11732        gum.FatalError
11733            If one value is a vector of 0s
11734        gum.UndefinedElement
11735            If one node does not belong to the Bayesian network
11736        """
11737        if not isinstance(evidces, dict):
11738            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
11739
11740        for k,v in evidces.items():
11741            if self.hasEvidence(k):
11742                self.chgEvidence(k,v)
11743            else:
11744                self.addEvidence(k,v)
11745
11746
11747
11748    def setTargets(self, targets):
11749        """
11750        Remove all the targets and add the ones in parameter.
11751
11752        Parameters
11753        ----------
11754        targets : set
11755          a set of targets
11756
11757        Raises
11758        ------
11759        gum.UndefinedElement
11760            If one target is not in the Bayes net
11761        """
11762        if not isinstance(targets, set):
11763            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
11764
11765        self.eraseAllTargets()
11766        for k in targets:
11767            self.addTarget(k)
11768
11769
11770
11771    def hardEvidenceNodes(self) -> object:
11772        r"""
11773
11774        Returns
11775        -------
11776        set
11777          the set of nodes with hard evidence
11778
11779        """
11780        return _pyAgrum.LazyPropagation_hardEvidenceNodes(self)
11781
11782    def softEvidenceNodes(self) -> object:
11783        r"""
11784
11785        Returns
11786        -------
11787        set
11788          the set of nodes with soft evidence
11789
11790        """
11791        return _pyAgrum.LazyPropagation_softEvidenceNodes(self)
11792
11793    def targets(self) -> object:
11794        r"""
11795
11796        Returns
11797        -------
11798        list
11799          the list of marginal targets
11800
11801        """
11802        return _pyAgrum.LazyPropagation_targets(self)
11803
11804    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
11805        r"""
11806
11807        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
11808
11809        Parameters
11810        ----------
11811        target : set
11812          a set of targets ids or names.
11813        evs : set
11814          a set of nodes ids or names.
11815
11816        Warnings
11817        --------
11818        if some evs are d-separated, they are not included in the Potential.
11819
11820        Returns
11821        -------
11822        pyAgrum.Potential
11823          a Potential for P(targets|evs)
11824
11825        """
11826        return _pyAgrum.LazyPropagation_evidenceImpact(self, target, evs)
11827
11828    def jointMutualInformation(self, targets: object) -> float:
11829        return _pyAgrum.LazyPropagation_jointMutualInformation(self, targets)
11830
11831    def jointPosterior(self, targets: object) -> "pyAgrum.Potential":
11832        r"""
11833
11834        Compute the joint posterior of a set of nodes.
11835
11836        Parameters
11837        ----------
11838        list :
11839          the list of nodes whose posterior joint probability is wanted
11840
11841
11842        Warnings
11843        --------
11844        The order of the variables given by the list here or when the jointTarget is declared can not be assumed to be used bu the Potential.
11845
11846        Returns
11847        -------
11848        pyAgrum.Potential
11849          a const ref to the posterior joint probability of the set of nodes.
11850
11851        Raises
11852        ------
11853        pyAgrum.UndefinedElement
11854          If an element of nodes is not in targets
11855
11856        """
11857        return _pyAgrum.LazyPropagation_jointPosterior(self, targets)
11858
11859    def addJointTarget(self, targets: object) -> None:
11860        r"""
11861
11862        Add a list of nodes as a new joint target. As a collateral effect, every node is added as a marginal target.
11863
11864        Parameters
11865        ----------
11866        list
11867          a list of names of nodes
11868
11869        Raises
11870        ------
11871        pyAgrum.UndefinedElement
11872          If some node(s) do not belong to the Bayesian network
11873
11874        """
11875        return _pyAgrum.LazyPropagation_addJointTarget(self, targets)
11876
11877    def eraseJointTarget(self, targets: object) -> None:
11878        r"""
11879
11880        Remove, if existing, the joint target.
11881
11882        Parameters
11883        ----------
11884        list
11885          a list of names or Ids of nodes
11886
11887        Raises
11888        ------
11889        pyAgrum.IndexError
11890          If one of the node does not belong to the Bayesian network
11891        pyAgrum.UndefinedElement
11892          If node Id is not in the Bayesian network
11893
11894        """
11895        return _pyAgrum.LazyPropagation_eraseJointTarget(self, targets)
11896
11897    def isJointTarget(self, targets: object) -> bool:
11898        r"""
11899
11900        Parameters
11901        ----------
11902        list
11903          a list of nodes ids or names.
11904
11905        Returns
11906        -------
11907        bool
11908          True if target is a joint target.
11909
11910        Raises
11911        ------
11912        pyAgrum.IndexError
11913          If the node does not belong to the Bayesian network
11914        pyAgrum.UndefinedElement
11915          If node Id is not in the Bayesian network
11916
11917        """
11918        return _pyAgrum.LazyPropagation_isJointTarget(self, targets)
11919
11920    def jointTargets(self) -> object:
11921        r"""
11922
11923        Returns
11924        -------
11925        list
11926          the list of target sets
11927
11928        """
11929        return _pyAgrum.LazyPropagation_jointTargets(self)
11930
11931    def makeInference(self) -> None:
11932        r"""
11933
11934        Perform the heavy computations needed to compute the targets' posteriors
11935
11936        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
11937        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
11938
11939        """
11940        return _pyAgrum.LazyPropagation_makeInference(self)
11941
11942    def addEvidence(self, *args) -> None:
11943        r"""
11944
11945        Adds a new evidence on a node (might be soft or hard).
11946
11947        Parameters
11948        ----------
11949        id : int
11950          a node Id
11951        nodeName : int
11952          a node name
11953        val :
11954          (int) a node value
11955        val :
11956          (str) the label of the node value
11957        vals : list
11958          a list of values
11959
11960        Raises
11961        ------
11962        pyAgrum.InvalidArgument
11963          If the node already has an evidence
11964        pyAgrum.InvalidArgument
11965          If val is not a value for the node
11966        pyAgrum.InvalidArgument
11967          If the size of vals is different from the domain side of the node
11968        pyAgrum.FatalError
11969          If vals is a vector of 0s
11970        pyAgrum.UndefinedElement
11971          If the node does not belong to the Bayesian network
11972
11973        """
11974        return _pyAgrum.LazyPropagation_addEvidence(self, *args)
11975
11976    def chgEvidence(self, *args) -> None:
11977        r"""
11978
11979        Change the value of an already existing evidence on a node (might be soft or hard).
11980
11981        Parameters
11982        ----------
11983        id : int
11984          a node Id
11985        nodeName : int
11986          a node name
11987        val :
11988          (int) a node value
11989        val :
11990          (str) the label of the node value
11991        vals : list
11992          a list of values
11993
11994        Raises
11995        ------
11996        pyAgrum.InvalidArgument
11997          If the node does not already have an evidence
11998        pyAgrum.InvalidArgument
11999          If val is not a value for the node
12000        pyAgrum.InvalidArgument
12001          If the size of vals is different from the domain side of the node
12002        pyAgrum.FatalError
12003          If vals is a vector of 0s
12004        pyAgrum.UndefinedElement
12005          If the node does not belong to the Bayesian network
12006
12007        """
12008        return _pyAgrum.LazyPropagation_chgEvidence(self, *args)
12009
12010    def hasEvidence(self, *args) -> bool:
12011        r"""
12012
12013        Parameters
12014        ----------
12015        id : int
12016          a node Id
12017        nodeName : str
12018          a node name
12019
12020        Returns
12021        -------
12022        bool
12023          True if some node(s) (or the one in parameters) have received evidence
12024
12025        Raises
12026        ------
12027        pyAgrum.IndexError
12028          If the node does not belong to the Bayesian network
12029
12030        """
12031        return _pyAgrum.LazyPropagation_hasEvidence(self, *args)
12032
12033    def eraseAllEvidence(self) -> None:
12034        r"""
12035
12036        Removes all the evidence entered into the network.
12037
12038        """
12039        return _pyAgrum.LazyPropagation_eraseAllEvidence(self)
12040
12041    def eraseEvidence(self, *args) -> None:
12042        r"""
12043
12044        Remove the evidence, if any, corresponding to the node Id or name.
12045
12046        Parameters
12047        ----------
12048        id : int
12049          a node Id
12050        nodeName : int
12051          a node name
12052
12053        Raises
12054        ------
12055        pyAgrum.IndexError
12056          If the node does not belong to the Bayesian network
12057
12058        """
12059        return _pyAgrum.LazyPropagation_eraseEvidence(self, *args)
12060
12061    def hasHardEvidence(self, nodeName: str) -> bool:
12062        r"""
12063
12064        Parameters
12065        ----------
12066        id : int
12067          a node Id
12068        nodeName : str
12069          a node name
12070
12071        Returns
12072        -------
12073        bool
12074          True if node has received a hard evidence
12075
12076        Raises
12077        ------
12078        pyAgrum.IndexError
12079          If the node does not belong to the Bayesian network
12080
12081        """
12082        return _pyAgrum.LazyPropagation_hasHardEvidence(self, nodeName)
12083
12084    def hasSoftEvidence(self, *args) -> bool:
12085        r"""
12086
12087        Parameters
12088        ----------
12089        id : int
12090          a node Id
12091        nodeName : str
12092          a node name
12093
12094        Returns
12095        -------
12096        bool
12097          True if node has received a soft evidence
12098
12099        Raises
12100        ------
12101        pyAgrum.IndexError
12102          If the node does not belong to the Bayesian network
12103
12104        """
12105        return _pyAgrum.LazyPropagation_hasSoftEvidence(self, *args)
12106
12107    def nbrEvidence(self) -> int:
12108        r"""
12109
12110        Returns
12111        -------
12112        int
12113          the number of evidence entered into the Bayesian network
12114
12115        """
12116        return _pyAgrum.LazyPropagation_nbrEvidence(self)
12117
12118    def nbrHardEvidence(self) -> int:
12119        r"""
12120
12121        Returns
12122        -------
12123        int
12124          the number of hard evidence entered into the Bayesian network
12125
12126        """
12127        return _pyAgrum.LazyPropagation_nbrHardEvidence(self)
12128
12129    def nbrSoftEvidence(self) -> int:
12130        r"""
12131
12132        Returns
12133        -------
12134        int
12135          the number of soft evidence entered into the Bayesian network
12136
12137        """
12138        return _pyAgrum.LazyPropagation_nbrSoftEvidence(self)
12139
12140    def eraseAllTargets(self) -> None:
12141        r"""
12142
12143        Clear all previously defined targets (marginal and joint targets).
12144
12145        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
12146
12147        """
12148        return _pyAgrum.LazyPropagation_eraseAllTargets(self)
12149
12150    def addAllTargets(self) -> None:
12151        r"""
12152
12153        Add all the nodes as targets.
12154
12155        """
12156        return _pyAgrum.LazyPropagation_addAllTargets(self)
12157
12158    def addTarget(self, *args) -> None:
12159        r"""
12160
12161        Add a marginal target to the list of targets.
12162
12163        Parameters
12164        ----------
12165        target : int
12166          a node Id
12167        nodeName : str
12168          a node name
12169
12170        Raises
12171        ------
12172        pyAgrum.UndefinedElement
12173          If target is not a NodeId in the Bayes net
12174
12175        """
12176        return _pyAgrum.LazyPropagation_addTarget(self, *args)
12177
12178    def eraseTarget(self, *args) -> None:
12179        r"""
12180
12181        Remove, if existing, the marginal target.
12182
12183        Parameters
12184        ----------
12185        target : int
12186          a node Id
12187        nodeName : int
12188          a node name
12189
12190        Raises
12191        ------
12192        pyAgrum.IndexError
12193          If one of the node does not belong to the Bayesian network
12194        pyAgrum.UndefinedElement
12195          If node Id is not in the Bayesian network
12196
12197        """
12198        return _pyAgrum.LazyPropagation_eraseTarget(self, *args)
12199
12200    def isTarget(self, *args) -> bool:
12201        r"""
12202
12203        Parameters
12204        ----------
12205        variable : int
12206         a node Id
12207        nodeName : str
12208          a node name
12209
12210        Returns
12211        -------
12212        bool
12213          True if variable is a (marginal) target
12214
12215        Raises
12216        ------
12217        pyAgrum.IndexError
12218          If the node does not belong to the Bayesian network
12219        pyAgrum.UndefinedElement
12220          If node Id is not in the Bayesian network
12221
12222        """
12223        return _pyAgrum.LazyPropagation_isTarget(self, *args)
12224
12225    def nbrTargets(self) -> int:
12226        r"""
12227
12228        Returns
12229        -------
12230        int
12231          the number of marginal targets
12232
12233        """
12234        return _pyAgrum.LazyPropagation_nbrTargets(self)
12235
12236    def H(self, *args) -> float:
12237        r"""
12238
12239        Parameters
12240        ----------
12241        X : int
12242          a node Id
12243        nodeName : str
12244          a node name
12245
12246        Returns
12247        -------
12248        float
12249          the computed Shanon's entropy of a node given the observation
12250
12251        """
12252        return _pyAgrum.LazyPropagation_H(self, *args)
12253
12254    def BN(self) -> "pyAgrum.IBayesNet":
12255        r"""
12256
12257        Returns
12258        -------
12259        pyAgrum.IBayesNet
12260          A constant reference over the IBayesNet referenced by this class.
12261
12262        Raises
12263        ------
12264        pyAgrum.UndefinedElement
12265          If no Bayes net has been assigned to the inference.
12266
12267        """
12268        return _pyAgrum.LazyPropagation_BN(self)
12269
12270    def posterior(self, *args) -> "pyAgrum.Potential":
12271        r"""
12272
12273        Computes and returns the posterior of a node.
12274
12275        Parameters
12276        ----------
12277        var : int
12278          the node Id of the node for which we need a posterior probability
12279        nodeName : str
12280          the node name of the node for which we need a posterior probability
12281
12282        Returns
12283        -------
12284        pyAgrum.Potential
12285          a const ref to the posterior probability of the node
12286
12287        Raises
12288        ------
12289        pyAgrum.UndefinedElement
12290          If an element of nodes is not in targets
12291
12292        """
12293        return _pyAgrum.LazyPropagation_posterior(self, *args)
12294
12295    def eraseAllJointTargets(self) -> None:
12296        r"""
12297
12298        Clear all previously defined joint targets.
12299
12300        """
12301        return _pyAgrum.LazyPropagation_eraseAllJointTargets(self)
12302
12303    def eraseAllMarginalTargets(self) -> None:
12304        r"""
12305
12306        Clear all the previously defined marginal targets.
12307
12308        """
12309        return _pyAgrum.LazyPropagation_eraseAllMarginalTargets(self)
12310
12311    def nbrJointTargets(self) -> int:
12312        r"""
12313
12314        Returns
12315        -------
12316        int
12317          the number of joint targets
12318
12319        """
12320        return _pyAgrum.LazyPropagation_nbrJointTargets(self)
12321
12322    def I(self, *args) -> float:
12323        r"""
12324
12325        Parameters
12326        ----------
12327        X : int or str
12328           a node Id or a node name
12329        Y : int or str
12330           another node Id or node name
12331
12332           Returns
12333        -------
12334        float
12335           the Mutual Information of X and Y given the observation
12336
12337        """
12338        return _pyAgrum.LazyPropagation_I(self, *args)
12339
12340    def VI(self, *args) -> float:
12341        r"""
12342
12343        Parameters
12344        ----------
12345        X : int or str
12346           a node Id or a node name
12347        Y : int or str
12348           another node Id or node name
12349
12350           Returns
12351        -------
12352        float
12353           variation of information between X and Y
12354
12355        """
12356        return _pyAgrum.LazyPropagation_VI(self, *args)
12357
12358    def evidenceJointImpact(self, *args) -> "pyAgrum.Potential":
12359        r"""
12360
12361        Create a pyAgrum.Potential for P(joint targets|evs) (for all instanciation of targets and evs)
12362
12363        Parameters
12364        ----------
12365        targets :
12366          (int) a node Id
12367        targets :
12368          (str) a node name
12369        evs : set
12370          a set of nodes ids or names.
12371
12372        Returns
12373        -------
12374        pyAgrum.Potential
12375          a Potential for P(target|evs)
12376
12377        Raises
12378        ------
12379        pyAgrum.Exception
12380          If some evidene entered into the Bayes net are incompatible (their joint proba = 0)
12381
12382        """
12383        return _pyAgrum.LazyPropagation_evidenceJointImpact(self, *args)
12384
12385# Register LazyPropagation in _pyAgrum:
12386_pyAgrum.LazyPropagation_swigregister(LazyPropagation)
12387
12388class ShaferShenoyInference(object):
12389    r"""
12390
12391    Class used for Shafer-Shenoy inferences.
12392
12393    ShaferShenoyInference(bn) -> ShaferShenoyInference
12394        Parameters:
12395            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
12396
12397    """
12398
12399    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
12400    __repr__ = _swig_repr
12401
12402    def __init__(self, *args):
12403        _pyAgrum.ShaferShenoyInference_swiginit(self, _pyAgrum.new_ShaferShenoyInference(*args))
12404
12405        self._model=args[0]
12406
12407
12408
12409    __swig_destroy__ = _pyAgrum.delete_ShaferShenoyInference
12410
12411    def setTriangulation(self, new_triangulation: "pyAgrum.Triangulation") -> None:
12412        return _pyAgrum.ShaferShenoyInference_setTriangulation(self, new_triangulation)
12413
12414    def setFindBarrenNodesType(self, type: int) -> None:
12415        r"""
12416
12417        sets how we determine barren nodes
12418
12419        Barren nodes are unnecessary for probability inference, so they can be safely discarded in this case (type = FIND_BARREN_NODES). This speeds-up inference. However, there are some cases in which we do not want to remove barren nodes, typically when we want to answer queries such as Most Probable Explanations (MPE).
12420
12421        0 = FIND_NO_BARREN_NODES
12422        1 = FIND_BARREN_NODES
12423
12424        Parameters
12425        ----------
12426        type : int
12427          the finder type
12428
12429        Raises
12430        ------
12431        pyAgrum.InvalidArgument
12432          If type is not implemented
12433
12434        """
12435        return _pyAgrum.ShaferShenoyInference_setFindBarrenNodesType(self, type)
12436
12437    def joinTree(self) -> "pyAgrum.CliqueGraph":
12438        r"""
12439
12440        Returns
12441        -------
12442        pyAgrum.CliqueGraph
12443          the current join tree used
12444
12445        """
12446        return _pyAgrum.ShaferShenoyInference_joinTree(self)
12447
12448    def junctionTree(self) -> "pyAgrum.JunctionTree":
12449        r"""
12450
12451        Returns
12452        -------
12453        pyAgrum.CliqueGraph
12454          the current junction tree
12455
12456        """
12457        val = _pyAgrum.ShaferShenoyInference_junctionTree(self)
12458
12459        val._engine=self
12460
12461
12462        return val
12463
12464
12465    def evidenceProbability(self) -> float:
12466        r"""
12467
12468        Returns
12469        -------
12470        float
12471          the probability of evidence
12472
12473        """
12474        return _pyAgrum.ShaferShenoyInference_evidenceProbability(self)
12475
12476    def setEvidence(self, evidces):
12477        """
12478        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
12479
12480        Parameters
12481        ----------
12482        evidces : dict
12483          a dict of evidences
12484
12485        Raises
12486        ------
12487        gum.InvalidArgument
12488            If one value is not a value for the node
12489        gum.InvalidArgument
12490            If the size of a value is different from the domain side of the node
12491        gum.FatalError
12492            If one value is a vector of 0s
12493        gum.UndefinedElement
12494            If one node does not belong to the Bayesian network
12495        """
12496        if not isinstance(evidces, dict):
12497            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
12498        self.eraseAllEvidence()
12499        for k,v in evidces.items():
12500            self.addEvidence(k,v)
12501
12502
12503
12504    def updateEvidence(self, evidces):
12505        """
12506        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
12507
12508        Parameters
12509        ----------
12510        evidces : dict
12511          a dict of evidences
12512
12513        Raises
12514        ------
12515        gum.InvalidArgument
12516            If one value is not a value for the node
12517        gum.InvalidArgument
12518            If the size of a value is different from the domain side of the node
12519        gum.FatalError
12520            If one value is a vector of 0s
12521        gum.UndefinedElement
12522            If one node does not belong to the Bayesian network
12523        """
12524        if not isinstance(evidces, dict):
12525            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
12526
12527        for k,v in evidces.items():
12528            if self.hasEvidence(k):
12529                self.chgEvidence(k,v)
12530            else:
12531                self.addEvidence(k,v)
12532
12533
12534
12535    def setTargets(self, targets):
12536        """
12537        Remove all the targets and add the ones in parameter.
12538
12539        Parameters
12540        ----------
12541        targets : set
12542          a set of targets
12543
12544        Raises
12545        ------
12546        gum.UndefinedElement
12547            If one target is not in the Bayes net
12548        """
12549        if not isinstance(targets, set):
12550            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
12551
12552        self.eraseAllTargets()
12553        for k in targets:
12554            self.addTarget(k)
12555
12556
12557
12558    def hardEvidenceNodes(self) -> object:
12559        r"""
12560
12561        Returns
12562        -------
12563        set
12564          the set of nodes with hard evidence
12565
12566        """
12567        return _pyAgrum.ShaferShenoyInference_hardEvidenceNodes(self)
12568
12569    def softEvidenceNodes(self) -> object:
12570        r"""
12571
12572        Returns
12573        -------
12574        set
12575          the set of nodes with soft evidence
12576
12577        """
12578        return _pyAgrum.ShaferShenoyInference_softEvidenceNodes(self)
12579
12580    def targets(self) -> object:
12581        r"""
12582
12583        Returns
12584        -------
12585        list
12586          the list of marginal targets
12587
12588        """
12589        return _pyAgrum.ShaferShenoyInference_targets(self)
12590
12591    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
12592        r"""
12593
12594        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
12595
12596        Parameters
12597        ----------
12598        target : set
12599          a set of targets ids or names.
12600        evs : set
12601          a set of nodes ids or names.
12602
12603        Warnings
12604        --------
12605        if some evs are d-separated, they are not included in the Potential.
12606
12607        Returns
12608        -------
12609        pyAgrum.Potential
12610          a Potential for P(targets|evs)
12611
12612        """
12613        return _pyAgrum.ShaferShenoyInference_evidenceImpact(self, target, evs)
12614
12615    def jointMutualInformation(self, targets: object) -> float:
12616        return _pyAgrum.ShaferShenoyInference_jointMutualInformation(self, targets)
12617
12618    def jointPosterior(self, targets: object) -> "pyAgrum.Potential":
12619        r"""
12620
12621        Compute the joint posterior of a set of nodes.
12622
12623        Parameters
12624        ----------
12625        list :
12626          the list of nodes whose posterior joint probability is wanted
12627
12628
12629        Warnings
12630        --------
12631        The order of the variables given by the list here or when the jointTarget is declared can not be assumed to be used bu the Potential.
12632
12633        Returns
12634        -------
12635        pyAgrum.Potential
12636          a const ref to the posterior joint probability of the set of nodes.
12637
12638        Raises
12639        ------
12640        pyAgrum.UndefinedElement
12641          If an element of nodes is not in targets
12642
12643        """
12644        return _pyAgrum.ShaferShenoyInference_jointPosterior(self, targets)
12645
12646    def addJointTarget(self, targets: object) -> None:
12647        r"""
12648
12649        Add a list of nodes as a new joint target. As a collateral effect, every node is added as a marginal target.
12650
12651        Parameters
12652        ----------
12653        list
12654          a list of names of nodes
12655
12656        Raises
12657        ------
12658        pyAgrum.UndefinedElement
12659          If some node(s) do not belong to the Bayesian network
12660
12661        """
12662        return _pyAgrum.ShaferShenoyInference_addJointTarget(self, targets)
12663
12664    def eraseJointTarget(self, targets: object) -> None:
12665        r"""
12666
12667        Remove, if existing, the joint target.
12668
12669        Parameters
12670        ----------
12671        list
12672          a list of names or Ids of nodes
12673
12674        Raises
12675        ------
12676        pyAgrum.IndexError
12677          If one of the node does not belong to the Bayesian network
12678        pyAgrum.UndefinedElement
12679          If node Id is not in the Bayesian network
12680
12681        """
12682        return _pyAgrum.ShaferShenoyInference_eraseJointTarget(self, targets)
12683
12684    def isJointTarget(self, targets: object) -> bool:
12685        r"""
12686
12687        Parameters
12688        ----------
12689        list
12690          a list of nodes ids or names.
12691
12692        Returns
12693        -------
12694        bool
12695          True if target is a joint target.
12696
12697        Raises
12698        ------
12699        pyAgrum.IndexError
12700          If the node does not belong to the Bayesian network
12701        pyAgrum.UndefinedElement
12702          If node Id is not in the Bayesian network
12703
12704        """
12705        return _pyAgrum.ShaferShenoyInference_isJointTarget(self, targets)
12706
12707    def jointTargets(self) -> object:
12708        r"""
12709
12710        Returns
12711        -------
12712        list
12713          the list of target sets
12714
12715        """
12716        return _pyAgrum.ShaferShenoyInference_jointTargets(self)
12717
12718    def makeInference(self) -> None:
12719        r"""
12720
12721        Perform the heavy computations needed to compute the targets' posteriors
12722
12723        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
12724        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
12725
12726        """
12727        return _pyAgrum.ShaferShenoyInference_makeInference(self)
12728
12729    def addEvidence(self, *args) -> None:
12730        r"""
12731
12732        Adds a new evidence on a node (might be soft or hard).
12733
12734        Parameters
12735        ----------
12736        id : int
12737          a node Id
12738        nodeName : int
12739          a node name
12740        val :
12741          (int) a node value
12742        val :
12743          (str) the label of the node value
12744        vals : list
12745          a list of values
12746
12747        Raises
12748        ------
12749        pyAgrum.InvalidArgument
12750          If the node already has an evidence
12751        pyAgrum.InvalidArgument
12752          If val is not a value for the node
12753        pyAgrum.InvalidArgument
12754          If the size of vals is different from the domain side of the node
12755        pyAgrum.FatalError
12756          If vals is a vector of 0s
12757        pyAgrum.UndefinedElement
12758          If the node does not belong to the Bayesian network
12759
12760        """
12761        return _pyAgrum.ShaferShenoyInference_addEvidence(self, *args)
12762
12763    def chgEvidence(self, *args) -> None:
12764        r"""
12765
12766        Change the value of an already existing evidence on a node (might be soft or hard).
12767
12768        Parameters
12769        ----------
12770        id : int
12771          a node Id
12772        nodeName : int
12773          a node name
12774        val :
12775          (int) a node value
12776        val :
12777          (str) the label of the node value
12778        vals : list
12779          a list of values
12780
12781        Raises
12782        ------
12783        pyAgrum.InvalidArgument
12784          If the node does not already have an evidence
12785        pyAgrum.InvalidArgument
12786          If val is not a value for the node
12787        pyAgrum.InvalidArgument
12788          If the size of vals is different from the domain side of the node
12789        pyAgrum.FatalError
12790          If vals is a vector of 0s
12791        pyAgrum.UndefinedElement
12792          If the node does not belong to the Bayesian network
12793
12794        """
12795        return _pyAgrum.ShaferShenoyInference_chgEvidence(self, *args)
12796
12797    def hasEvidence(self, *args) -> bool:
12798        r"""
12799
12800        Parameters
12801        ----------
12802        id : int
12803          a node Id
12804        nodeName : str
12805          a node name
12806
12807        Returns
12808        -------
12809        bool
12810          True if some node(s) (or the one in parameters) have received evidence
12811
12812        Raises
12813        ------
12814        pyAgrum.IndexError
12815          If the node does not belong to the Bayesian network
12816
12817        """
12818        return _pyAgrum.ShaferShenoyInference_hasEvidence(self, *args)
12819
12820    def eraseAllEvidence(self) -> None:
12821        r"""
12822
12823        Removes all the evidence entered into the network.
12824
12825        """
12826        return _pyAgrum.ShaferShenoyInference_eraseAllEvidence(self)
12827
12828    def eraseEvidence(self, *args) -> None:
12829        r"""
12830
12831        Remove the evidence, if any, corresponding to the node Id or name.
12832
12833        Parameters
12834        ----------
12835        id : int
12836          a node Id
12837        nodeName : int
12838          a node name
12839
12840        Raises
12841        ------
12842        pyAgrum.IndexError
12843          If the node does not belong to the Bayesian network
12844
12845        """
12846        return _pyAgrum.ShaferShenoyInference_eraseEvidence(self, *args)
12847
12848    def hasHardEvidence(self, nodeName: str) -> bool:
12849        r"""
12850
12851        Parameters
12852        ----------
12853        id : int
12854          a node Id
12855        nodeName : str
12856          a node name
12857
12858        Returns
12859        -------
12860        bool
12861          True if node has received a hard evidence
12862
12863        Raises
12864        ------
12865        pyAgrum.IndexError
12866          If the node does not belong to the Bayesian network
12867
12868        """
12869        return _pyAgrum.ShaferShenoyInference_hasHardEvidence(self, nodeName)
12870
12871    def hasSoftEvidence(self, *args) -> bool:
12872        r"""
12873
12874        Parameters
12875        ----------
12876        id : int
12877          a node Id
12878        nodeName : str
12879          a node name
12880
12881        Returns
12882        -------
12883        bool
12884          True if node has received a soft evidence
12885
12886        Raises
12887        ------
12888        pyAgrum.IndexError
12889          If the node does not belong to the Bayesian network
12890
12891        """
12892        return _pyAgrum.ShaferShenoyInference_hasSoftEvidence(self, *args)
12893
12894    def nbrEvidence(self) -> int:
12895        r"""
12896
12897        Returns
12898        -------
12899        int
12900          the number of evidence entered into the Bayesian network
12901
12902        """
12903        return _pyAgrum.ShaferShenoyInference_nbrEvidence(self)
12904
12905    def nbrHardEvidence(self) -> int:
12906        r"""
12907
12908        Returns
12909        -------
12910        int
12911          the number of hard evidence entered into the Bayesian network
12912
12913        """
12914        return _pyAgrum.ShaferShenoyInference_nbrHardEvidence(self)
12915
12916    def nbrSoftEvidence(self) -> int:
12917        r"""
12918
12919        Returns
12920        -------
12921        int
12922          the number of soft evidence entered into the Bayesian network
12923
12924        """
12925        return _pyAgrum.ShaferShenoyInference_nbrSoftEvidence(self)
12926
12927    def eraseAllTargets(self) -> None:
12928        r"""
12929
12930        Clear all previously defined targets (marginal and joint targets).
12931
12932        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
12933
12934        """
12935        return _pyAgrum.ShaferShenoyInference_eraseAllTargets(self)
12936
12937    def addAllTargets(self) -> None:
12938        r"""
12939
12940        Add all the nodes as targets.
12941
12942        """
12943        return _pyAgrum.ShaferShenoyInference_addAllTargets(self)
12944
12945    def addTarget(self, *args) -> None:
12946        r"""
12947
12948        Add a marginal target to the list of targets.
12949
12950        Parameters
12951        ----------
12952        target : int
12953          a node Id
12954        nodeName : str
12955          a node name
12956
12957        Raises
12958        ------
12959        pyAgrum.UndefinedElement
12960          If target is not a NodeId in the Bayes net
12961
12962        """
12963        return _pyAgrum.ShaferShenoyInference_addTarget(self, *args)
12964
12965    def eraseTarget(self, *args) -> None:
12966        r"""
12967
12968        Remove, if existing, the marginal target.
12969
12970        Parameters
12971        ----------
12972        target : int
12973          a node Id
12974        nodeName : int
12975          a node name
12976
12977        Raises
12978        ------
12979        pyAgrum.IndexError
12980          If one of the node does not belong to the Bayesian network
12981        pyAgrum.UndefinedElement
12982          If node Id is not in the Bayesian network
12983
12984        """
12985        return _pyAgrum.ShaferShenoyInference_eraseTarget(self, *args)
12986
12987    def isTarget(self, *args) -> bool:
12988        r"""
12989
12990        Parameters
12991        ----------
12992        variable : int
12993         a node Id
12994        nodeName : str
12995          a node name
12996
12997        Returns
12998        -------
12999        bool
13000          True if variable is a (marginal) target
13001
13002        Raises
13003        ------
13004        pyAgrum.IndexError
13005          If the node does not belong to the Bayesian network
13006        pyAgrum.UndefinedElement
13007          If node Id is not in the Bayesian network
13008
13009        """
13010        return _pyAgrum.ShaferShenoyInference_isTarget(self, *args)
13011
13012    def nbrTargets(self) -> int:
13013        r"""
13014
13015        Returns
13016        -------
13017        int
13018          the number of marginal targets
13019
13020        """
13021        return _pyAgrum.ShaferShenoyInference_nbrTargets(self)
13022
13023    def H(self, *args) -> float:
13024        r"""
13025
13026        Parameters
13027        ----------
13028        X : int
13029          a node Id
13030        nodeName : str
13031          a node name
13032
13033        Returns
13034        -------
13035        float
13036          the computed Shanon's entropy of a node given the observation
13037
13038        """
13039        return _pyAgrum.ShaferShenoyInference_H(self, *args)
13040
13041    def BN(self) -> "pyAgrum.IBayesNet":
13042        r"""
13043
13044        Returns
13045        -------
13046        pyAgrum.IBayesNet
13047          A constant reference over the IBayesNet referenced by this class.
13048
13049        Raises
13050        ------
13051        pyAgrum.UndefinedElement
13052          If no Bayes net has been assigned to the inference.
13053
13054        """
13055        return _pyAgrum.ShaferShenoyInference_BN(self)
13056
13057    def posterior(self, *args) -> "pyAgrum.Potential":
13058        r"""
13059
13060        Computes and returns the posterior of a node.
13061
13062        Parameters
13063        ----------
13064        var : int
13065          the node Id of the node for which we need a posterior probability
13066        nodeName : str
13067          the node name of the node for which we need a posterior probability
13068
13069        Returns
13070        -------
13071        pyAgrum.Potential
13072          a const ref to the posterior probability of the node
13073
13074        Raises
13075        ------
13076        pyAgrum.UndefinedElement
13077          If an element of nodes is not in targets
13078
13079        """
13080        return _pyAgrum.ShaferShenoyInference_posterior(self, *args)
13081
13082    def eraseAllJointTargets(self) -> None:
13083        r"""
13084
13085        Clear all previously defined joint targets.
13086
13087        """
13088        return _pyAgrum.ShaferShenoyInference_eraseAllJointTargets(self)
13089
13090    def eraseAllMarginalTargets(self) -> None:
13091        r"""
13092
13093        Clear all the previously defined marginal targets.
13094
13095        """
13096        return _pyAgrum.ShaferShenoyInference_eraseAllMarginalTargets(self)
13097
13098    def nbrJointTargets(self) -> int:
13099        r"""
13100
13101        Returns
13102        -------
13103        int
13104          the number of joint targets
13105
13106        """
13107        return _pyAgrum.ShaferShenoyInference_nbrJointTargets(self)
13108
13109    def I(self, *args) -> float:
13110        r"""
13111
13112        Parameters
13113        ----------
13114        X : int or str
13115           a node Id or a node name
13116        Y : int or str
13117           another node Id or node name
13118
13119           Returns
13120        -------
13121        float
13122           the Mutual Information of X and Y given the observation
13123
13124        """
13125        return _pyAgrum.ShaferShenoyInference_I(self, *args)
13126
13127    def VI(self, *args) -> float:
13128        r"""
13129
13130        Parameters
13131        ----------
13132        X : int or str
13133           a node Id or a node name
13134        Y : int or str
13135           another node Id or node name
13136
13137           Returns
13138        -------
13139        float
13140           variation of information between X and Y
13141
13142        """
13143        return _pyAgrum.ShaferShenoyInference_VI(self, *args)
13144
13145    def evidenceJointImpact(self, *args) -> "pyAgrum.Potential":
13146        r"""
13147
13148        Create a pyAgrum.Potential for P(joint targets|evs) (for all instanciation of targets and evs)
13149
13150        Parameters
13151        ----------
13152        targets :
13153          (int) a node Id
13154        targets :
13155          (str) a node name
13156        evs : set
13157          a set of nodes ids or names.
13158
13159        Returns
13160        -------
13161        pyAgrum.Potential
13162          a Potential for P(target|evs)
13163
13164        Raises
13165        ------
13166        pyAgrum.Exception
13167          If some evidene entered into the Bayes net are incompatible (their joint proba = 0)
13168
13169        """
13170        return _pyAgrum.ShaferShenoyInference_evidenceJointImpact(self, *args)
13171
13172# Register ShaferShenoyInference in _pyAgrum:
13173_pyAgrum.ShaferShenoyInference_swigregister(ShaferShenoyInference)
13174
13175class VariableElimination(object):
13176    r"""
13177
13178    Class used for Variable Elimination inference algorithm.
13179
13180    VariableElimination(bn) -> VariableElimination
13181        Parameters:
13182            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
13183
13184    """
13185
13186    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
13187    __repr__ = _swig_repr
13188
13189    def __init__(self, *args):
13190        _pyAgrum.VariableElimination_swiginit(self, _pyAgrum.new_VariableElimination(*args))
13191
13192        self._model=args[0]
13193
13194
13195
13196    __swig_destroy__ = _pyAgrum.delete_VariableElimination
13197
13198    def setTriangulation(self, new_triangulation: "pyAgrum.Triangulation") -> None:
13199        return _pyAgrum.VariableElimination_setTriangulation(self, new_triangulation)
13200
13201    def setRelevantPotentialsFinderType(self, type: int) -> None:
13202        r"""
13203
13204        sets how we determine the relevant potentials to combine
13205
13206        When a clique sends a message to a separator, it first constitute the set of the potentials it contains and of the potentials contained in the messages it received. If RelevantPotentialsFinderType = FIND_ALL, all these potentials are combined and projected to produce the message sent to the separator. If RelevantPotentialsFinderType = DSEP_BAYESBALL_NODES, then only the set of potentials d-connected to the variables of the separator are kept for combination and projection.
13207
13208        0 = FIND_ALL
13209        1 = DSEP_BAYESBALL_NODES
13210        2 = DSEP_BAYESBALL_POTENTIALS
13211        3 = DSEP_KOLLER_FRIEDMAN_2009
13212
13213        Parameters
13214        ----------
13215        type : int
13216          the finder type
13217
13218        Raises
13219        ------
13220        pyAgrum.InvalidArgument
13221          If type is not implemented
13222
13223        """
13224        return _pyAgrum.VariableElimination_setRelevantPotentialsFinderType(self, type)
13225
13226    def setFindBarrenNodesType(self, type: int) -> None:
13227        r"""
13228
13229        sets how we determine barren nodes
13230
13231        Barren nodes are unnecessary for probability inference, so they can be safely discarded in this case (type = FIND_BARREN_NODES). This speeds-up inference. However, there are some cases in which we do not want to remove barren nodes, typically when we want to answer queries such as Most Probable Explanations (MPE).
13232
13233        0 = FIND_NO_BARREN_NODES
13234        1 = FIND_BARREN_NODES
13235
13236        Parameters
13237        ----------
13238        type : int
13239          the finder type
13240
13241        Raises
13242        ------
13243        pyAgrum.InvalidArgument
13244          If type is not implemented
13245
13246        """
13247        return _pyAgrum.VariableElimination_setFindBarrenNodesType(self, type)
13248
13249    def junctionTree(self, id: int) -> "pyAgrum.JunctionTree":
13250        r"""
13251
13252        Returns
13253        -------
13254        pyAgrum.CliqueGraph
13255          the current junction tree
13256
13257        """
13258        val = _pyAgrum.VariableElimination_junctionTree(self, id)
13259
13260        val._engine=self
13261
13262
13263        return val
13264
13265
13266    def setEvidence(self, evidces):
13267        """
13268        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
13269
13270        Parameters
13271        ----------
13272        evidces : dict
13273          a dict of evidences
13274
13275        Raises
13276        ------
13277        gum.InvalidArgument
13278            If one value is not a value for the node
13279        gum.InvalidArgument
13280            If the size of a value is different from the domain side of the node
13281        gum.FatalError
13282            If one value is a vector of 0s
13283        gum.UndefinedElement
13284            If one node does not belong to the Bayesian network
13285        """
13286        if not isinstance(evidces, dict):
13287            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
13288        self.eraseAllEvidence()
13289        for k,v in evidces.items():
13290            self.addEvidence(k,v)
13291
13292
13293
13294    def updateEvidence(self, evidces):
13295        """
13296        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
13297
13298        Parameters
13299        ----------
13300        evidces : dict
13301          a dict of evidences
13302
13303        Raises
13304        ------
13305        gum.InvalidArgument
13306            If one value is not a value for the node
13307        gum.InvalidArgument
13308            If the size of a value is different from the domain side of the node
13309        gum.FatalError
13310            If one value is a vector of 0s
13311        gum.UndefinedElement
13312            If one node does not belong to the Bayesian network
13313        """
13314        if not isinstance(evidces, dict):
13315            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
13316
13317        for k,v in evidces.items():
13318            if self.hasEvidence(k):
13319                self.chgEvidence(k,v)
13320            else:
13321                self.addEvidence(k,v)
13322
13323
13324
13325    def setTargets(self, targets):
13326        """
13327        Remove all the targets and add the ones in parameter.
13328
13329        Parameters
13330        ----------
13331        targets : set
13332          a set of targets
13333
13334        Raises
13335        ------
13336        gum.UndefinedElement
13337            If one target is not in the Bayes net
13338        """
13339        if not isinstance(targets, set):
13340            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
13341
13342        self.eraseAllTargets()
13343        for k in targets:
13344            self.addTarget(k)
13345
13346
13347
13348    def hardEvidenceNodes(self) -> object:
13349        r"""
13350
13351        Returns
13352        -------
13353        set
13354          the set of nodes with hard evidence
13355
13356        """
13357        return _pyAgrum.VariableElimination_hardEvidenceNodes(self)
13358
13359    def softEvidenceNodes(self) -> object:
13360        r"""
13361
13362        Returns
13363        -------
13364        set
13365          the set of nodes with soft evidence
13366
13367        """
13368        return _pyAgrum.VariableElimination_softEvidenceNodes(self)
13369
13370    def targets(self) -> object:
13371        r"""
13372
13373        Returns
13374        -------
13375        list
13376          the list of marginal targets
13377
13378        """
13379        return _pyAgrum.VariableElimination_targets(self)
13380
13381    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
13382        r"""
13383
13384        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
13385
13386        Parameters
13387        ----------
13388        target : set
13389          a set of targets ids or names.
13390        evs : set
13391          a set of nodes ids or names.
13392
13393        Warnings
13394        --------
13395        if some evs are d-separated, they are not included in the Potential.
13396
13397        Returns
13398        -------
13399        pyAgrum.Potential
13400          a Potential for P(targets|evs)
13401
13402        """
13403        return _pyAgrum.VariableElimination_evidenceImpact(self, target, evs)
13404
13405    def jointMutualInformation(self, targets: object) -> float:
13406        return _pyAgrum.VariableElimination_jointMutualInformation(self, targets)
13407
13408    def evidenceJointImpact(self, targets: object, evs: object) -> "pyAgrum.Potential":
13409        r"""
13410
13411        Create a pyAgrum.Potential for P(joint targets|evs) (for all instanciation of targets and evs)
13412
13413        Parameters
13414        ----------
13415        targets :
13416          (int) a node Id
13417        targets :
13418          (str) a node name
13419        evs : set
13420          a set of nodes ids or names.
13421
13422        Returns
13423        -------
13424        pyAgrum.Potential
13425          a Potential for P(target|evs)
13426
13427        Raises
13428        ------
13429        pyAgrum.Exception
13430          If some evidene entered into the Bayes net are incompatible (their joint proba = 0)
13431
13432        """
13433        return _pyAgrum.VariableElimination_evidenceJointImpact(self, targets, evs)
13434
13435    def jointPosterior(self, targets: object) -> "pyAgrum.Potential":
13436        r"""
13437
13438        Compute the joint posterior of a set of nodes.
13439
13440        Parameters
13441        ----------
13442        list :
13443          the list of nodes whose posterior joint probability is wanted
13444
13445
13446        Warnings
13447        --------
13448        The order of the variables given by the list here or when the jointTarget is declared can not be assumed to be used bu the Potential.
13449
13450        Returns
13451        -------
13452        pyAgrum.Potential
13453          a const ref to the posterior joint probability of the set of nodes.
13454
13455        Raises
13456        ------
13457        pyAgrum.UndefinedElement
13458          If an element of nodes is not in targets
13459
13460        """
13461        return _pyAgrum.VariableElimination_jointPosterior(self, targets)
13462
13463    def addJointTarget(self, targets: object) -> None:
13464        r"""
13465
13466        Add a list of nodes as a new joint target. As a collateral effect, every node is added as a marginal target.
13467
13468        Parameters
13469        ----------
13470        list
13471          a list of names of nodes
13472
13473        Raises
13474        ------
13475        pyAgrum.UndefinedElement
13476          If some node(s) do not belong to the Bayesian network
13477
13478        """
13479        return _pyAgrum.VariableElimination_addJointTarget(self, targets)
13480
13481    def eraseJointTarget(self, targets: object) -> None:
13482        r"""
13483
13484        Remove, if existing, the joint target.
13485
13486        Parameters
13487        ----------
13488        list
13489          a list of names or Ids of nodes
13490
13491        Raises
13492        ------
13493        pyAgrum.IndexError
13494          If one of the node does not belong to the Bayesian network
13495        pyAgrum.UndefinedElement
13496          If node Id is not in the Bayesian network
13497
13498        """
13499        return _pyAgrum.VariableElimination_eraseJointTarget(self, targets)
13500
13501    def isJointTarget(self, targets: object) -> bool:
13502        r"""
13503
13504        Parameters
13505        ----------
13506        list
13507          a list of nodes ids or names.
13508
13509        Returns
13510        -------
13511        bool
13512          True if target is a joint target.
13513
13514        Raises
13515        ------
13516        pyAgrum.IndexError
13517          If the node does not belong to the Bayesian network
13518        pyAgrum.UndefinedElement
13519          If node Id is not in the Bayesian network
13520
13521        """
13522        return _pyAgrum.VariableElimination_isJointTarget(self, targets)
13523
13524    def jointTargets(self) -> object:
13525        r"""
13526
13527        Returns
13528        -------
13529        list
13530          the list of target sets
13531
13532        """
13533        return _pyAgrum.VariableElimination_jointTargets(self)
13534
13535    def makeInference(self) -> None:
13536        r"""
13537
13538        Perform the heavy computations needed to compute the targets' posteriors
13539
13540        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
13541        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
13542
13543        """
13544        return _pyAgrum.VariableElimination_makeInference(self)
13545
13546    def posterior(self, *args) -> "pyAgrum.Potential":
13547        r"""
13548
13549        Computes and returns the posterior of a node.
13550
13551        Parameters
13552        ----------
13553        var : int
13554          the node Id of the node for which we need a posterior probability
13555        nodeName : str
13556          the node name of the node for which we need a posterior probability
13557
13558        Returns
13559        -------
13560        pyAgrum.Potential
13561          a const ref to the posterior probability of the node
13562
13563        Raises
13564        ------
13565        pyAgrum.UndefinedElement
13566          If an element of nodes is not in targets
13567
13568        """
13569        return _pyAgrum.VariableElimination_posterior(self, *args)
13570
13571    def addEvidence(self, *args) -> None:
13572        r"""
13573
13574        Adds a new evidence on a node (might be soft or hard).
13575
13576        Parameters
13577        ----------
13578        id : int
13579          a node Id
13580        nodeName : int
13581          a node name
13582        val :
13583          (int) a node value
13584        val :
13585          (str) the label of the node value
13586        vals : list
13587          a list of values
13588
13589        Raises
13590        ------
13591        pyAgrum.InvalidArgument
13592          If the node already has an evidence
13593        pyAgrum.InvalidArgument
13594          If val is not a value for the node
13595        pyAgrum.InvalidArgument
13596          If the size of vals is different from the domain side of the node
13597        pyAgrum.FatalError
13598          If vals is a vector of 0s
13599        pyAgrum.UndefinedElement
13600          If the node does not belong to the Bayesian network
13601
13602        """
13603        return _pyAgrum.VariableElimination_addEvidence(self, *args)
13604
13605    def chgEvidence(self, *args) -> None:
13606        r"""
13607
13608        Change the value of an already existing evidence on a node (might be soft or hard).
13609
13610        Parameters
13611        ----------
13612        id : int
13613          a node Id
13614        nodeName : int
13615          a node name
13616        val :
13617          (int) a node value
13618        val :
13619          (str) the label of the node value
13620        vals : list
13621          a list of values
13622
13623        Raises
13624        ------
13625        pyAgrum.InvalidArgument
13626          If the node does not already have an evidence
13627        pyAgrum.InvalidArgument
13628          If val is not a value for the node
13629        pyAgrum.InvalidArgument
13630          If the size of vals is different from the domain side of the node
13631        pyAgrum.FatalError
13632          If vals is a vector of 0s
13633        pyAgrum.UndefinedElement
13634          If the node does not belong to the Bayesian network
13635
13636        """
13637        return _pyAgrum.VariableElimination_chgEvidence(self, *args)
13638
13639    def hasEvidence(self, *args) -> bool:
13640        r"""
13641
13642        Parameters
13643        ----------
13644        id : int
13645          a node Id
13646        nodeName : str
13647          a node name
13648
13649        Returns
13650        -------
13651        bool
13652          True if some node(s) (or the one in parameters) have received evidence
13653
13654        Raises
13655        ------
13656        pyAgrum.IndexError
13657          If the node does not belong to the Bayesian network
13658
13659        """
13660        return _pyAgrum.VariableElimination_hasEvidence(self, *args)
13661
13662    def eraseAllEvidence(self) -> None:
13663        r"""
13664
13665        Removes all the evidence entered into the network.
13666
13667        """
13668        return _pyAgrum.VariableElimination_eraseAllEvidence(self)
13669
13670    def eraseEvidence(self, *args) -> None:
13671        r"""
13672
13673        Remove the evidence, if any, corresponding to the node Id or name.
13674
13675        Parameters
13676        ----------
13677        id : int
13678          a node Id
13679        nodeName : int
13680          a node name
13681
13682        Raises
13683        ------
13684        pyAgrum.IndexError
13685          If the node does not belong to the Bayesian network
13686
13687        """
13688        return _pyAgrum.VariableElimination_eraseEvidence(self, *args)
13689
13690    def hasHardEvidence(self, nodeName: str) -> bool:
13691        r"""
13692
13693        Parameters
13694        ----------
13695        id : int
13696          a node Id
13697        nodeName : str
13698          a node name
13699
13700        Returns
13701        -------
13702        bool
13703          True if node has received a hard evidence
13704
13705        Raises
13706        ------
13707        pyAgrum.IndexError
13708          If the node does not belong to the Bayesian network
13709
13710        """
13711        return _pyAgrum.VariableElimination_hasHardEvidence(self, nodeName)
13712
13713    def hasSoftEvidence(self, *args) -> bool:
13714        r"""
13715
13716        Parameters
13717        ----------
13718        id : int
13719          a node Id
13720        nodeName : str
13721          a node name
13722
13723        Returns
13724        -------
13725        bool
13726          True if node has received a soft evidence
13727
13728        Raises
13729        ------
13730        pyAgrum.IndexError
13731          If the node does not belong to the Bayesian network
13732
13733        """
13734        return _pyAgrum.VariableElimination_hasSoftEvidence(self, *args)
13735
13736    def nbrEvidence(self) -> int:
13737        r"""
13738
13739        Returns
13740        -------
13741        int
13742          the number of evidence entered into the Bayesian network
13743
13744        """
13745        return _pyAgrum.VariableElimination_nbrEvidence(self)
13746
13747    def nbrHardEvidence(self) -> int:
13748        r"""
13749
13750        Returns
13751        -------
13752        int
13753          the number of hard evidence entered into the Bayesian network
13754
13755        """
13756        return _pyAgrum.VariableElimination_nbrHardEvidence(self)
13757
13758    def nbrSoftEvidence(self) -> int:
13759        r"""
13760
13761        Returns
13762        -------
13763        int
13764          the number of soft evidence entered into the Bayesian network
13765
13766        """
13767        return _pyAgrum.VariableElimination_nbrSoftEvidence(self)
13768
13769    def eraseAllTargets(self) -> None:
13770        r"""
13771
13772        Clear all previously defined targets (marginal and joint targets).
13773
13774        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
13775
13776        """
13777        return _pyAgrum.VariableElimination_eraseAllTargets(self)
13778
13779    def addAllTargets(self) -> None:
13780        r"""
13781
13782        Add all the nodes as targets.
13783
13784        """
13785        return _pyAgrum.VariableElimination_addAllTargets(self)
13786
13787    def addTarget(self, *args) -> None:
13788        r"""
13789
13790        Add a marginal target to the list of targets.
13791
13792        Parameters
13793        ----------
13794        target : int
13795          a node Id
13796        nodeName : str
13797          a node name
13798
13799        Raises
13800        ------
13801        pyAgrum.UndefinedElement
13802          If target is not a NodeId in the Bayes net
13803
13804        """
13805        return _pyAgrum.VariableElimination_addTarget(self, *args)
13806
13807    def eraseTarget(self, *args) -> None:
13808        r"""
13809
13810        Remove, if existing, the marginal target.
13811
13812        Parameters
13813        ----------
13814        target : int
13815          a node Id
13816        nodeName : int
13817          a node name
13818
13819        Raises
13820        ------
13821        pyAgrum.IndexError
13822          If one of the node does not belong to the Bayesian network
13823        pyAgrum.UndefinedElement
13824          If node Id is not in the Bayesian network
13825
13826        """
13827        return _pyAgrum.VariableElimination_eraseTarget(self, *args)
13828
13829    def isTarget(self, *args) -> bool:
13830        r"""
13831
13832        Parameters
13833        ----------
13834        variable : int
13835         a node Id
13836        nodeName : str
13837          a node name
13838
13839        Returns
13840        -------
13841        bool
13842          True if variable is a (marginal) target
13843
13844        Raises
13845        ------
13846        pyAgrum.IndexError
13847          If the node does not belong to the Bayesian network
13848        pyAgrum.UndefinedElement
13849          If node Id is not in the Bayesian network
13850
13851        """
13852        return _pyAgrum.VariableElimination_isTarget(self, *args)
13853
13854    def nbrTargets(self) -> int:
13855        r"""
13856
13857        Returns
13858        -------
13859        int
13860          the number of marginal targets
13861
13862        """
13863        return _pyAgrum.VariableElimination_nbrTargets(self)
13864
13865    def H(self, *args) -> float:
13866        r"""
13867
13868        Parameters
13869        ----------
13870        X : int
13871          a node Id
13872        nodeName : str
13873          a node name
13874
13875        Returns
13876        -------
13877        float
13878          the computed Shanon's entropy of a node given the observation
13879
13880        """
13881        return _pyAgrum.VariableElimination_H(self, *args)
13882
13883    def BN(self) -> "pyAgrum.IBayesNet":
13884        r"""
13885
13886        Returns
13887        -------
13888        pyAgrum.IBayesNet
13889          A constant reference over the IBayesNet referenced by this class.
13890
13891        Raises
13892        ------
13893        pyAgrum.UndefinedElement
13894          If no Bayes net has been assigned to the inference.
13895
13896        """
13897        return _pyAgrum.VariableElimination_BN(self)
13898
13899# Register VariableElimination in _pyAgrum:
13900_pyAgrum.VariableElimination_swigregister(VariableElimination)
13901
13902class GibbsSampling(object):
13903    r"""
13904
13905    Class for making Gibbs sampling inference in Bayesian networks.
13906
13907    GibbsSampling(bn) -> GibbsSampling
13908        Parameters:
13909          * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
13910
13911    """
13912
13913    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
13914    __repr__ = _swig_repr
13915
13916    def __init__(self, bn: "IBayesNet"):
13917        _pyAgrum.GibbsSampling_swiginit(self, _pyAgrum.new_GibbsSampling(bn))
13918
13919        self._model=bn#BN
13920
13921
13922
13923    __swig_destroy__ = _pyAgrum.delete_GibbsSampling
13924
13925    def setBurnIn(self, b: int) -> None:
13926        r"""
13927
13928        Parameters
13929        ----------
13930        b : int
13931          size of burn in on number of iteration
13932
13933        """
13934        return _pyAgrum.GibbsSampling_setBurnIn(self, b)
13935
13936    def burnIn(self) -> int:
13937        r"""
13938
13939        Returns
13940        -------
13941        int
13942          size of burn in on number of iteration
13943
13944        """
13945        return _pyAgrum.GibbsSampling_burnIn(self)
13946
13947    def setEvidence(self, evidces):
13948        """
13949        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
13950
13951        Parameters
13952        ----------
13953        evidces : dict
13954          a dict of evidences
13955
13956        Raises
13957        ------
13958        gum.InvalidArgument
13959            If one value is not a value for the node
13960        gum.InvalidArgument
13961            If the size of a value is different from the domain side of the node
13962        gum.FatalError
13963            If one value is a vector of 0s
13964        gum.UndefinedElement
13965            If one node does not belong to the Bayesian network
13966        """
13967        if not isinstance(evidces, dict):
13968            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
13969        self.eraseAllEvidence()
13970        for k,v in evidces.items():
13971            self.addEvidence(k,v)
13972
13973
13974
13975    def updateEvidence(self, evidces):
13976        """
13977        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
13978
13979        Parameters
13980        ----------
13981        evidces : dict
13982          a dict of evidences
13983
13984        Raises
13985        ------
13986        gum.InvalidArgument
13987            If one value is not a value for the node
13988        gum.InvalidArgument
13989            If the size of a value is different from the domain side of the node
13990        gum.FatalError
13991            If one value is a vector of 0s
13992        gum.UndefinedElement
13993            If one node does not belong to the Bayesian network
13994        """
13995        if not isinstance(evidces, dict):
13996            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
13997
13998        for k,v in evidces.items():
13999            if self.hasEvidence(k):
14000                self.chgEvidence(k,v)
14001            else:
14002                self.addEvidence(k,v)
14003
14004
14005
14006    def setTargets(self, targets):
14007        """
14008        Remove all the targets and add the ones in parameter.
14009
14010        Parameters
14011        ----------
14012        targets : set
14013          a set of targets
14014
14015        Raises
14016        ------
14017        gum.UndefinedElement
14018            If one target is not in the Bayes net
14019        """
14020        if not isinstance(targets, set):
14021            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
14022
14023        self.eraseAllTargets()
14024        for k in targets:
14025            self.addTarget(k)
14026
14027
14028
14029    def hardEvidenceNodes(self) -> object:
14030        r"""
14031
14032        Returns
14033        -------
14034        set
14035          the set of nodes with hard evidence
14036
14037        """
14038        return _pyAgrum.GibbsSampling_hardEvidenceNodes(self)
14039
14040    def softEvidenceNodes(self) -> object:
14041        r"""
14042
14043        Returns
14044        -------
14045        set
14046          the set of nodes with soft evidence
14047
14048        """
14049        return _pyAgrum.GibbsSampling_softEvidenceNodes(self)
14050
14051    def targets(self) -> object:
14052        r"""
14053
14054        Returns
14055        -------
14056        list
14057          the list of marginal targets
14058
14059        """
14060        return _pyAgrum.GibbsSampling_targets(self)
14061
14062    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
14063        r"""
14064
14065        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
14066
14067        Parameters
14068        ----------
14069        target : set
14070          a set of targets ids or names.
14071        evs : set
14072          a set of nodes ids or names.
14073
14074        Warnings
14075        --------
14076        if some evs are d-separated, they are not included in the Potential.
14077
14078        Returns
14079        -------
14080        pyAgrum.Potential
14081          a Potential for P(targets|evs)
14082
14083        """
14084        return _pyAgrum.GibbsSampling_evidenceImpact(self, target, evs)
14085
14086    def setVerbosity(self, v: bool) -> None:
14087        r"""
14088
14089        Parameters
14090        ----------
14091        v : bool
14092                verbosity
14093
14094        """
14095        return _pyAgrum.GibbsSampling_setVerbosity(self, v)
14096
14097    def setEpsilon(self, eps: float) -> None:
14098        r"""
14099
14100        Parameters
14101        ----------
14102        eps : float
14103        	the epsilon we want to use
14104
14105        Raises
14106        ------
14107        pyAgrum.OutOfBounds
14108        	If eps<0
14109
14110        """
14111        return _pyAgrum.GibbsSampling_setEpsilon(self, eps)
14112
14113    def setMinEpsilonRate(self, rate: float) -> None:
14114        r"""
14115
14116        Parameters
14117        ----------
14118        rate : float
14119        	the minimal epsilon rate
14120
14121        """
14122        return _pyAgrum.GibbsSampling_setMinEpsilonRate(self, rate)
14123
14124    def setMaxIter(self, max: int) -> None:
14125        r"""
14126
14127        Parameters
14128        ----------
14129        max : int
14130        	the maximum number of iteration
14131
14132        Raises
14133        ------
14134        pyAgrum.OutOfBounds
14135        	If max <= 1
14136
14137        """
14138        return _pyAgrum.GibbsSampling_setMaxIter(self, max)
14139
14140    def setMaxTime(self, timeout: float) -> None:
14141        r"""
14142
14143        Parameters
14144        ----------
14145        tiemout : float
14146        	stopping criterion on timeout (in seconds)
14147
14148        Raises
14149        ------
14150        pyAgrum.OutOfBounds
14151        	If timeout<=0.0
14152
14153        """
14154        return _pyAgrum.GibbsSampling_setMaxTime(self, timeout)
14155
14156    def setPeriodSize(self, p: int) -> None:
14157        r"""
14158
14159        Parameters
14160        ----------
14161        p : int
14162        	number of samples between 2 stopping
14163
14164        Raises
14165        ------
14166        pyAgrum.OutOfBounds
14167        	If p<1
14168
14169        """
14170        return _pyAgrum.GibbsSampling_setPeriodSize(self, p)
14171
14172    def verbosity(self) -> bool:
14173        r"""
14174
14175        Returns
14176        -------
14177        bool
14178        	True if the verbosity is enabled
14179
14180        """
14181        return _pyAgrum.GibbsSampling_verbosity(self)
14182
14183    def epsilon(self) -> float:
14184        r"""
14185
14186        Returns
14187        -------
14188        float
14189        	the value of epsilon
14190
14191        """
14192        return _pyAgrum.GibbsSampling_epsilon(self)
14193
14194    def minEpsilonRate(self) -> float:
14195        r"""
14196
14197        Returns
14198        -------
14199        float
14200        	the value of the minimal epsilon rate
14201
14202        """
14203        return _pyAgrum.GibbsSampling_minEpsilonRate(self)
14204
14205    def maxIter(self) -> int:
14206        r"""
14207
14208        Returns
14209        -------
14210        int
14211        	the criterion on number of iterations
14212
14213        """
14214        return _pyAgrum.GibbsSampling_maxIter(self)
14215
14216    def maxTime(self) -> float:
14217        r"""
14218
14219        Returns
14220        -------
14221        float
14222        	the timeout(in seconds)
14223
14224        """
14225        return _pyAgrum.GibbsSampling_maxTime(self)
14226
14227    def periodSize(self) -> int:
14228        r"""
14229
14230        Returns
14231        -------
14232        int
14233        	the number of samples between 2 stopping
14234
14235        Raises
14236        ------
14237        pyAgrum.OutOfBounds
14238        	If p<1
14239
14240        """
14241        return _pyAgrum.GibbsSampling_periodSize(self)
14242
14243    def nbrIterations(self) -> int:
14244        r"""
14245
14246        Returns
14247        -------
14248        int
14249        	the number of iterations
14250
14251        """
14252        return _pyAgrum.GibbsSampling_nbrIterations(self)
14253
14254    def currentTime(self) -> float:
14255        r"""
14256
14257        Returns
14258        -------
14259        float
14260        	get the current running time in second (float)
14261
14262        """
14263        return _pyAgrum.GibbsSampling_currentTime(self)
14264
14265    def messageApproximationScheme(self) -> str:
14266        r"""
14267
14268        Returns
14269        -------
14270        str
14271        	the approximation scheme message
14272
14273        """
14274        return _pyAgrum.GibbsSampling_messageApproximationScheme(self)
14275
14276    def history(self) -> List[float]:
14277        r"""
14278
14279        Returns
14280        -------
14281        tuple
14282        	the scheme history
14283
14284        Raises
14285        ------
14286        pyAgrum.OperationNotAllowed
14287        	If the scheme did not performed or if verbosity is set to false
14288
14289        """
14290        return _pyAgrum.GibbsSampling_history(self)
14291
14292    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
14293        return _pyAgrum.GibbsSampling__asIApproximationSchemeConfiguration(self)
14294
14295    def makeInference(self) -> None:
14296        r"""
14297
14298        Perform the heavy computations needed to compute the targets' posteriors
14299
14300        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
14301        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
14302
14303        """
14304        return _pyAgrum.GibbsSampling_makeInference(self)
14305
14306    def posterior(self, *args) -> "pyAgrum.Potential":
14307        r"""
14308
14309        Computes and returns the posterior of a node.
14310
14311        Parameters
14312        ----------
14313        var : int
14314          the node Id of the node for which we need a posterior probability
14315        nodeName : str
14316          the node name of the node for which we need a posterior probability
14317
14318        Returns
14319        -------
14320        pyAgrum.Potential
14321          a const ref to the posterior probability of the node
14322
14323        Raises
14324        ------
14325        pyAgrum.UndefinedElement
14326          If an element of nodes is not in targets
14327
14328        """
14329        return _pyAgrum.GibbsSampling_posterior(self, *args)
14330
14331    def addEvidence(self, *args) -> None:
14332        r"""
14333
14334        Adds a new evidence on a node (might be soft or hard).
14335
14336        Parameters
14337        ----------
14338        id : int
14339          a node Id
14340        nodeName : int
14341          a node name
14342        val :
14343          (int) a node value
14344        val :
14345          (str) the label of the node value
14346        vals : list
14347          a list of values
14348
14349        Raises
14350        ------
14351        pyAgrum.InvalidArgument
14352          If the node already has an evidence
14353        pyAgrum.InvalidArgument
14354          If val is not a value for the node
14355        pyAgrum.InvalidArgument
14356          If the size of vals is different from the domain side of the node
14357        pyAgrum.FatalError
14358          If vals is a vector of 0s
14359        pyAgrum.UndefinedElement
14360          If the node does not belong to the Bayesian network
14361
14362        """
14363        return _pyAgrum.GibbsSampling_addEvidence(self, *args)
14364
14365    def chgEvidence(self, *args) -> None:
14366        r"""
14367
14368        Change the value of an already existing evidence on a node (might be soft or hard).
14369
14370        Parameters
14371        ----------
14372        id : int
14373          a node Id
14374        nodeName : int
14375          a node name
14376        val :
14377          (int) a node value
14378        val :
14379          (str) the label of the node value
14380        vals : list
14381          a list of values
14382
14383        Raises
14384        ------
14385        pyAgrum.InvalidArgument
14386          If the node does not already have an evidence
14387        pyAgrum.InvalidArgument
14388          If val is not a value for the node
14389        pyAgrum.InvalidArgument
14390          If the size of vals is different from the domain side of the node
14391        pyAgrum.FatalError
14392          If vals is a vector of 0s
14393        pyAgrum.UndefinedElement
14394          If the node does not belong to the Bayesian network
14395
14396        """
14397        return _pyAgrum.GibbsSampling_chgEvidence(self, *args)
14398
14399    def hasEvidence(self, *args) -> bool:
14400        r"""
14401
14402        Parameters
14403        ----------
14404        id : int
14405          a node Id
14406        nodeName : str
14407          a node name
14408
14409        Returns
14410        -------
14411        bool
14412          True if some node(s) (or the one in parameters) have received evidence
14413
14414        Raises
14415        ------
14416        pyAgrum.IndexError
14417          If the node does not belong to the Bayesian network
14418
14419        """
14420        return _pyAgrum.GibbsSampling_hasEvidence(self, *args)
14421
14422    def eraseAllEvidence(self) -> None:
14423        r"""
14424
14425        Removes all the evidence entered into the network.
14426
14427        """
14428        return _pyAgrum.GibbsSampling_eraseAllEvidence(self)
14429
14430    def eraseEvidence(self, *args) -> None:
14431        r"""
14432
14433        Remove the evidence, if any, corresponding to the node Id or name.
14434
14435        Parameters
14436        ----------
14437        id : int
14438          a node Id
14439        nodeName : int
14440          a node name
14441
14442        Raises
14443        ------
14444        pyAgrum.IndexError
14445          If the node does not belong to the Bayesian network
14446
14447        """
14448        return _pyAgrum.GibbsSampling_eraseEvidence(self, *args)
14449
14450    def hasHardEvidence(self, nodeName: str) -> bool:
14451        r"""
14452
14453        Parameters
14454        ----------
14455        id : int
14456          a node Id
14457        nodeName : str
14458          a node name
14459
14460        Returns
14461        -------
14462        bool
14463          True if node has received a hard evidence
14464
14465        Raises
14466        ------
14467        pyAgrum.IndexError
14468          If the node does not belong to the Bayesian network
14469
14470        """
14471        return _pyAgrum.GibbsSampling_hasHardEvidence(self, nodeName)
14472
14473    def hasSoftEvidence(self, *args) -> bool:
14474        r"""
14475
14476        Parameters
14477        ----------
14478        id : int
14479          a node Id
14480        nodeName : str
14481          a node name
14482
14483        Returns
14484        -------
14485        bool
14486          True if node has received a soft evidence
14487
14488        Raises
14489        ------
14490        pyAgrum.IndexError
14491          If the node does not belong to the Bayesian network
14492
14493        """
14494        return _pyAgrum.GibbsSampling_hasSoftEvidence(self, *args)
14495
14496    def nbrEvidence(self) -> int:
14497        r"""
14498
14499        Returns
14500        -------
14501        int
14502          the number of evidence entered into the Bayesian network
14503
14504        """
14505        return _pyAgrum.GibbsSampling_nbrEvidence(self)
14506
14507    def nbrHardEvidence(self) -> int:
14508        r"""
14509
14510        Returns
14511        -------
14512        int
14513          the number of hard evidence entered into the Bayesian network
14514
14515        """
14516        return _pyAgrum.GibbsSampling_nbrHardEvidence(self)
14517
14518    def nbrSoftEvidence(self) -> int:
14519        r"""
14520
14521        Returns
14522        -------
14523        int
14524          the number of soft evidence entered into the Bayesian network
14525
14526        """
14527        return _pyAgrum.GibbsSampling_nbrSoftEvidence(self)
14528
14529    def eraseAllTargets(self) -> None:
14530        r"""
14531
14532        Clear all previously defined targets (marginal and joint targets).
14533
14534        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
14535
14536        """
14537        return _pyAgrum.GibbsSampling_eraseAllTargets(self)
14538
14539    def addAllTargets(self) -> None:
14540        r"""
14541
14542        Add all the nodes as targets.
14543
14544        """
14545        return _pyAgrum.GibbsSampling_addAllTargets(self)
14546
14547    def addTarget(self, *args) -> None:
14548        r"""
14549
14550        Add a marginal target to the list of targets.
14551
14552        Parameters
14553        ----------
14554        target : int
14555          a node Id
14556        nodeName : str
14557          a node name
14558
14559        Raises
14560        ------
14561        pyAgrum.UndefinedElement
14562          If target is not a NodeId in the Bayes net
14563
14564        """
14565        return _pyAgrum.GibbsSampling_addTarget(self, *args)
14566
14567    def eraseTarget(self, *args) -> None:
14568        r"""
14569
14570        Remove, if existing, the marginal target.
14571
14572        Parameters
14573        ----------
14574        target : int
14575          a node Id
14576        nodeName : int
14577          a node name
14578
14579        Raises
14580        ------
14581        pyAgrum.IndexError
14582          If one of the node does not belong to the Bayesian network
14583        pyAgrum.UndefinedElement
14584          If node Id is not in the Bayesian network
14585
14586        """
14587        return _pyAgrum.GibbsSampling_eraseTarget(self, *args)
14588
14589    def isTarget(self, *args) -> bool:
14590        r"""
14591
14592        Parameters
14593        ----------
14594        variable : int
14595         a node Id
14596        nodeName : str
14597          a node name
14598
14599        Returns
14600        -------
14601        bool
14602          True if variable is a (marginal) target
14603
14604        Raises
14605        ------
14606        pyAgrum.IndexError
14607          If the node does not belong to the Bayesian network
14608        pyAgrum.UndefinedElement
14609          If node Id is not in the Bayesian network
14610
14611        """
14612        return _pyAgrum.GibbsSampling_isTarget(self, *args)
14613
14614    def nbrTargets(self) -> int:
14615        r"""
14616
14617        Returns
14618        -------
14619        int
14620          the number of marginal targets
14621
14622        """
14623        return _pyAgrum.GibbsSampling_nbrTargets(self)
14624
14625    def H(self, *args) -> float:
14626        r"""
14627
14628        Parameters
14629        ----------
14630        X : int
14631          a node Id
14632        nodeName : str
14633          a node name
14634
14635        Returns
14636        -------
14637        float
14638          the computed Shanon's entropy of a node given the observation
14639
14640        """
14641        return _pyAgrum.GibbsSampling_H(self, *args)
14642
14643    def BN(self) -> "pyAgrum.IBayesNet":
14644        r"""
14645
14646        Returns
14647        -------
14648        pyAgrum.IBayesNet
14649          A constant reference over the IBayesNet referenced by this class.
14650
14651        Raises
14652        ------
14653        pyAgrum.UndefinedElement
14654          If no Bayes net has been assigned to the inference.
14655
14656        """
14657        return _pyAgrum.GibbsSampling_BN(self)
14658
14659    def currentPosterior(self, *args) -> "pyAgrum.Potential":
14660        r"""
14661
14662        Computes and returns the current posterior of a node.
14663
14664        Parameters
14665        ----------
14666        var : int
14667          the node Id of the node for which we need a posterior probability
14668        nodeName : str
14669          the node name of the node for which we need a posterior probability
14670
14671        Returns
14672        -------
14673        pyAgrum.Potential
14674          a const ref to the current posterior probability of the node
14675
14676        Raises
14677        ------
14678        UndefinedElement
14679          If an element of nodes is not in targets
14680
14681        """
14682        return _pyAgrum.GibbsSampling_currentPosterior(self, *args)
14683
14684    def nbrDrawnVar(self) -> int:
14685        r"""
14686
14687        Returns
14688        -------
14689        int
14690          the number of variable drawn at each iteration
14691
14692        """
14693        return _pyAgrum.GibbsSampling_nbrDrawnVar(self)
14694
14695    def setNbrDrawnVar(self, _nbr: int) -> None:
14696        r"""
14697
14698        Parameters
14699        ----------
14700        _nbr : int
14701          the number of variables to be drawn at each iteration
14702
14703        """
14704        return _pyAgrum.GibbsSampling_setNbrDrawnVar(self, _nbr)
14705
14706    def isDrawnAtRandom(self) -> bool:
14707        r"""
14708
14709        Returns
14710        -------
14711        bool
14712          True if variables are drawn at random
14713
14714        """
14715        return _pyAgrum.GibbsSampling_isDrawnAtRandom(self)
14716
14717    def setDrawnAtRandom(self, _atRandom: bool) -> None:
14718        r"""
14719
14720        Parameters
14721        ----------
14722        _atRandom : bool
14723          indicates if variables should be drawn at random
14724
14725        """
14726        return _pyAgrum.GibbsSampling_setDrawnAtRandom(self, _atRandom)
14727
14728# Register GibbsSampling in _pyAgrum:
14729_pyAgrum.GibbsSampling_swigregister(GibbsSampling)
14730
14731class ImportanceSampling(object):
14732    r"""
14733
14734    Class used for inferences using the Importance Sampling algorithm.
14735
14736    ImportanceSampling(bn) -> ImportanceSampling
14737        Parameters:
14738            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
14739
14740    """
14741
14742    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
14743    __repr__ = _swig_repr
14744
14745    def __init__(self, bn: "IBayesNet"):
14746        _pyAgrum.ImportanceSampling_swiginit(self, _pyAgrum.new_ImportanceSampling(bn))
14747
14748        self._model=bn#BN
14749
14750
14751
14752    __swig_destroy__ = _pyAgrum.delete_ImportanceSampling
14753
14754    def setEvidence(self, evidces):
14755        """
14756        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
14757
14758        Parameters
14759        ----------
14760        evidces : dict
14761          a dict of evidences
14762
14763        Raises
14764        ------
14765        gum.InvalidArgument
14766            If one value is not a value for the node
14767        gum.InvalidArgument
14768            If the size of a value is different from the domain side of the node
14769        gum.FatalError
14770            If one value is a vector of 0s
14771        gum.UndefinedElement
14772            If one node does not belong to the Bayesian network
14773        """
14774        if not isinstance(evidces, dict):
14775            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
14776        self.eraseAllEvidence()
14777        for k,v in evidces.items():
14778            self.addEvidence(k,v)
14779
14780
14781
14782    def updateEvidence(self, evidces):
14783        """
14784        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
14785
14786        Parameters
14787        ----------
14788        evidces : dict
14789          a dict of evidences
14790
14791        Raises
14792        ------
14793        gum.InvalidArgument
14794            If one value is not a value for the node
14795        gum.InvalidArgument
14796            If the size of a value is different from the domain side of the node
14797        gum.FatalError
14798            If one value is a vector of 0s
14799        gum.UndefinedElement
14800            If one node does not belong to the Bayesian network
14801        """
14802        if not isinstance(evidces, dict):
14803            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
14804
14805        for k,v in evidces.items():
14806            if self.hasEvidence(k):
14807                self.chgEvidence(k,v)
14808            else:
14809                self.addEvidence(k,v)
14810
14811
14812
14813    def setTargets(self, targets):
14814        """
14815        Remove all the targets and add the ones in parameter.
14816
14817        Parameters
14818        ----------
14819        targets : set
14820          a set of targets
14821
14822        Raises
14823        ------
14824        gum.UndefinedElement
14825            If one target is not in the Bayes net
14826        """
14827        if not isinstance(targets, set):
14828            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
14829
14830        self.eraseAllTargets()
14831        for k in targets:
14832            self.addTarget(k)
14833
14834
14835
14836    def hardEvidenceNodes(self) -> object:
14837        r"""
14838
14839        Returns
14840        -------
14841        set
14842          the set of nodes with hard evidence
14843
14844        """
14845        return _pyAgrum.ImportanceSampling_hardEvidenceNodes(self)
14846
14847    def softEvidenceNodes(self) -> object:
14848        r"""
14849
14850        Returns
14851        -------
14852        set
14853          the set of nodes with soft evidence
14854
14855        """
14856        return _pyAgrum.ImportanceSampling_softEvidenceNodes(self)
14857
14858    def targets(self) -> object:
14859        r"""
14860
14861        Returns
14862        -------
14863        list
14864          the list of marginal targets
14865
14866        """
14867        return _pyAgrum.ImportanceSampling_targets(self)
14868
14869    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
14870        r"""
14871
14872        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
14873
14874        Parameters
14875        ----------
14876        target : set
14877          a set of targets ids or names.
14878        evs : set
14879          a set of nodes ids or names.
14880
14881        Warnings
14882        --------
14883        if some evs are d-separated, they are not included in the Potential.
14884
14885        Returns
14886        -------
14887        pyAgrum.Potential
14888          a Potential for P(targets|evs)
14889
14890        """
14891        return _pyAgrum.ImportanceSampling_evidenceImpact(self, target, evs)
14892
14893    def setVerbosity(self, v: bool) -> None:
14894        r"""
14895
14896        Parameters
14897        ----------
14898        v : bool
14899                verbosity
14900
14901        """
14902        return _pyAgrum.ImportanceSampling_setVerbosity(self, v)
14903
14904    def setEpsilon(self, eps: float) -> None:
14905        r"""
14906
14907        Parameters
14908        ----------
14909        eps : float
14910        	the epsilon we want to use
14911
14912        Raises
14913        ------
14914        pyAgrum.OutOfBounds
14915        	If eps<0
14916
14917        """
14918        return _pyAgrum.ImportanceSampling_setEpsilon(self, eps)
14919
14920    def setMinEpsilonRate(self, rate: float) -> None:
14921        r"""
14922
14923        Parameters
14924        ----------
14925        rate : float
14926        	the minimal epsilon rate
14927
14928        """
14929        return _pyAgrum.ImportanceSampling_setMinEpsilonRate(self, rate)
14930
14931    def setMaxIter(self, max: int) -> None:
14932        r"""
14933
14934        Parameters
14935        ----------
14936        max : int
14937        	the maximum number of iteration
14938
14939        Raises
14940        ------
14941        pyAgrum.OutOfBounds
14942        	If max <= 1
14943
14944        """
14945        return _pyAgrum.ImportanceSampling_setMaxIter(self, max)
14946
14947    def setMaxTime(self, timeout: float) -> None:
14948        r"""
14949
14950        Parameters
14951        ----------
14952        tiemout : float
14953        	stopping criterion on timeout (in seconds)
14954
14955        Raises
14956        ------
14957        pyAgrum.OutOfBounds
14958        	If timeout<=0.0
14959
14960        """
14961        return _pyAgrum.ImportanceSampling_setMaxTime(self, timeout)
14962
14963    def setPeriodSize(self, p: int) -> None:
14964        r"""
14965
14966        Parameters
14967        ----------
14968        p : int
14969        	number of samples between 2 stopping
14970
14971        Raises
14972        ------
14973        pyAgrum.OutOfBounds
14974        	If p<1
14975
14976        """
14977        return _pyAgrum.ImportanceSampling_setPeriodSize(self, p)
14978
14979    def verbosity(self) -> bool:
14980        r"""
14981
14982        Returns
14983        -------
14984        bool
14985        	True if the verbosity is enabled
14986
14987        """
14988        return _pyAgrum.ImportanceSampling_verbosity(self)
14989
14990    def epsilon(self) -> float:
14991        r"""
14992
14993        Returns
14994        -------
14995        float
14996        	the value of epsilon
14997
14998        """
14999        return _pyAgrum.ImportanceSampling_epsilon(self)
15000
15001    def minEpsilonRate(self) -> float:
15002        r"""
15003
15004        Returns
15005        -------
15006        float
15007        	the value of the minimal epsilon rate
15008
15009        """
15010        return _pyAgrum.ImportanceSampling_minEpsilonRate(self)
15011
15012    def maxIter(self) -> int:
15013        r"""
15014
15015        Returns
15016        -------
15017        int
15018        	the criterion on number of iterations
15019
15020        """
15021        return _pyAgrum.ImportanceSampling_maxIter(self)
15022
15023    def maxTime(self) -> float:
15024        r"""
15025
15026        Returns
15027        -------
15028        float
15029        	the timeout(in seconds)
15030
15031        """
15032        return _pyAgrum.ImportanceSampling_maxTime(self)
15033
15034    def periodSize(self) -> int:
15035        r"""
15036
15037        Returns
15038        -------
15039        int
15040        	the number of samples between 2 stopping
15041
15042        Raises
15043        ------
15044        pyAgrum.OutOfBounds
15045        	If p<1
15046
15047        """
15048        return _pyAgrum.ImportanceSampling_periodSize(self)
15049
15050    def nbrIterations(self) -> int:
15051        r"""
15052
15053        Returns
15054        -------
15055        int
15056        	the number of iterations
15057
15058        """
15059        return _pyAgrum.ImportanceSampling_nbrIterations(self)
15060
15061    def currentTime(self) -> float:
15062        r"""
15063
15064        Returns
15065        -------
15066        float
15067        	get the current running time in second (float)
15068
15069        """
15070        return _pyAgrum.ImportanceSampling_currentTime(self)
15071
15072    def messageApproximationScheme(self) -> str:
15073        r"""
15074
15075        Returns
15076        -------
15077        str
15078        	the approximation scheme message
15079
15080        """
15081        return _pyAgrum.ImportanceSampling_messageApproximationScheme(self)
15082
15083    def history(self) -> List[float]:
15084        r"""
15085
15086        Returns
15087        -------
15088        tuple
15089        	the scheme history
15090
15091        Raises
15092        ------
15093        pyAgrum.OperationNotAllowed
15094        	If the scheme did not performed or if verbosity is set to false
15095
15096        """
15097        return _pyAgrum.ImportanceSampling_history(self)
15098
15099    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
15100        return _pyAgrum.ImportanceSampling__asIApproximationSchemeConfiguration(self)
15101
15102    def makeInference(self) -> None:
15103        r"""
15104
15105        Perform the heavy computations needed to compute the targets' posteriors
15106
15107        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
15108        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
15109
15110        """
15111        return _pyAgrum.ImportanceSampling_makeInference(self)
15112
15113    def posterior(self, *args) -> "pyAgrum.Potential":
15114        r"""
15115
15116        Computes and returns the posterior of a node.
15117
15118        Parameters
15119        ----------
15120        var : int
15121          the node Id of the node for which we need a posterior probability
15122        nodeName : str
15123          the node name of the node for which we need a posterior probability
15124
15125        Returns
15126        -------
15127        pyAgrum.Potential
15128          a const ref to the posterior probability of the node
15129
15130        Raises
15131        ------
15132        pyAgrum.UndefinedElement
15133          If an element of nodes is not in targets
15134
15135        """
15136        return _pyAgrum.ImportanceSampling_posterior(self, *args)
15137
15138    def addEvidence(self, *args) -> None:
15139        r"""
15140
15141        Adds a new evidence on a node (might be soft or hard).
15142
15143        Parameters
15144        ----------
15145        id : int
15146          a node Id
15147        nodeName : int
15148          a node name
15149        val :
15150          (int) a node value
15151        val :
15152          (str) the label of the node value
15153        vals : list
15154          a list of values
15155
15156        Raises
15157        ------
15158        pyAgrum.InvalidArgument
15159          If the node already has an evidence
15160        pyAgrum.InvalidArgument
15161          If val is not a value for the node
15162        pyAgrum.InvalidArgument
15163          If the size of vals is different from the domain side of the node
15164        pyAgrum.FatalError
15165          If vals is a vector of 0s
15166        pyAgrum.UndefinedElement
15167          If the node does not belong to the Bayesian network
15168
15169        """
15170        return _pyAgrum.ImportanceSampling_addEvidence(self, *args)
15171
15172    def chgEvidence(self, *args) -> None:
15173        r"""
15174
15175        Change the value of an already existing evidence on a node (might be soft or hard).
15176
15177        Parameters
15178        ----------
15179        id : int
15180          a node Id
15181        nodeName : int
15182          a node name
15183        val :
15184          (int) a node value
15185        val :
15186          (str) the label of the node value
15187        vals : list
15188          a list of values
15189
15190        Raises
15191        ------
15192        pyAgrum.InvalidArgument
15193          If the node does not already have an evidence
15194        pyAgrum.InvalidArgument
15195          If val is not a value for the node
15196        pyAgrum.InvalidArgument
15197          If the size of vals is different from the domain side of the node
15198        pyAgrum.FatalError
15199          If vals is a vector of 0s
15200        pyAgrum.UndefinedElement
15201          If the node does not belong to the Bayesian network
15202
15203        """
15204        return _pyAgrum.ImportanceSampling_chgEvidence(self, *args)
15205
15206    def hasEvidence(self, *args) -> bool:
15207        r"""
15208
15209        Parameters
15210        ----------
15211        id : int
15212          a node Id
15213        nodeName : str
15214          a node name
15215
15216        Returns
15217        -------
15218        bool
15219          True if some node(s) (or the one in parameters) have received evidence
15220
15221        Raises
15222        ------
15223        pyAgrum.IndexError
15224          If the node does not belong to the Bayesian network
15225
15226        """
15227        return _pyAgrum.ImportanceSampling_hasEvidence(self, *args)
15228
15229    def eraseAllEvidence(self) -> None:
15230        r"""
15231
15232        Removes all the evidence entered into the network.
15233
15234        """
15235        return _pyAgrum.ImportanceSampling_eraseAllEvidence(self)
15236
15237    def eraseEvidence(self, *args) -> None:
15238        r"""
15239
15240        Remove the evidence, if any, corresponding to the node Id or name.
15241
15242        Parameters
15243        ----------
15244        id : int
15245          a node Id
15246        nodeName : int
15247          a node name
15248
15249        Raises
15250        ------
15251        pyAgrum.IndexError
15252          If the node does not belong to the Bayesian network
15253
15254        """
15255        return _pyAgrum.ImportanceSampling_eraseEvidence(self, *args)
15256
15257    def hasHardEvidence(self, nodeName: str) -> bool:
15258        r"""
15259
15260        Parameters
15261        ----------
15262        id : int
15263          a node Id
15264        nodeName : str
15265          a node name
15266
15267        Returns
15268        -------
15269        bool
15270          True if node has received a hard evidence
15271
15272        Raises
15273        ------
15274        pyAgrum.IndexError
15275          If the node does not belong to the Bayesian network
15276
15277        """
15278        return _pyAgrum.ImportanceSampling_hasHardEvidence(self, nodeName)
15279
15280    def hasSoftEvidence(self, *args) -> bool:
15281        r"""
15282
15283        Parameters
15284        ----------
15285        id : int
15286          a node Id
15287        nodeName : str
15288          a node name
15289
15290        Returns
15291        -------
15292        bool
15293          True if node has received a soft evidence
15294
15295        Raises
15296        ------
15297        pyAgrum.IndexError
15298          If the node does not belong to the Bayesian network
15299
15300        """
15301        return _pyAgrum.ImportanceSampling_hasSoftEvidence(self, *args)
15302
15303    def nbrEvidence(self) -> int:
15304        r"""
15305
15306        Returns
15307        -------
15308        int
15309          the number of evidence entered into the Bayesian network
15310
15311        """
15312        return _pyAgrum.ImportanceSampling_nbrEvidence(self)
15313
15314    def nbrHardEvidence(self) -> int:
15315        r"""
15316
15317        Returns
15318        -------
15319        int
15320          the number of hard evidence entered into the Bayesian network
15321
15322        """
15323        return _pyAgrum.ImportanceSampling_nbrHardEvidence(self)
15324
15325    def nbrSoftEvidence(self) -> int:
15326        r"""
15327
15328        Returns
15329        -------
15330        int
15331          the number of soft evidence entered into the Bayesian network
15332
15333        """
15334        return _pyAgrum.ImportanceSampling_nbrSoftEvidence(self)
15335
15336    def eraseAllTargets(self) -> None:
15337        r"""
15338
15339        Clear all previously defined targets (marginal and joint targets).
15340
15341        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
15342
15343        """
15344        return _pyAgrum.ImportanceSampling_eraseAllTargets(self)
15345
15346    def addAllTargets(self) -> None:
15347        r"""
15348
15349        Add all the nodes as targets.
15350
15351        """
15352        return _pyAgrum.ImportanceSampling_addAllTargets(self)
15353
15354    def addTarget(self, *args) -> None:
15355        r"""
15356
15357        Add a marginal target to the list of targets.
15358
15359        Parameters
15360        ----------
15361        target : int
15362          a node Id
15363        nodeName : str
15364          a node name
15365
15366        Raises
15367        ------
15368        pyAgrum.UndefinedElement
15369          If target is not a NodeId in the Bayes net
15370
15371        """
15372        return _pyAgrum.ImportanceSampling_addTarget(self, *args)
15373
15374    def eraseTarget(self, *args) -> None:
15375        r"""
15376
15377        Remove, if existing, the marginal target.
15378
15379        Parameters
15380        ----------
15381        target : int
15382          a node Id
15383        nodeName : int
15384          a node name
15385
15386        Raises
15387        ------
15388        pyAgrum.IndexError
15389          If one of the node does not belong to the Bayesian network
15390        pyAgrum.UndefinedElement
15391          If node Id is not in the Bayesian network
15392
15393        """
15394        return _pyAgrum.ImportanceSampling_eraseTarget(self, *args)
15395
15396    def isTarget(self, *args) -> bool:
15397        r"""
15398
15399        Parameters
15400        ----------
15401        variable : int
15402         a node Id
15403        nodeName : str
15404          a node name
15405
15406        Returns
15407        -------
15408        bool
15409          True if variable is a (marginal) target
15410
15411        Raises
15412        ------
15413        pyAgrum.IndexError
15414          If the node does not belong to the Bayesian network
15415        pyAgrum.UndefinedElement
15416          If node Id is not in the Bayesian network
15417
15418        """
15419        return _pyAgrum.ImportanceSampling_isTarget(self, *args)
15420
15421    def nbrTargets(self) -> int:
15422        r"""
15423
15424        Returns
15425        -------
15426        int
15427          the number of marginal targets
15428
15429        """
15430        return _pyAgrum.ImportanceSampling_nbrTargets(self)
15431
15432    def H(self, *args) -> float:
15433        r"""
15434
15435        Parameters
15436        ----------
15437        X : int
15438          a node Id
15439        nodeName : str
15440          a node name
15441
15442        Returns
15443        -------
15444        float
15445          the computed Shanon's entropy of a node given the observation
15446
15447        """
15448        return _pyAgrum.ImportanceSampling_H(self, *args)
15449
15450    def BN(self) -> "pyAgrum.IBayesNet":
15451        r"""
15452
15453        Returns
15454        -------
15455        pyAgrum.IBayesNet
15456          A constant reference over the IBayesNet referenced by this class.
15457
15458        Raises
15459        ------
15460        pyAgrum.UndefinedElement
15461          If no Bayes net has been assigned to the inference.
15462
15463        """
15464        return _pyAgrum.ImportanceSampling_BN(self)
15465
15466    def currentPosterior(self, *args) -> "pyAgrum.Potential":
15467        r"""
15468
15469        Computes and returns the current posterior of a node.
15470
15471        Parameters
15472        ----------
15473        var : int
15474          the node Id of the node for which we need a posterior probability
15475        nodeName : str
15476          the node name of the node for which we need a posterior probability
15477
15478        Returns
15479        -------
15480        pyAgrum.Potential
15481          a const ref to the current posterior probability of the node
15482
15483        Raises
15484        ------
15485        UndefinedElement
15486          If an element of nodes is not in targets
15487
15488        """
15489        return _pyAgrum.ImportanceSampling_currentPosterior(self, *args)
15490
15491# Register ImportanceSampling in _pyAgrum:
15492_pyAgrum.ImportanceSampling_swigregister(ImportanceSampling)
15493
15494class WeightedSampling(object):
15495    r"""
15496
15497    Class used for Weighted sampling inference algorithm.
15498
15499    WeightedSampling(bn) -> WeightedSampling
15500        Parameters:
15501            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
15502
15503    """
15504
15505    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
15506    __repr__ = _swig_repr
15507
15508    def __init__(self, bn: "IBayesNet"):
15509        _pyAgrum.WeightedSampling_swiginit(self, _pyAgrum.new_WeightedSampling(bn))
15510
15511        self._model=bn#BN
15512
15513
15514
15515    __swig_destroy__ = _pyAgrum.delete_WeightedSampling
15516
15517    def setEvidence(self, evidces):
15518        """
15519        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
15520
15521        Parameters
15522        ----------
15523        evidces : dict
15524          a dict of evidences
15525
15526        Raises
15527        ------
15528        gum.InvalidArgument
15529            If one value is not a value for the node
15530        gum.InvalidArgument
15531            If the size of a value is different from the domain side of the node
15532        gum.FatalError
15533            If one value is a vector of 0s
15534        gum.UndefinedElement
15535            If one node does not belong to the Bayesian network
15536        """
15537        if not isinstance(evidces, dict):
15538            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
15539        self.eraseAllEvidence()
15540        for k,v in evidces.items():
15541            self.addEvidence(k,v)
15542
15543
15544
15545    def updateEvidence(self, evidces):
15546        """
15547        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
15548
15549        Parameters
15550        ----------
15551        evidces : dict
15552          a dict of evidences
15553
15554        Raises
15555        ------
15556        gum.InvalidArgument
15557            If one value is not a value for the node
15558        gum.InvalidArgument
15559            If the size of a value is different from the domain side of the node
15560        gum.FatalError
15561            If one value is a vector of 0s
15562        gum.UndefinedElement
15563            If one node does not belong to the Bayesian network
15564        """
15565        if not isinstance(evidces, dict):
15566            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
15567
15568        for k,v in evidces.items():
15569            if self.hasEvidence(k):
15570                self.chgEvidence(k,v)
15571            else:
15572                self.addEvidence(k,v)
15573
15574
15575
15576    def setTargets(self, targets):
15577        """
15578        Remove all the targets and add the ones in parameter.
15579
15580        Parameters
15581        ----------
15582        targets : set
15583          a set of targets
15584
15585        Raises
15586        ------
15587        gum.UndefinedElement
15588            If one target is not in the Bayes net
15589        """
15590        if not isinstance(targets, set):
15591            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
15592
15593        self.eraseAllTargets()
15594        for k in targets:
15595            self.addTarget(k)
15596
15597
15598
15599    def hardEvidenceNodes(self) -> object:
15600        r"""
15601
15602        Returns
15603        -------
15604        set
15605          the set of nodes with hard evidence
15606
15607        """
15608        return _pyAgrum.WeightedSampling_hardEvidenceNodes(self)
15609
15610    def softEvidenceNodes(self) -> object:
15611        r"""
15612
15613        Returns
15614        -------
15615        set
15616          the set of nodes with soft evidence
15617
15618        """
15619        return _pyAgrum.WeightedSampling_softEvidenceNodes(self)
15620
15621    def targets(self) -> object:
15622        r"""
15623
15624        Returns
15625        -------
15626        list
15627          the list of marginal targets
15628
15629        """
15630        return _pyAgrum.WeightedSampling_targets(self)
15631
15632    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
15633        r"""
15634
15635        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
15636
15637        Parameters
15638        ----------
15639        target : set
15640          a set of targets ids or names.
15641        evs : set
15642          a set of nodes ids or names.
15643
15644        Warnings
15645        --------
15646        if some evs are d-separated, they are not included in the Potential.
15647
15648        Returns
15649        -------
15650        pyAgrum.Potential
15651          a Potential for P(targets|evs)
15652
15653        """
15654        return _pyAgrum.WeightedSampling_evidenceImpact(self, target, evs)
15655
15656    def setVerbosity(self, v: bool) -> None:
15657        r"""
15658
15659        Parameters
15660        ----------
15661        v : bool
15662                verbosity
15663
15664        """
15665        return _pyAgrum.WeightedSampling_setVerbosity(self, v)
15666
15667    def setEpsilon(self, eps: float) -> None:
15668        r"""
15669
15670        Parameters
15671        ----------
15672        eps : float
15673        	the epsilon we want to use
15674
15675        Raises
15676        ------
15677        pyAgrum.OutOfBounds
15678        	If eps<0
15679
15680        """
15681        return _pyAgrum.WeightedSampling_setEpsilon(self, eps)
15682
15683    def setMinEpsilonRate(self, rate: float) -> None:
15684        r"""
15685
15686        Parameters
15687        ----------
15688        rate : float
15689        	the minimal epsilon rate
15690
15691        """
15692        return _pyAgrum.WeightedSampling_setMinEpsilonRate(self, rate)
15693
15694    def setMaxIter(self, max: int) -> None:
15695        r"""
15696
15697        Parameters
15698        ----------
15699        max : int
15700        	the maximum number of iteration
15701
15702        Raises
15703        ------
15704        pyAgrum.OutOfBounds
15705        	If max <= 1
15706
15707        """
15708        return _pyAgrum.WeightedSampling_setMaxIter(self, max)
15709
15710    def setMaxTime(self, timeout: float) -> None:
15711        r"""
15712
15713        Parameters
15714        ----------
15715        tiemout : float
15716        	stopping criterion on timeout (in seconds)
15717
15718        Raises
15719        ------
15720        pyAgrum.OutOfBounds
15721        	If timeout<=0.0
15722
15723        """
15724        return _pyAgrum.WeightedSampling_setMaxTime(self, timeout)
15725
15726    def setPeriodSize(self, p: int) -> None:
15727        r"""
15728
15729        Parameters
15730        ----------
15731        p : int
15732        	number of samples between 2 stopping
15733
15734        Raises
15735        ------
15736        pyAgrum.OutOfBounds
15737        	If p<1
15738
15739        """
15740        return _pyAgrum.WeightedSampling_setPeriodSize(self, p)
15741
15742    def verbosity(self) -> bool:
15743        r"""
15744
15745        Returns
15746        -------
15747        bool
15748        	True if the verbosity is enabled
15749
15750        """
15751        return _pyAgrum.WeightedSampling_verbosity(self)
15752
15753    def epsilon(self) -> float:
15754        r"""
15755
15756        Returns
15757        -------
15758        float
15759        	the value of epsilon
15760
15761        """
15762        return _pyAgrum.WeightedSampling_epsilon(self)
15763
15764    def minEpsilonRate(self) -> float:
15765        r"""
15766
15767        Returns
15768        -------
15769        float
15770        	the value of the minimal epsilon rate
15771
15772        """
15773        return _pyAgrum.WeightedSampling_minEpsilonRate(self)
15774
15775    def maxIter(self) -> int:
15776        r"""
15777
15778        Returns
15779        -------
15780        int
15781        	the criterion on number of iterations
15782
15783        """
15784        return _pyAgrum.WeightedSampling_maxIter(self)
15785
15786    def maxTime(self) -> float:
15787        r"""
15788
15789        Returns
15790        -------
15791        float
15792        	the timeout(in seconds)
15793
15794        """
15795        return _pyAgrum.WeightedSampling_maxTime(self)
15796
15797    def periodSize(self) -> int:
15798        r"""
15799
15800        Returns
15801        -------
15802        int
15803        	the number of samples between 2 stopping
15804
15805        Raises
15806        ------
15807        pyAgrum.OutOfBounds
15808        	If p<1
15809
15810        """
15811        return _pyAgrum.WeightedSampling_periodSize(self)
15812
15813    def nbrIterations(self) -> int:
15814        r"""
15815
15816        Returns
15817        -------
15818        int
15819        	the number of iterations
15820
15821        """
15822        return _pyAgrum.WeightedSampling_nbrIterations(self)
15823
15824    def currentTime(self) -> float:
15825        r"""
15826
15827        Returns
15828        -------
15829        float
15830        	get the current running time in second (float)
15831
15832        """
15833        return _pyAgrum.WeightedSampling_currentTime(self)
15834
15835    def messageApproximationScheme(self) -> str:
15836        r"""
15837
15838        Returns
15839        -------
15840        str
15841        	the approximation scheme message
15842
15843        """
15844        return _pyAgrum.WeightedSampling_messageApproximationScheme(self)
15845
15846    def history(self) -> List[float]:
15847        r"""
15848
15849        Returns
15850        -------
15851        tuple
15852        	the scheme history
15853
15854        Raises
15855        ------
15856        pyAgrum.OperationNotAllowed
15857        	If the scheme did not performed or if verbosity is set to false
15858
15859        """
15860        return _pyAgrum.WeightedSampling_history(self)
15861
15862    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
15863        return _pyAgrum.WeightedSampling__asIApproximationSchemeConfiguration(self)
15864
15865    def makeInference(self) -> None:
15866        r"""
15867
15868        Perform the heavy computations needed to compute the targets' posteriors
15869
15870        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
15871        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
15872
15873        """
15874        return _pyAgrum.WeightedSampling_makeInference(self)
15875
15876    def posterior(self, *args) -> "pyAgrum.Potential":
15877        r"""
15878
15879        Computes and returns the posterior of a node.
15880
15881        Parameters
15882        ----------
15883        var : int
15884          the node Id of the node for which we need a posterior probability
15885        nodeName : str
15886          the node name of the node for which we need a posterior probability
15887
15888        Returns
15889        -------
15890        pyAgrum.Potential
15891          a const ref to the posterior probability of the node
15892
15893        Raises
15894        ------
15895        pyAgrum.UndefinedElement
15896          If an element of nodes is not in targets
15897
15898        """
15899        return _pyAgrum.WeightedSampling_posterior(self, *args)
15900
15901    def addEvidence(self, *args) -> None:
15902        r"""
15903
15904        Adds a new evidence on a node (might be soft or hard).
15905
15906        Parameters
15907        ----------
15908        id : int
15909          a node Id
15910        nodeName : int
15911          a node name
15912        val :
15913          (int) a node value
15914        val :
15915          (str) the label of the node value
15916        vals : list
15917          a list of values
15918
15919        Raises
15920        ------
15921        pyAgrum.InvalidArgument
15922          If the node already has an evidence
15923        pyAgrum.InvalidArgument
15924          If val is not a value for the node
15925        pyAgrum.InvalidArgument
15926          If the size of vals is different from the domain side of the node
15927        pyAgrum.FatalError
15928          If vals is a vector of 0s
15929        pyAgrum.UndefinedElement
15930          If the node does not belong to the Bayesian network
15931
15932        """
15933        return _pyAgrum.WeightedSampling_addEvidence(self, *args)
15934
15935    def chgEvidence(self, *args) -> None:
15936        r"""
15937
15938        Change the value of an already existing evidence on a node (might be soft or hard).
15939
15940        Parameters
15941        ----------
15942        id : int
15943          a node Id
15944        nodeName : int
15945          a node name
15946        val :
15947          (int) a node value
15948        val :
15949          (str) the label of the node value
15950        vals : list
15951          a list of values
15952
15953        Raises
15954        ------
15955        pyAgrum.InvalidArgument
15956          If the node does not already have an evidence
15957        pyAgrum.InvalidArgument
15958          If val is not a value for the node
15959        pyAgrum.InvalidArgument
15960          If the size of vals is different from the domain side of the node
15961        pyAgrum.FatalError
15962          If vals is a vector of 0s
15963        pyAgrum.UndefinedElement
15964          If the node does not belong to the Bayesian network
15965
15966        """
15967        return _pyAgrum.WeightedSampling_chgEvidence(self, *args)
15968
15969    def hasEvidence(self, *args) -> bool:
15970        r"""
15971
15972        Parameters
15973        ----------
15974        id : int
15975          a node Id
15976        nodeName : str
15977          a node name
15978
15979        Returns
15980        -------
15981        bool
15982          True if some node(s) (or the one in parameters) have received evidence
15983
15984        Raises
15985        ------
15986        pyAgrum.IndexError
15987          If the node does not belong to the Bayesian network
15988
15989        """
15990        return _pyAgrum.WeightedSampling_hasEvidence(self, *args)
15991
15992    def eraseAllEvidence(self) -> None:
15993        r"""
15994
15995        Removes all the evidence entered into the network.
15996
15997        """
15998        return _pyAgrum.WeightedSampling_eraseAllEvidence(self)
15999
16000    def eraseEvidence(self, *args) -> None:
16001        r"""
16002
16003        Remove the evidence, if any, corresponding to the node Id or name.
16004
16005        Parameters
16006        ----------
16007        id : int
16008          a node Id
16009        nodeName : int
16010          a node name
16011
16012        Raises
16013        ------
16014        pyAgrum.IndexError
16015          If the node does not belong to the Bayesian network
16016
16017        """
16018        return _pyAgrum.WeightedSampling_eraseEvidence(self, *args)
16019
16020    def hasHardEvidence(self, nodeName: str) -> bool:
16021        r"""
16022
16023        Parameters
16024        ----------
16025        id : int
16026          a node Id
16027        nodeName : str
16028          a node name
16029
16030        Returns
16031        -------
16032        bool
16033          True if node has received a hard evidence
16034
16035        Raises
16036        ------
16037        pyAgrum.IndexError
16038          If the node does not belong to the Bayesian network
16039
16040        """
16041        return _pyAgrum.WeightedSampling_hasHardEvidence(self, nodeName)
16042
16043    def hasSoftEvidence(self, *args) -> bool:
16044        r"""
16045
16046        Parameters
16047        ----------
16048        id : int
16049          a node Id
16050        nodeName : str
16051          a node name
16052
16053        Returns
16054        -------
16055        bool
16056          True if node has received a soft evidence
16057
16058        Raises
16059        ------
16060        pyAgrum.IndexError
16061          If the node does not belong to the Bayesian network
16062
16063        """
16064        return _pyAgrum.WeightedSampling_hasSoftEvidence(self, *args)
16065
16066    def nbrEvidence(self) -> int:
16067        r"""
16068
16069        Returns
16070        -------
16071        int
16072          the number of evidence entered into the Bayesian network
16073
16074        """
16075        return _pyAgrum.WeightedSampling_nbrEvidence(self)
16076
16077    def nbrHardEvidence(self) -> int:
16078        r"""
16079
16080        Returns
16081        -------
16082        int
16083          the number of hard evidence entered into the Bayesian network
16084
16085        """
16086        return _pyAgrum.WeightedSampling_nbrHardEvidence(self)
16087
16088    def nbrSoftEvidence(self) -> int:
16089        r"""
16090
16091        Returns
16092        -------
16093        int
16094          the number of soft evidence entered into the Bayesian network
16095
16096        """
16097        return _pyAgrum.WeightedSampling_nbrSoftEvidence(self)
16098
16099    def eraseAllTargets(self) -> None:
16100        r"""
16101
16102        Clear all previously defined targets (marginal and joint targets).
16103
16104        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
16105
16106        """
16107        return _pyAgrum.WeightedSampling_eraseAllTargets(self)
16108
16109    def addAllTargets(self) -> None:
16110        r"""
16111
16112        Add all the nodes as targets.
16113
16114        """
16115        return _pyAgrum.WeightedSampling_addAllTargets(self)
16116
16117    def addTarget(self, *args) -> None:
16118        r"""
16119
16120        Add a marginal target to the list of targets.
16121
16122        Parameters
16123        ----------
16124        target : int
16125          a node Id
16126        nodeName : str
16127          a node name
16128
16129        Raises
16130        ------
16131        pyAgrum.UndefinedElement
16132          If target is not a NodeId in the Bayes net
16133
16134        """
16135        return _pyAgrum.WeightedSampling_addTarget(self, *args)
16136
16137    def eraseTarget(self, *args) -> None:
16138        r"""
16139
16140        Remove, if existing, the marginal target.
16141
16142        Parameters
16143        ----------
16144        target : int
16145          a node Id
16146        nodeName : int
16147          a node name
16148
16149        Raises
16150        ------
16151        pyAgrum.IndexError
16152          If one of the node does not belong to the Bayesian network
16153        pyAgrum.UndefinedElement
16154          If node Id is not in the Bayesian network
16155
16156        """
16157        return _pyAgrum.WeightedSampling_eraseTarget(self, *args)
16158
16159    def isTarget(self, *args) -> bool:
16160        r"""
16161
16162        Parameters
16163        ----------
16164        variable : int
16165         a node Id
16166        nodeName : str
16167          a node name
16168
16169        Returns
16170        -------
16171        bool
16172          True if variable is a (marginal) target
16173
16174        Raises
16175        ------
16176        pyAgrum.IndexError
16177          If the node does not belong to the Bayesian network
16178        pyAgrum.UndefinedElement
16179          If node Id is not in the Bayesian network
16180
16181        """
16182        return _pyAgrum.WeightedSampling_isTarget(self, *args)
16183
16184    def nbrTargets(self) -> int:
16185        r"""
16186
16187        Returns
16188        -------
16189        int
16190          the number of marginal targets
16191
16192        """
16193        return _pyAgrum.WeightedSampling_nbrTargets(self)
16194
16195    def H(self, *args) -> float:
16196        r"""
16197
16198        Parameters
16199        ----------
16200        X : int
16201          a node Id
16202        nodeName : str
16203          a node name
16204
16205        Returns
16206        -------
16207        float
16208          the computed Shanon's entropy of a node given the observation
16209
16210        """
16211        return _pyAgrum.WeightedSampling_H(self, *args)
16212
16213    def BN(self) -> "pyAgrum.IBayesNet":
16214        r"""
16215
16216        Returns
16217        -------
16218        pyAgrum.IBayesNet
16219          A constant reference over the IBayesNet referenced by this class.
16220
16221        Raises
16222        ------
16223        pyAgrum.UndefinedElement
16224          If no Bayes net has been assigned to the inference.
16225
16226        """
16227        return _pyAgrum.WeightedSampling_BN(self)
16228
16229    def currentPosterior(self, *args) -> "pyAgrum.Potential":
16230        r"""
16231
16232        Computes and returns the current posterior of a node.
16233
16234        Parameters
16235        ----------
16236        var : int
16237          the node Id of the node for which we need a posterior probability
16238        nodeName : str
16239          the node name of the node for which we need a posterior probability
16240
16241        Returns
16242        -------
16243        pyAgrum.Potential
16244          a const ref to the current posterior probability of the node
16245
16246        Raises
16247        ------
16248        UndefinedElement
16249          If an element of nodes is not in targets
16250
16251        """
16252        return _pyAgrum.WeightedSampling_currentPosterior(self, *args)
16253
16254# Register WeightedSampling in _pyAgrum:
16255_pyAgrum.WeightedSampling_swigregister(WeightedSampling)
16256
16257class MonteCarloSampling(object):
16258    r"""
16259
16260    Class used for Monte Carlo sampling inference algorithm.
16261
16262    MonteCarloSampling(bn) -> MonteCarloSampling
16263        Parameters:
16264            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
16265
16266    """
16267
16268    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
16269    __repr__ = _swig_repr
16270
16271    def __init__(self, bn: "IBayesNet"):
16272        _pyAgrum.MonteCarloSampling_swiginit(self, _pyAgrum.new_MonteCarloSampling(bn))
16273
16274        self._model=bn#BN
16275
16276
16277
16278    __swig_destroy__ = _pyAgrum.delete_MonteCarloSampling
16279
16280    def setEvidence(self, evidces):
16281        """
16282        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
16283
16284        Parameters
16285        ----------
16286        evidces : dict
16287          a dict of evidences
16288
16289        Raises
16290        ------
16291        gum.InvalidArgument
16292            If one value is not a value for the node
16293        gum.InvalidArgument
16294            If the size of a value is different from the domain side of the node
16295        gum.FatalError
16296            If one value is a vector of 0s
16297        gum.UndefinedElement
16298            If one node does not belong to the Bayesian network
16299        """
16300        if not isinstance(evidces, dict):
16301            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
16302        self.eraseAllEvidence()
16303        for k,v in evidces.items():
16304            self.addEvidence(k,v)
16305
16306
16307
16308    def updateEvidence(self, evidces):
16309        """
16310        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
16311
16312        Parameters
16313        ----------
16314        evidces : dict
16315          a dict of evidences
16316
16317        Raises
16318        ------
16319        gum.InvalidArgument
16320            If one value is not a value for the node
16321        gum.InvalidArgument
16322            If the size of a value is different from the domain side of the node
16323        gum.FatalError
16324            If one value is a vector of 0s
16325        gum.UndefinedElement
16326            If one node does not belong to the Bayesian network
16327        """
16328        if not isinstance(evidces, dict):
16329            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
16330
16331        for k,v in evidces.items():
16332            if self.hasEvidence(k):
16333                self.chgEvidence(k,v)
16334            else:
16335                self.addEvidence(k,v)
16336
16337
16338
16339    def setTargets(self, targets):
16340        """
16341        Remove all the targets and add the ones in parameter.
16342
16343        Parameters
16344        ----------
16345        targets : set
16346          a set of targets
16347
16348        Raises
16349        ------
16350        gum.UndefinedElement
16351            If one target is not in the Bayes net
16352        """
16353        if not isinstance(targets, set):
16354            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
16355
16356        self.eraseAllTargets()
16357        for k in targets:
16358            self.addTarget(k)
16359
16360
16361
16362    def hardEvidenceNodes(self) -> object:
16363        r"""
16364
16365        Returns
16366        -------
16367        set
16368          the set of nodes with hard evidence
16369
16370        """
16371        return _pyAgrum.MonteCarloSampling_hardEvidenceNodes(self)
16372
16373    def softEvidenceNodes(self) -> object:
16374        r"""
16375
16376        Returns
16377        -------
16378        set
16379          the set of nodes with soft evidence
16380
16381        """
16382        return _pyAgrum.MonteCarloSampling_softEvidenceNodes(self)
16383
16384    def targets(self) -> object:
16385        r"""
16386
16387        Returns
16388        -------
16389        list
16390          the list of marginal targets
16391
16392        """
16393        return _pyAgrum.MonteCarloSampling_targets(self)
16394
16395    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
16396        r"""
16397
16398        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
16399
16400        Parameters
16401        ----------
16402        target : set
16403          a set of targets ids or names.
16404        evs : set
16405          a set of nodes ids or names.
16406
16407        Warnings
16408        --------
16409        if some evs are d-separated, they are not included in the Potential.
16410
16411        Returns
16412        -------
16413        pyAgrum.Potential
16414          a Potential for P(targets|evs)
16415
16416        """
16417        return _pyAgrum.MonteCarloSampling_evidenceImpact(self, target, evs)
16418
16419    def setVerbosity(self, v: bool) -> None:
16420        r"""
16421
16422        Parameters
16423        ----------
16424        v : bool
16425                verbosity
16426
16427        """
16428        return _pyAgrum.MonteCarloSampling_setVerbosity(self, v)
16429
16430    def setEpsilon(self, eps: float) -> None:
16431        r"""
16432
16433        Parameters
16434        ----------
16435        eps : float
16436        	the epsilon we want to use
16437
16438        Raises
16439        ------
16440        pyAgrum.OutOfBounds
16441        	If eps<0
16442
16443        """
16444        return _pyAgrum.MonteCarloSampling_setEpsilon(self, eps)
16445
16446    def setMinEpsilonRate(self, rate: float) -> None:
16447        r"""
16448
16449        Parameters
16450        ----------
16451        rate : float
16452        	the minimal epsilon rate
16453
16454        """
16455        return _pyAgrum.MonteCarloSampling_setMinEpsilonRate(self, rate)
16456
16457    def setMaxIter(self, max: int) -> None:
16458        r"""
16459
16460        Parameters
16461        ----------
16462        max : int
16463        	the maximum number of iteration
16464
16465        Raises
16466        ------
16467        pyAgrum.OutOfBounds
16468        	If max <= 1
16469
16470        """
16471        return _pyAgrum.MonteCarloSampling_setMaxIter(self, max)
16472
16473    def setMaxTime(self, timeout: float) -> None:
16474        r"""
16475
16476        Parameters
16477        ----------
16478        tiemout : float
16479        	stopping criterion on timeout (in seconds)
16480
16481        Raises
16482        ------
16483        pyAgrum.OutOfBounds
16484        	If timeout<=0.0
16485
16486        """
16487        return _pyAgrum.MonteCarloSampling_setMaxTime(self, timeout)
16488
16489    def setPeriodSize(self, p: int) -> None:
16490        r"""
16491
16492        Parameters
16493        ----------
16494        p : int
16495        	number of samples between 2 stopping
16496
16497        Raises
16498        ------
16499        pyAgrum.OutOfBounds
16500        	If p<1
16501
16502        """
16503        return _pyAgrum.MonteCarloSampling_setPeriodSize(self, p)
16504
16505    def verbosity(self) -> bool:
16506        r"""
16507
16508        Returns
16509        -------
16510        bool
16511        	True if the verbosity is enabled
16512
16513        """
16514        return _pyAgrum.MonteCarloSampling_verbosity(self)
16515
16516    def epsilon(self) -> float:
16517        r"""
16518
16519        Returns
16520        -------
16521        float
16522        	the value of epsilon
16523
16524        """
16525        return _pyAgrum.MonteCarloSampling_epsilon(self)
16526
16527    def minEpsilonRate(self) -> float:
16528        r"""
16529
16530        Returns
16531        -------
16532        float
16533        	the value of the minimal epsilon rate
16534
16535        """
16536        return _pyAgrum.MonteCarloSampling_minEpsilonRate(self)
16537
16538    def maxIter(self) -> int:
16539        r"""
16540
16541        Returns
16542        -------
16543        int
16544        	the criterion on number of iterations
16545
16546        """
16547        return _pyAgrum.MonteCarloSampling_maxIter(self)
16548
16549    def maxTime(self) -> float:
16550        r"""
16551
16552        Returns
16553        -------
16554        float
16555        	the timeout(in seconds)
16556
16557        """
16558        return _pyAgrum.MonteCarloSampling_maxTime(self)
16559
16560    def periodSize(self) -> int:
16561        r"""
16562
16563        Returns
16564        -------
16565        int
16566        	the number of samples between 2 stopping
16567
16568        Raises
16569        ------
16570        pyAgrum.OutOfBounds
16571        	If p<1
16572
16573        """
16574        return _pyAgrum.MonteCarloSampling_periodSize(self)
16575
16576    def nbrIterations(self) -> int:
16577        r"""
16578
16579        Returns
16580        -------
16581        int
16582        	the number of iterations
16583
16584        """
16585        return _pyAgrum.MonteCarloSampling_nbrIterations(self)
16586
16587    def currentTime(self) -> float:
16588        r"""
16589
16590        Returns
16591        -------
16592        float
16593        	get the current running time in second (float)
16594
16595        """
16596        return _pyAgrum.MonteCarloSampling_currentTime(self)
16597
16598    def messageApproximationScheme(self) -> str:
16599        r"""
16600
16601        Returns
16602        -------
16603        str
16604        	the approximation scheme message
16605
16606        """
16607        return _pyAgrum.MonteCarloSampling_messageApproximationScheme(self)
16608
16609    def history(self) -> List[float]:
16610        r"""
16611
16612        Returns
16613        -------
16614        tuple
16615        	the scheme history
16616
16617        Raises
16618        ------
16619        pyAgrum.OperationNotAllowed
16620        	If the scheme did not performed or if verbosity is set to false
16621
16622        """
16623        return _pyAgrum.MonteCarloSampling_history(self)
16624
16625    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
16626        return _pyAgrum.MonteCarloSampling__asIApproximationSchemeConfiguration(self)
16627
16628    def makeInference(self) -> None:
16629        r"""
16630
16631        Perform the heavy computations needed to compute the targets' posteriors
16632
16633        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
16634        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
16635
16636        """
16637        return _pyAgrum.MonteCarloSampling_makeInference(self)
16638
16639    def posterior(self, *args) -> "pyAgrum.Potential":
16640        r"""
16641
16642        Computes and returns the posterior of a node.
16643
16644        Parameters
16645        ----------
16646        var : int
16647          the node Id of the node for which we need a posterior probability
16648        nodeName : str
16649          the node name of the node for which we need a posterior probability
16650
16651        Returns
16652        -------
16653        pyAgrum.Potential
16654          a const ref to the posterior probability of the node
16655
16656        Raises
16657        ------
16658        pyAgrum.UndefinedElement
16659          If an element of nodes is not in targets
16660
16661        """
16662        return _pyAgrum.MonteCarloSampling_posterior(self, *args)
16663
16664    def addEvidence(self, *args) -> None:
16665        r"""
16666
16667        Adds a new evidence on a node (might be soft or hard).
16668
16669        Parameters
16670        ----------
16671        id : int
16672          a node Id
16673        nodeName : int
16674          a node name
16675        val :
16676          (int) a node value
16677        val :
16678          (str) the label of the node value
16679        vals : list
16680          a list of values
16681
16682        Raises
16683        ------
16684        pyAgrum.InvalidArgument
16685          If the node already has an evidence
16686        pyAgrum.InvalidArgument
16687          If val is not a value for the node
16688        pyAgrum.InvalidArgument
16689          If the size of vals is different from the domain side of the node
16690        pyAgrum.FatalError
16691          If vals is a vector of 0s
16692        pyAgrum.UndefinedElement
16693          If the node does not belong to the Bayesian network
16694
16695        """
16696        return _pyAgrum.MonteCarloSampling_addEvidence(self, *args)
16697
16698    def chgEvidence(self, *args) -> None:
16699        r"""
16700
16701        Change the value of an already existing evidence on a node (might be soft or hard).
16702
16703        Parameters
16704        ----------
16705        id : int
16706          a node Id
16707        nodeName : int
16708          a node name
16709        val :
16710          (int) a node value
16711        val :
16712          (str) the label of the node value
16713        vals : list
16714          a list of values
16715
16716        Raises
16717        ------
16718        pyAgrum.InvalidArgument
16719          If the node does not already have an evidence
16720        pyAgrum.InvalidArgument
16721          If val is not a value for the node
16722        pyAgrum.InvalidArgument
16723          If the size of vals is different from the domain side of the node
16724        pyAgrum.FatalError
16725          If vals is a vector of 0s
16726        pyAgrum.UndefinedElement
16727          If the node does not belong to the Bayesian network
16728
16729        """
16730        return _pyAgrum.MonteCarloSampling_chgEvidence(self, *args)
16731
16732    def hasEvidence(self, *args) -> bool:
16733        r"""
16734
16735        Parameters
16736        ----------
16737        id : int
16738          a node Id
16739        nodeName : str
16740          a node name
16741
16742        Returns
16743        -------
16744        bool
16745          True if some node(s) (or the one in parameters) have received evidence
16746
16747        Raises
16748        ------
16749        pyAgrum.IndexError
16750          If the node does not belong to the Bayesian network
16751
16752        """
16753        return _pyAgrum.MonteCarloSampling_hasEvidence(self, *args)
16754
16755    def eraseAllEvidence(self) -> None:
16756        r"""
16757
16758        Removes all the evidence entered into the network.
16759
16760        """
16761        return _pyAgrum.MonteCarloSampling_eraseAllEvidence(self)
16762
16763    def eraseEvidence(self, *args) -> None:
16764        r"""
16765
16766        Remove the evidence, if any, corresponding to the node Id or name.
16767
16768        Parameters
16769        ----------
16770        id : int
16771          a node Id
16772        nodeName : int
16773          a node name
16774
16775        Raises
16776        ------
16777        pyAgrum.IndexError
16778          If the node does not belong to the Bayesian network
16779
16780        """
16781        return _pyAgrum.MonteCarloSampling_eraseEvidence(self, *args)
16782
16783    def hasHardEvidence(self, nodeName: str) -> bool:
16784        r"""
16785
16786        Parameters
16787        ----------
16788        id : int
16789          a node Id
16790        nodeName : str
16791          a node name
16792
16793        Returns
16794        -------
16795        bool
16796          True if node has received a hard evidence
16797
16798        Raises
16799        ------
16800        pyAgrum.IndexError
16801          If the node does not belong to the Bayesian network
16802
16803        """
16804        return _pyAgrum.MonteCarloSampling_hasHardEvidence(self, nodeName)
16805
16806    def hasSoftEvidence(self, *args) -> bool:
16807        r"""
16808
16809        Parameters
16810        ----------
16811        id : int
16812          a node Id
16813        nodeName : str
16814          a node name
16815
16816        Returns
16817        -------
16818        bool
16819          True if node has received a soft evidence
16820
16821        Raises
16822        ------
16823        pyAgrum.IndexError
16824          If the node does not belong to the Bayesian network
16825
16826        """
16827        return _pyAgrum.MonteCarloSampling_hasSoftEvidence(self, *args)
16828
16829    def nbrEvidence(self) -> int:
16830        r"""
16831
16832        Returns
16833        -------
16834        int
16835          the number of evidence entered into the Bayesian network
16836
16837        """
16838        return _pyAgrum.MonteCarloSampling_nbrEvidence(self)
16839
16840    def nbrHardEvidence(self) -> int:
16841        r"""
16842
16843        Returns
16844        -------
16845        int
16846          the number of hard evidence entered into the Bayesian network
16847
16848        """
16849        return _pyAgrum.MonteCarloSampling_nbrHardEvidence(self)
16850
16851    def nbrSoftEvidence(self) -> int:
16852        r"""
16853
16854        Returns
16855        -------
16856        int
16857          the number of soft evidence entered into the Bayesian network
16858
16859        """
16860        return _pyAgrum.MonteCarloSampling_nbrSoftEvidence(self)
16861
16862    def eraseAllTargets(self) -> None:
16863        r"""
16864
16865        Clear all previously defined targets (marginal and joint targets).
16866
16867        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
16868
16869        """
16870        return _pyAgrum.MonteCarloSampling_eraseAllTargets(self)
16871
16872    def addAllTargets(self) -> None:
16873        r"""
16874
16875        Add all the nodes as targets.
16876
16877        """
16878        return _pyAgrum.MonteCarloSampling_addAllTargets(self)
16879
16880    def addTarget(self, *args) -> None:
16881        r"""
16882
16883        Add a marginal target to the list of targets.
16884
16885        Parameters
16886        ----------
16887        target : int
16888          a node Id
16889        nodeName : str
16890          a node name
16891
16892        Raises
16893        ------
16894        pyAgrum.UndefinedElement
16895          If target is not a NodeId in the Bayes net
16896
16897        """
16898        return _pyAgrum.MonteCarloSampling_addTarget(self, *args)
16899
16900    def eraseTarget(self, *args) -> None:
16901        r"""
16902
16903        Remove, if existing, the marginal target.
16904
16905        Parameters
16906        ----------
16907        target : int
16908          a node Id
16909        nodeName : int
16910          a node name
16911
16912        Raises
16913        ------
16914        pyAgrum.IndexError
16915          If one of the node does not belong to the Bayesian network
16916        pyAgrum.UndefinedElement
16917          If node Id is not in the Bayesian network
16918
16919        """
16920        return _pyAgrum.MonteCarloSampling_eraseTarget(self, *args)
16921
16922    def isTarget(self, *args) -> bool:
16923        r"""
16924
16925        Parameters
16926        ----------
16927        variable : int
16928         a node Id
16929        nodeName : str
16930          a node name
16931
16932        Returns
16933        -------
16934        bool
16935          True if variable is a (marginal) target
16936
16937        Raises
16938        ------
16939        pyAgrum.IndexError
16940          If the node does not belong to the Bayesian network
16941        pyAgrum.UndefinedElement
16942          If node Id is not in the Bayesian network
16943
16944        """
16945        return _pyAgrum.MonteCarloSampling_isTarget(self, *args)
16946
16947    def nbrTargets(self) -> int:
16948        r"""
16949
16950        Returns
16951        -------
16952        int
16953          the number of marginal targets
16954
16955        """
16956        return _pyAgrum.MonteCarloSampling_nbrTargets(self)
16957
16958    def H(self, *args) -> float:
16959        r"""
16960
16961        Parameters
16962        ----------
16963        X : int
16964          a node Id
16965        nodeName : str
16966          a node name
16967
16968        Returns
16969        -------
16970        float
16971          the computed Shanon's entropy of a node given the observation
16972
16973        """
16974        return _pyAgrum.MonteCarloSampling_H(self, *args)
16975
16976    def BN(self) -> "pyAgrum.IBayesNet":
16977        r"""
16978
16979        Returns
16980        -------
16981        pyAgrum.IBayesNet
16982          A constant reference over the IBayesNet referenced by this class.
16983
16984        Raises
16985        ------
16986        pyAgrum.UndefinedElement
16987          If no Bayes net has been assigned to the inference.
16988
16989        """
16990        return _pyAgrum.MonteCarloSampling_BN(self)
16991
16992    def currentPosterior(self, *args) -> "pyAgrum.Potential":
16993        r"""
16994
16995        Computes and returns the current posterior of a node.
16996
16997        Parameters
16998        ----------
16999        var : int
17000          the node Id of the node for which we need a posterior probability
17001        nodeName : str
17002          the node name of the node for which we need a posterior probability
17003
17004        Returns
17005        -------
17006        pyAgrum.Potential
17007          a const ref to the current posterior probability of the node
17008
17009        Raises
17010        ------
17011        UndefinedElement
17012          If an element of nodes is not in targets
17013
17014        """
17015        return _pyAgrum.MonteCarloSampling_currentPosterior(self, *args)
17016
17017# Register MonteCarloSampling in _pyAgrum:
17018_pyAgrum.MonteCarloSampling_swigregister(MonteCarloSampling)
17019
17020class LoopyImportanceSampling(ImportanceSampling):
17021    r"""
17022
17023    Class used for inferences using a loopy version of importance sampling.
17024
17025    LoopyImportanceSampling(bn) -> LoopyImportanceSampling
17026        Parameters:
17027            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
17028
17029    """
17030
17031    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
17032    __repr__ = _swig_repr
17033
17034    def __init__(self, bn: "IBayesNet"):
17035        _pyAgrum.LoopyImportanceSampling_swiginit(self, _pyAgrum.new_LoopyImportanceSampling(bn))
17036
17037        self._model=bn#BN
17038
17039
17040
17041    __swig_destroy__ = _pyAgrum.delete_LoopyImportanceSampling
17042
17043    def makeInference_(self) -> None:
17044        return _pyAgrum.LoopyImportanceSampling_makeInference_(self)
17045
17046    def setVirtualLBPSize(self, vlbpsize: float) -> None:
17047        r"""
17048
17049        Parameters
17050        ----------
17051        vlbpsize : float
17052          the size of the virtual LBP
17053
17054        """
17055        return _pyAgrum.LoopyImportanceSampling_setVirtualLBPSize(self, vlbpsize)
17056
17057    def setEvidence(self, evidces):
17058        """
17059        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
17060
17061        Parameters
17062        ----------
17063        evidces : dict
17064          a dict of evidences
17065
17066        Raises
17067        ------
17068        gum.InvalidArgument
17069            If one value is not a value for the node
17070        gum.InvalidArgument
17071            If the size of a value is different from the domain side of the node
17072        gum.FatalError
17073            If one value is a vector of 0s
17074        gum.UndefinedElement
17075            If one node does not belong to the Bayesian network
17076        """
17077        if not isinstance(evidces, dict):
17078            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
17079        self.eraseAllEvidence()
17080        for k,v in evidces.items():
17081            self.addEvidence(k,v)
17082
17083
17084
17085    def updateEvidence(self, evidces):
17086        """
17087        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
17088
17089        Parameters
17090        ----------
17091        evidces : dict
17092          a dict of evidences
17093
17094        Raises
17095        ------
17096        gum.InvalidArgument
17097            If one value is not a value for the node
17098        gum.InvalidArgument
17099            If the size of a value is different from the domain side of the node
17100        gum.FatalError
17101            If one value is a vector of 0s
17102        gum.UndefinedElement
17103            If one node does not belong to the Bayesian network
17104        """
17105        if not isinstance(evidces, dict):
17106            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
17107
17108        for k,v in evidces.items():
17109            if self.hasEvidence(k):
17110                self.chgEvidence(k,v)
17111            else:
17112                self.addEvidence(k,v)
17113
17114
17115
17116    def setTargets(self, targets):
17117        """
17118        Remove all the targets and add the ones in parameter.
17119
17120        Parameters
17121        ----------
17122        targets : set
17123          a set of targets
17124
17125        Raises
17126        ------
17127        gum.UndefinedElement
17128            If one target is not in the Bayes net
17129        """
17130        if not isinstance(targets, set):
17131            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
17132
17133        self.eraseAllTargets()
17134        for k in targets:
17135            self.addTarget(k)
17136
17137
17138
17139    def hardEvidenceNodes(self) -> object:
17140        r"""
17141
17142        Returns
17143        -------
17144        set
17145          the set of nodes with hard evidence
17146
17147        """
17148        return _pyAgrum.LoopyImportanceSampling_hardEvidenceNodes(self)
17149
17150    def softEvidenceNodes(self) -> object:
17151        r"""
17152
17153        Returns
17154        -------
17155        set
17156          the set of nodes with soft evidence
17157
17158        """
17159        return _pyAgrum.LoopyImportanceSampling_softEvidenceNodes(self)
17160
17161    def targets(self) -> object:
17162        r"""
17163
17164        Returns
17165        -------
17166        list
17167          the list of marginal targets
17168
17169        """
17170        return _pyAgrum.LoopyImportanceSampling_targets(self)
17171
17172    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
17173        r"""
17174
17175        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
17176
17177        Parameters
17178        ----------
17179        target : set
17180          a set of targets ids or names.
17181        evs : set
17182          a set of nodes ids or names.
17183
17184        Warnings
17185        --------
17186        if some evs are d-separated, they are not included in the Potential.
17187
17188        Returns
17189        -------
17190        pyAgrum.Potential
17191          a Potential for P(targets|evs)
17192
17193        """
17194        return _pyAgrum.LoopyImportanceSampling_evidenceImpact(self, target, evs)
17195
17196    def setVerbosity(self, v: bool) -> None:
17197        r"""
17198
17199        Parameters
17200        ----------
17201        v : bool
17202                verbosity
17203
17204        """
17205        return _pyAgrum.LoopyImportanceSampling_setVerbosity(self, v)
17206
17207    def setEpsilon(self, eps: float) -> None:
17208        r"""
17209
17210        Parameters
17211        ----------
17212        eps : float
17213        	the epsilon we want to use
17214
17215        Raises
17216        ------
17217        pyAgrum.OutOfBounds
17218        	If eps<0
17219
17220        """
17221        return _pyAgrum.LoopyImportanceSampling_setEpsilon(self, eps)
17222
17223    def setMinEpsilonRate(self, rate: float) -> None:
17224        r"""
17225
17226        Parameters
17227        ----------
17228        rate : float
17229        	the minimal epsilon rate
17230
17231        """
17232        return _pyAgrum.LoopyImportanceSampling_setMinEpsilonRate(self, rate)
17233
17234    def setMaxIter(self, max: int) -> None:
17235        r"""
17236
17237        Parameters
17238        ----------
17239        max : int
17240        	the maximum number of iteration
17241
17242        Raises
17243        ------
17244        pyAgrum.OutOfBounds
17245        	If max <= 1
17246
17247        """
17248        return _pyAgrum.LoopyImportanceSampling_setMaxIter(self, max)
17249
17250    def setMaxTime(self, timeout: float) -> None:
17251        r"""
17252
17253        Parameters
17254        ----------
17255        tiemout : float
17256        	stopping criterion on timeout (in seconds)
17257
17258        Raises
17259        ------
17260        pyAgrum.OutOfBounds
17261        	If timeout<=0.0
17262
17263        """
17264        return _pyAgrum.LoopyImportanceSampling_setMaxTime(self, timeout)
17265
17266    def setPeriodSize(self, p: int) -> None:
17267        r"""
17268
17269        Parameters
17270        ----------
17271        p : int
17272        	number of samples between 2 stopping
17273
17274        Raises
17275        ------
17276        pyAgrum.OutOfBounds
17277        	If p<1
17278
17279        """
17280        return _pyAgrum.LoopyImportanceSampling_setPeriodSize(self, p)
17281
17282    def verbosity(self) -> bool:
17283        r"""
17284
17285        Returns
17286        -------
17287        bool
17288        	True if the verbosity is enabled
17289
17290        """
17291        return _pyAgrum.LoopyImportanceSampling_verbosity(self)
17292
17293    def epsilon(self) -> float:
17294        r"""
17295
17296        Returns
17297        -------
17298        float
17299        	the value of epsilon
17300
17301        """
17302        return _pyAgrum.LoopyImportanceSampling_epsilon(self)
17303
17304    def minEpsilonRate(self) -> float:
17305        r"""
17306
17307        Returns
17308        -------
17309        float
17310        	the value of the minimal epsilon rate
17311
17312        """
17313        return _pyAgrum.LoopyImportanceSampling_minEpsilonRate(self)
17314
17315    def maxIter(self) -> int:
17316        r"""
17317
17318        Returns
17319        -------
17320        int
17321        	the criterion on number of iterations
17322
17323        """
17324        return _pyAgrum.LoopyImportanceSampling_maxIter(self)
17325
17326    def maxTime(self) -> float:
17327        r"""
17328
17329        Returns
17330        -------
17331        float
17332        	the timeout(in seconds)
17333
17334        """
17335        return _pyAgrum.LoopyImportanceSampling_maxTime(self)
17336
17337    def periodSize(self) -> int:
17338        r"""
17339
17340        Returns
17341        -------
17342        int
17343        	the number of samples between 2 stopping
17344
17345        Raises
17346        ------
17347        pyAgrum.OutOfBounds
17348        	If p<1
17349
17350        """
17351        return _pyAgrum.LoopyImportanceSampling_periodSize(self)
17352
17353    def nbrIterations(self) -> int:
17354        r"""
17355
17356        Returns
17357        -------
17358        int
17359        	the number of iterations
17360
17361        """
17362        return _pyAgrum.LoopyImportanceSampling_nbrIterations(self)
17363
17364    def currentTime(self) -> float:
17365        r"""
17366
17367        Returns
17368        -------
17369        float
17370        	get the current running time in second (float)
17371
17372        """
17373        return _pyAgrum.LoopyImportanceSampling_currentTime(self)
17374
17375    def messageApproximationScheme(self) -> str:
17376        r"""
17377
17378        Returns
17379        -------
17380        str
17381        	the approximation scheme message
17382
17383        """
17384        return _pyAgrum.LoopyImportanceSampling_messageApproximationScheme(self)
17385
17386    def history(self) -> List[float]:
17387        r"""
17388
17389        Returns
17390        -------
17391        tuple
17392        	the scheme history
17393
17394        Raises
17395        ------
17396        pyAgrum.OperationNotAllowed
17397        	If the scheme did not performed or if verbosity is set to false
17398
17399        """
17400        return _pyAgrum.LoopyImportanceSampling_history(self)
17401
17402    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
17403        return _pyAgrum.LoopyImportanceSampling__asIApproximationSchemeConfiguration(self)
17404
17405    def makeInference(self) -> None:
17406        r"""
17407
17408        Perform the heavy computations needed to compute the targets' posteriors
17409
17410        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
17411        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
17412
17413        """
17414        return _pyAgrum.LoopyImportanceSampling_makeInference(self)
17415
17416    def posterior(self, *args) -> "pyAgrum.Potential":
17417        r"""
17418
17419        Computes and returns the posterior of a node.
17420
17421        Parameters
17422        ----------
17423        var : int
17424          the node Id of the node for which we need a posterior probability
17425        nodeName : str
17426          the node name of the node for which we need a posterior probability
17427
17428        Returns
17429        -------
17430        pyAgrum.Potential
17431          a const ref to the posterior probability of the node
17432
17433        Raises
17434        ------
17435        pyAgrum.UndefinedElement
17436          If an element of nodes is not in targets
17437
17438        """
17439        return _pyAgrum.LoopyImportanceSampling_posterior(self, *args)
17440
17441    def addEvidence(self, *args) -> None:
17442        r"""
17443
17444        Adds a new evidence on a node (might be soft or hard).
17445
17446        Parameters
17447        ----------
17448        id : int
17449          a node Id
17450        nodeName : int
17451          a node name
17452        val :
17453          (int) a node value
17454        val :
17455          (str) the label of the node value
17456        vals : list
17457          a list of values
17458
17459        Raises
17460        ------
17461        pyAgrum.InvalidArgument
17462          If the node already has an evidence
17463        pyAgrum.InvalidArgument
17464          If val is not a value for the node
17465        pyAgrum.InvalidArgument
17466          If the size of vals is different from the domain side of the node
17467        pyAgrum.FatalError
17468          If vals is a vector of 0s
17469        pyAgrum.UndefinedElement
17470          If the node does not belong to the Bayesian network
17471
17472        """
17473        return _pyAgrum.LoopyImportanceSampling_addEvidence(self, *args)
17474
17475    def chgEvidence(self, *args) -> None:
17476        r"""
17477
17478        Change the value of an already existing evidence on a node (might be soft or hard).
17479
17480        Parameters
17481        ----------
17482        id : int
17483          a node Id
17484        nodeName : int
17485          a node name
17486        val :
17487          (int) a node value
17488        val :
17489          (str) the label of the node value
17490        vals : list
17491          a list of values
17492
17493        Raises
17494        ------
17495        pyAgrum.InvalidArgument
17496          If the node does not already have an evidence
17497        pyAgrum.InvalidArgument
17498          If val is not a value for the node
17499        pyAgrum.InvalidArgument
17500          If the size of vals is different from the domain side of the node
17501        pyAgrum.FatalError
17502          If vals is a vector of 0s
17503        pyAgrum.UndefinedElement
17504          If the node does not belong to the Bayesian network
17505
17506        """
17507        return _pyAgrum.LoopyImportanceSampling_chgEvidence(self, *args)
17508
17509    def hasEvidence(self, *args) -> bool:
17510        r"""
17511
17512        Parameters
17513        ----------
17514        id : int
17515          a node Id
17516        nodeName : str
17517          a node name
17518
17519        Returns
17520        -------
17521        bool
17522          True if some node(s) (or the one in parameters) have received evidence
17523
17524        Raises
17525        ------
17526        pyAgrum.IndexError
17527          If the node does not belong to the Bayesian network
17528
17529        """
17530        return _pyAgrum.LoopyImportanceSampling_hasEvidence(self, *args)
17531
17532    def eraseAllEvidence(self) -> None:
17533        r"""
17534
17535        Removes all the evidence entered into the network.
17536
17537        """
17538        return _pyAgrum.LoopyImportanceSampling_eraseAllEvidence(self)
17539
17540    def eraseEvidence(self, *args) -> None:
17541        r"""
17542
17543        Remove the evidence, if any, corresponding to the node Id or name.
17544
17545        Parameters
17546        ----------
17547        id : int
17548          a node Id
17549        nodeName : int
17550          a node name
17551
17552        Raises
17553        ------
17554        pyAgrum.IndexError
17555          If the node does not belong to the Bayesian network
17556
17557        """
17558        return _pyAgrum.LoopyImportanceSampling_eraseEvidence(self, *args)
17559
17560    def hasHardEvidence(self, nodeName: str) -> bool:
17561        r"""
17562
17563        Parameters
17564        ----------
17565        id : int
17566          a node Id
17567        nodeName : str
17568          a node name
17569
17570        Returns
17571        -------
17572        bool
17573          True if node has received a hard evidence
17574
17575        Raises
17576        ------
17577        pyAgrum.IndexError
17578          If the node does not belong to the Bayesian network
17579
17580        """
17581        return _pyAgrum.LoopyImportanceSampling_hasHardEvidence(self, nodeName)
17582
17583    def hasSoftEvidence(self, *args) -> bool:
17584        r"""
17585
17586        Parameters
17587        ----------
17588        id : int
17589          a node Id
17590        nodeName : str
17591          a node name
17592
17593        Returns
17594        -------
17595        bool
17596          True if node has received a soft evidence
17597
17598        Raises
17599        ------
17600        pyAgrum.IndexError
17601          If the node does not belong to the Bayesian network
17602
17603        """
17604        return _pyAgrum.LoopyImportanceSampling_hasSoftEvidence(self, *args)
17605
17606    def nbrEvidence(self) -> int:
17607        r"""
17608
17609        Returns
17610        -------
17611        int
17612          the number of evidence entered into the Bayesian network
17613
17614        """
17615        return _pyAgrum.LoopyImportanceSampling_nbrEvidence(self)
17616
17617    def nbrHardEvidence(self) -> int:
17618        r"""
17619
17620        Returns
17621        -------
17622        int
17623          the number of hard evidence entered into the Bayesian network
17624
17625        """
17626        return _pyAgrum.LoopyImportanceSampling_nbrHardEvidence(self)
17627
17628    def nbrSoftEvidence(self) -> int:
17629        r"""
17630
17631        Returns
17632        -------
17633        int
17634          the number of soft evidence entered into the Bayesian network
17635
17636        """
17637        return _pyAgrum.LoopyImportanceSampling_nbrSoftEvidence(self)
17638
17639    def eraseAllTargets(self) -> None:
17640        r"""
17641
17642        Clear all previously defined targets (marginal and joint targets).
17643
17644        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
17645
17646        """
17647        return _pyAgrum.LoopyImportanceSampling_eraseAllTargets(self)
17648
17649    def addAllTargets(self) -> None:
17650        r"""
17651
17652        Add all the nodes as targets.
17653
17654        """
17655        return _pyAgrum.LoopyImportanceSampling_addAllTargets(self)
17656
17657    def addTarget(self, *args) -> None:
17658        r"""
17659
17660        Add a marginal target to the list of targets.
17661
17662        Parameters
17663        ----------
17664        target : int
17665          a node Id
17666        nodeName : str
17667          a node name
17668
17669        Raises
17670        ------
17671        pyAgrum.UndefinedElement
17672          If target is not a NodeId in the Bayes net
17673
17674        """
17675        return _pyAgrum.LoopyImportanceSampling_addTarget(self, *args)
17676
17677    def eraseTarget(self, *args) -> None:
17678        r"""
17679
17680        Remove, if existing, the marginal target.
17681
17682        Parameters
17683        ----------
17684        target : int
17685          a node Id
17686        nodeName : int
17687          a node name
17688
17689        Raises
17690        ------
17691        pyAgrum.IndexError
17692          If one of the node does not belong to the Bayesian network
17693        pyAgrum.UndefinedElement
17694          If node Id is not in the Bayesian network
17695
17696        """
17697        return _pyAgrum.LoopyImportanceSampling_eraseTarget(self, *args)
17698
17699    def isTarget(self, *args) -> bool:
17700        r"""
17701
17702        Parameters
17703        ----------
17704        variable : int
17705         a node Id
17706        nodeName : str
17707          a node name
17708
17709        Returns
17710        -------
17711        bool
17712          True if variable is a (marginal) target
17713
17714        Raises
17715        ------
17716        pyAgrum.IndexError
17717          If the node does not belong to the Bayesian network
17718        pyAgrum.UndefinedElement
17719          If node Id is not in the Bayesian network
17720
17721        """
17722        return _pyAgrum.LoopyImportanceSampling_isTarget(self, *args)
17723
17724    def nbrTargets(self) -> int:
17725        r"""
17726
17727        Returns
17728        -------
17729        int
17730          the number of marginal targets
17731
17732        """
17733        return _pyAgrum.LoopyImportanceSampling_nbrTargets(self)
17734
17735    def H(self, *args) -> float:
17736        r"""
17737
17738        Parameters
17739        ----------
17740        X : int
17741          a node Id
17742        nodeName : str
17743          a node name
17744
17745        Returns
17746        -------
17747        float
17748          the computed Shanon's entropy of a node given the observation
17749
17750        """
17751        return _pyAgrum.LoopyImportanceSampling_H(self, *args)
17752
17753    def BN(self) -> "pyAgrum.IBayesNet":
17754        r"""
17755
17756        Returns
17757        -------
17758        pyAgrum.IBayesNet
17759          A constant reference over the IBayesNet referenced by this class.
17760
17761        Raises
17762        ------
17763        pyAgrum.UndefinedElement
17764          If no Bayes net has been assigned to the inference.
17765
17766        """
17767        return _pyAgrum.LoopyImportanceSampling_BN(self)
17768
17769    def currentPosterior(self, *args) -> "pyAgrum.Potential":
17770        r"""
17771
17772        Computes and returns the current posterior of a node.
17773
17774        Parameters
17775        ----------
17776        var : int
17777          the node Id of the node for which we need a posterior probability
17778        nodeName : str
17779          the node name of the node for which we need a posterior probability
17780
17781        Returns
17782        -------
17783        pyAgrum.Potential
17784          a const ref to the current posterior probability of the node
17785
17786        Raises
17787        ------
17788        UndefinedElement
17789          If an element of nodes is not in targets
17790
17791        """
17792        return _pyAgrum.LoopyImportanceSampling_currentPosterior(self, *args)
17793
17794# Register LoopyImportanceSampling in _pyAgrum:
17795_pyAgrum.LoopyImportanceSampling_swigregister(LoopyImportanceSampling)
17796
17797class LoopyWeightedSampling(WeightedSampling):
17798    r"""
17799
17800    Class used for inferences using a loopy version of weighted sampling.
17801
17802    LoopyWeightedSampling(bn) -> LoopyWeightedSampling
17803        Parameters:
17804            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
17805
17806    """
17807
17808    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
17809    __repr__ = _swig_repr
17810
17811    def __init__(self, bn: "IBayesNet"):
17812        _pyAgrum.LoopyWeightedSampling_swiginit(self, _pyAgrum.new_LoopyWeightedSampling(bn))
17813
17814        self._model=bn#BN
17815
17816
17817
17818    __swig_destroy__ = _pyAgrum.delete_LoopyWeightedSampling
17819
17820    def makeInference_(self) -> None:
17821        return _pyAgrum.LoopyWeightedSampling_makeInference_(self)
17822
17823    def setVirtualLBPSize(self, vlbpsize: float) -> None:
17824        r"""
17825
17826        Parameters
17827        ----------
17828        vlbpsize : float
17829          the size of the virtual LBP
17830
17831        """
17832        return _pyAgrum.LoopyWeightedSampling_setVirtualLBPSize(self, vlbpsize)
17833
17834    def setEvidence(self, evidces):
17835        """
17836        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
17837
17838        Parameters
17839        ----------
17840        evidces : dict
17841          a dict of evidences
17842
17843        Raises
17844        ------
17845        gum.InvalidArgument
17846            If one value is not a value for the node
17847        gum.InvalidArgument
17848            If the size of a value is different from the domain side of the node
17849        gum.FatalError
17850            If one value is a vector of 0s
17851        gum.UndefinedElement
17852            If one node does not belong to the Bayesian network
17853        """
17854        if not isinstance(evidces, dict):
17855            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
17856        self.eraseAllEvidence()
17857        for k,v in evidces.items():
17858            self.addEvidence(k,v)
17859
17860
17861
17862    def updateEvidence(self, evidces):
17863        """
17864        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
17865
17866        Parameters
17867        ----------
17868        evidces : dict
17869          a dict of evidences
17870
17871        Raises
17872        ------
17873        gum.InvalidArgument
17874            If one value is not a value for the node
17875        gum.InvalidArgument
17876            If the size of a value is different from the domain side of the node
17877        gum.FatalError
17878            If one value is a vector of 0s
17879        gum.UndefinedElement
17880            If one node does not belong to the Bayesian network
17881        """
17882        if not isinstance(evidces, dict):
17883            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
17884
17885        for k,v in evidces.items():
17886            if self.hasEvidence(k):
17887                self.chgEvidence(k,v)
17888            else:
17889                self.addEvidence(k,v)
17890
17891
17892
17893    def setTargets(self, targets):
17894        """
17895        Remove all the targets and add the ones in parameter.
17896
17897        Parameters
17898        ----------
17899        targets : set
17900          a set of targets
17901
17902        Raises
17903        ------
17904        gum.UndefinedElement
17905            If one target is not in the Bayes net
17906        """
17907        if not isinstance(targets, set):
17908            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
17909
17910        self.eraseAllTargets()
17911        for k in targets:
17912            self.addTarget(k)
17913
17914
17915
17916    def hardEvidenceNodes(self) -> object:
17917        r"""
17918
17919        Returns
17920        -------
17921        set
17922          the set of nodes with hard evidence
17923
17924        """
17925        return _pyAgrum.LoopyWeightedSampling_hardEvidenceNodes(self)
17926
17927    def softEvidenceNodes(self) -> object:
17928        r"""
17929
17930        Returns
17931        -------
17932        set
17933          the set of nodes with soft evidence
17934
17935        """
17936        return _pyAgrum.LoopyWeightedSampling_softEvidenceNodes(self)
17937
17938    def targets(self) -> object:
17939        r"""
17940
17941        Returns
17942        -------
17943        list
17944          the list of marginal targets
17945
17946        """
17947        return _pyAgrum.LoopyWeightedSampling_targets(self)
17948
17949    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
17950        r"""
17951
17952        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
17953
17954        Parameters
17955        ----------
17956        target : set
17957          a set of targets ids or names.
17958        evs : set
17959          a set of nodes ids or names.
17960
17961        Warnings
17962        --------
17963        if some evs are d-separated, they are not included in the Potential.
17964
17965        Returns
17966        -------
17967        pyAgrum.Potential
17968          a Potential for P(targets|evs)
17969
17970        """
17971        return _pyAgrum.LoopyWeightedSampling_evidenceImpact(self, target, evs)
17972
17973    def setVerbosity(self, v: bool) -> None:
17974        r"""
17975
17976        Parameters
17977        ----------
17978        v : bool
17979                verbosity
17980
17981        """
17982        return _pyAgrum.LoopyWeightedSampling_setVerbosity(self, v)
17983
17984    def setEpsilon(self, eps: float) -> None:
17985        r"""
17986
17987        Parameters
17988        ----------
17989        eps : float
17990        	the epsilon we want to use
17991
17992        Raises
17993        ------
17994        pyAgrum.OutOfBounds
17995        	If eps<0
17996
17997        """
17998        return _pyAgrum.LoopyWeightedSampling_setEpsilon(self, eps)
17999
18000    def setMinEpsilonRate(self, rate: float) -> None:
18001        r"""
18002
18003        Parameters
18004        ----------
18005        rate : float
18006        	the minimal epsilon rate
18007
18008        """
18009        return _pyAgrum.LoopyWeightedSampling_setMinEpsilonRate(self, rate)
18010
18011    def setMaxIter(self, max: int) -> None:
18012        r"""
18013
18014        Parameters
18015        ----------
18016        max : int
18017        	the maximum number of iteration
18018
18019        Raises
18020        ------
18021        pyAgrum.OutOfBounds
18022        	If max <= 1
18023
18024        """
18025        return _pyAgrum.LoopyWeightedSampling_setMaxIter(self, max)
18026
18027    def setMaxTime(self, timeout: float) -> None:
18028        r"""
18029
18030        Parameters
18031        ----------
18032        tiemout : float
18033        	stopping criterion on timeout (in seconds)
18034
18035        Raises
18036        ------
18037        pyAgrum.OutOfBounds
18038        	If timeout<=0.0
18039
18040        """
18041        return _pyAgrum.LoopyWeightedSampling_setMaxTime(self, timeout)
18042
18043    def setPeriodSize(self, p: int) -> None:
18044        r"""
18045
18046        Parameters
18047        ----------
18048        p : int
18049        	number of samples between 2 stopping
18050
18051        Raises
18052        ------
18053        pyAgrum.OutOfBounds
18054        	If p<1
18055
18056        """
18057        return _pyAgrum.LoopyWeightedSampling_setPeriodSize(self, p)
18058
18059    def verbosity(self) -> bool:
18060        r"""
18061
18062        Returns
18063        -------
18064        bool
18065        	True if the verbosity is enabled
18066
18067        """
18068        return _pyAgrum.LoopyWeightedSampling_verbosity(self)
18069
18070    def epsilon(self) -> float:
18071        r"""
18072
18073        Returns
18074        -------
18075        float
18076        	the value of epsilon
18077
18078        """
18079        return _pyAgrum.LoopyWeightedSampling_epsilon(self)
18080
18081    def minEpsilonRate(self) -> float:
18082        r"""
18083
18084        Returns
18085        -------
18086        float
18087        	the value of the minimal epsilon rate
18088
18089        """
18090        return _pyAgrum.LoopyWeightedSampling_minEpsilonRate(self)
18091
18092    def maxIter(self) -> int:
18093        r"""
18094
18095        Returns
18096        -------
18097        int
18098        	the criterion on number of iterations
18099
18100        """
18101        return _pyAgrum.LoopyWeightedSampling_maxIter(self)
18102
18103    def maxTime(self) -> float:
18104        r"""
18105
18106        Returns
18107        -------
18108        float
18109        	the timeout(in seconds)
18110
18111        """
18112        return _pyAgrum.LoopyWeightedSampling_maxTime(self)
18113
18114    def periodSize(self) -> int:
18115        r"""
18116
18117        Returns
18118        -------
18119        int
18120        	the number of samples between 2 stopping
18121
18122        Raises
18123        ------
18124        pyAgrum.OutOfBounds
18125        	If p<1
18126
18127        """
18128        return _pyAgrum.LoopyWeightedSampling_periodSize(self)
18129
18130    def nbrIterations(self) -> int:
18131        r"""
18132
18133        Returns
18134        -------
18135        int
18136        	the number of iterations
18137
18138        """
18139        return _pyAgrum.LoopyWeightedSampling_nbrIterations(self)
18140
18141    def currentTime(self) -> float:
18142        r"""
18143
18144        Returns
18145        -------
18146        float
18147        	get the current running time in second (float)
18148
18149        """
18150        return _pyAgrum.LoopyWeightedSampling_currentTime(self)
18151
18152    def messageApproximationScheme(self) -> str:
18153        r"""
18154
18155        Returns
18156        -------
18157        str
18158        	the approximation scheme message
18159
18160        """
18161        return _pyAgrum.LoopyWeightedSampling_messageApproximationScheme(self)
18162
18163    def history(self) -> List[float]:
18164        r"""
18165
18166        Returns
18167        -------
18168        tuple
18169        	the scheme history
18170
18171        Raises
18172        ------
18173        pyAgrum.OperationNotAllowed
18174        	If the scheme did not performed or if verbosity is set to false
18175
18176        """
18177        return _pyAgrum.LoopyWeightedSampling_history(self)
18178
18179    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
18180        return _pyAgrum.LoopyWeightedSampling__asIApproximationSchemeConfiguration(self)
18181
18182    def makeInference(self) -> None:
18183        r"""
18184
18185        Perform the heavy computations needed to compute the targets' posteriors
18186
18187        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
18188        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
18189
18190        """
18191        return _pyAgrum.LoopyWeightedSampling_makeInference(self)
18192
18193    def posterior(self, *args) -> "pyAgrum.Potential":
18194        r"""
18195
18196        Computes and returns the posterior of a node.
18197
18198        Parameters
18199        ----------
18200        var : int
18201          the node Id of the node for which we need a posterior probability
18202        nodeName : str
18203          the node name of the node for which we need a posterior probability
18204
18205        Returns
18206        -------
18207        pyAgrum.Potential
18208          a const ref to the posterior probability of the node
18209
18210        Raises
18211        ------
18212        pyAgrum.UndefinedElement
18213          If an element of nodes is not in targets
18214
18215        """
18216        return _pyAgrum.LoopyWeightedSampling_posterior(self, *args)
18217
18218    def addEvidence(self, *args) -> None:
18219        r"""
18220
18221        Adds a new evidence on a node (might be soft or hard).
18222
18223        Parameters
18224        ----------
18225        id : int
18226          a node Id
18227        nodeName : int
18228          a node name
18229        val :
18230          (int) a node value
18231        val :
18232          (str) the label of the node value
18233        vals : list
18234          a list of values
18235
18236        Raises
18237        ------
18238        pyAgrum.InvalidArgument
18239          If the node already has an evidence
18240        pyAgrum.InvalidArgument
18241          If val is not a value for the node
18242        pyAgrum.InvalidArgument
18243          If the size of vals is different from the domain side of the node
18244        pyAgrum.FatalError
18245          If vals is a vector of 0s
18246        pyAgrum.UndefinedElement
18247          If the node does not belong to the Bayesian network
18248
18249        """
18250        return _pyAgrum.LoopyWeightedSampling_addEvidence(self, *args)
18251
18252    def chgEvidence(self, *args) -> None:
18253        r"""
18254
18255        Change the value of an already existing evidence on a node (might be soft or hard).
18256
18257        Parameters
18258        ----------
18259        id : int
18260          a node Id
18261        nodeName : int
18262          a node name
18263        val :
18264          (int) a node value
18265        val :
18266          (str) the label of the node value
18267        vals : list
18268          a list of values
18269
18270        Raises
18271        ------
18272        pyAgrum.InvalidArgument
18273          If the node does not already have an evidence
18274        pyAgrum.InvalidArgument
18275          If val is not a value for the node
18276        pyAgrum.InvalidArgument
18277          If the size of vals is different from the domain side of the node
18278        pyAgrum.FatalError
18279          If vals is a vector of 0s
18280        pyAgrum.UndefinedElement
18281          If the node does not belong to the Bayesian network
18282
18283        """
18284        return _pyAgrum.LoopyWeightedSampling_chgEvidence(self, *args)
18285
18286    def hasEvidence(self, *args) -> bool:
18287        r"""
18288
18289        Parameters
18290        ----------
18291        id : int
18292          a node Id
18293        nodeName : str
18294          a node name
18295
18296        Returns
18297        -------
18298        bool
18299          True if some node(s) (or the one in parameters) have received evidence
18300
18301        Raises
18302        ------
18303        pyAgrum.IndexError
18304          If the node does not belong to the Bayesian network
18305
18306        """
18307        return _pyAgrum.LoopyWeightedSampling_hasEvidence(self, *args)
18308
18309    def eraseAllEvidence(self) -> None:
18310        r"""
18311
18312        Removes all the evidence entered into the network.
18313
18314        """
18315        return _pyAgrum.LoopyWeightedSampling_eraseAllEvidence(self)
18316
18317    def eraseEvidence(self, *args) -> None:
18318        r"""
18319
18320        Remove the evidence, if any, corresponding to the node Id or name.
18321
18322        Parameters
18323        ----------
18324        id : int
18325          a node Id
18326        nodeName : int
18327          a node name
18328
18329        Raises
18330        ------
18331        pyAgrum.IndexError
18332          If the node does not belong to the Bayesian network
18333
18334        """
18335        return _pyAgrum.LoopyWeightedSampling_eraseEvidence(self, *args)
18336
18337    def hasHardEvidence(self, nodeName: str) -> bool:
18338        r"""
18339
18340        Parameters
18341        ----------
18342        id : int
18343          a node Id
18344        nodeName : str
18345          a node name
18346
18347        Returns
18348        -------
18349        bool
18350          True if node has received a hard evidence
18351
18352        Raises
18353        ------
18354        pyAgrum.IndexError
18355          If the node does not belong to the Bayesian network
18356
18357        """
18358        return _pyAgrum.LoopyWeightedSampling_hasHardEvidence(self, nodeName)
18359
18360    def hasSoftEvidence(self, *args) -> bool:
18361        r"""
18362
18363        Parameters
18364        ----------
18365        id : int
18366          a node Id
18367        nodeName : str
18368          a node name
18369
18370        Returns
18371        -------
18372        bool
18373          True if node has received a soft evidence
18374
18375        Raises
18376        ------
18377        pyAgrum.IndexError
18378          If the node does not belong to the Bayesian network
18379
18380        """
18381        return _pyAgrum.LoopyWeightedSampling_hasSoftEvidence(self, *args)
18382
18383    def nbrEvidence(self) -> int:
18384        r"""
18385
18386        Returns
18387        -------
18388        int
18389          the number of evidence entered into the Bayesian network
18390
18391        """
18392        return _pyAgrum.LoopyWeightedSampling_nbrEvidence(self)
18393
18394    def nbrHardEvidence(self) -> int:
18395        r"""
18396
18397        Returns
18398        -------
18399        int
18400          the number of hard evidence entered into the Bayesian network
18401
18402        """
18403        return _pyAgrum.LoopyWeightedSampling_nbrHardEvidence(self)
18404
18405    def nbrSoftEvidence(self) -> int:
18406        r"""
18407
18408        Returns
18409        -------
18410        int
18411          the number of soft evidence entered into the Bayesian network
18412
18413        """
18414        return _pyAgrum.LoopyWeightedSampling_nbrSoftEvidence(self)
18415
18416    def eraseAllTargets(self) -> None:
18417        r"""
18418
18419        Clear all previously defined targets (marginal and joint targets).
18420
18421        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
18422
18423        """
18424        return _pyAgrum.LoopyWeightedSampling_eraseAllTargets(self)
18425
18426    def addAllTargets(self) -> None:
18427        r"""
18428
18429        Add all the nodes as targets.
18430
18431        """
18432        return _pyAgrum.LoopyWeightedSampling_addAllTargets(self)
18433
18434    def addTarget(self, *args) -> None:
18435        r"""
18436
18437        Add a marginal target to the list of targets.
18438
18439        Parameters
18440        ----------
18441        target : int
18442          a node Id
18443        nodeName : str
18444          a node name
18445
18446        Raises
18447        ------
18448        pyAgrum.UndefinedElement
18449          If target is not a NodeId in the Bayes net
18450
18451        """
18452        return _pyAgrum.LoopyWeightedSampling_addTarget(self, *args)
18453
18454    def eraseTarget(self, *args) -> None:
18455        r"""
18456
18457        Remove, if existing, the marginal target.
18458
18459        Parameters
18460        ----------
18461        target : int
18462          a node Id
18463        nodeName : int
18464          a node name
18465
18466        Raises
18467        ------
18468        pyAgrum.IndexError
18469          If one of the node does not belong to the Bayesian network
18470        pyAgrum.UndefinedElement
18471          If node Id is not in the Bayesian network
18472
18473        """
18474        return _pyAgrum.LoopyWeightedSampling_eraseTarget(self, *args)
18475
18476    def isTarget(self, *args) -> bool:
18477        r"""
18478
18479        Parameters
18480        ----------
18481        variable : int
18482         a node Id
18483        nodeName : str
18484          a node name
18485
18486        Returns
18487        -------
18488        bool
18489          True if variable is a (marginal) target
18490
18491        Raises
18492        ------
18493        pyAgrum.IndexError
18494          If the node does not belong to the Bayesian network
18495        pyAgrum.UndefinedElement
18496          If node Id is not in the Bayesian network
18497
18498        """
18499        return _pyAgrum.LoopyWeightedSampling_isTarget(self, *args)
18500
18501    def nbrTargets(self) -> int:
18502        r"""
18503
18504        Returns
18505        -------
18506        int
18507          the number of marginal targets
18508
18509        """
18510        return _pyAgrum.LoopyWeightedSampling_nbrTargets(self)
18511
18512    def H(self, *args) -> float:
18513        r"""
18514
18515        Parameters
18516        ----------
18517        X : int
18518          a node Id
18519        nodeName : str
18520          a node name
18521
18522        Returns
18523        -------
18524        float
18525          the computed Shanon's entropy of a node given the observation
18526
18527        """
18528        return _pyAgrum.LoopyWeightedSampling_H(self, *args)
18529
18530    def BN(self) -> "pyAgrum.IBayesNet":
18531        r"""
18532
18533        Returns
18534        -------
18535        pyAgrum.IBayesNet
18536          A constant reference over the IBayesNet referenced by this class.
18537
18538        Raises
18539        ------
18540        pyAgrum.UndefinedElement
18541          If no Bayes net has been assigned to the inference.
18542
18543        """
18544        return _pyAgrum.LoopyWeightedSampling_BN(self)
18545
18546    def currentPosterior(self, *args) -> "pyAgrum.Potential":
18547        r"""
18548
18549        Computes and returns the current posterior of a node.
18550
18551        Parameters
18552        ----------
18553        var : int
18554          the node Id of the node for which we need a posterior probability
18555        nodeName : str
18556          the node name of the node for which we need a posterior probability
18557
18558        Returns
18559        -------
18560        pyAgrum.Potential
18561          a const ref to the current posterior probability of the node
18562
18563        Raises
18564        ------
18565        UndefinedElement
18566          If an element of nodes is not in targets
18567
18568        """
18569        return _pyAgrum.LoopyWeightedSampling_currentPosterior(self, *args)
18570
18571# Register LoopyWeightedSampling in _pyAgrum:
18572_pyAgrum.LoopyWeightedSampling_swigregister(LoopyWeightedSampling)
18573
18574class LoopyGibbsSampling(GibbsSampling):
18575    r"""
18576
18577    Class used for inferences using a loopy version of Gibbs sampling.
18578
18579    LoopyGibbsSampling(bn) -> LoopyGibbsSampling
18580        Parameters:
18581            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
18582
18583    """
18584
18585    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
18586    __repr__ = _swig_repr
18587
18588    def __init__(self, bn: "IBayesNet"):
18589        _pyAgrum.LoopyGibbsSampling_swiginit(self, _pyAgrum.new_LoopyGibbsSampling(bn))
18590
18591        self._model=bn#BN
18592
18593
18594
18595    __swig_destroy__ = _pyAgrum.delete_LoopyGibbsSampling
18596
18597    def makeInference_(self) -> None:
18598        return _pyAgrum.LoopyGibbsSampling_makeInference_(self)
18599
18600    def setVirtualLBPSize(self, vlbpsize: float) -> None:
18601        r"""
18602
18603        Parameters
18604        ----------
18605        vlbpsize : float
18606          the size of the virtual LBP
18607
18608        """
18609        return _pyAgrum.LoopyGibbsSampling_setVirtualLBPSize(self, vlbpsize)
18610
18611    def setEvidence(self, evidces):
18612        """
18613        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
18614
18615        Parameters
18616        ----------
18617        evidces : dict
18618          a dict of evidences
18619
18620        Raises
18621        ------
18622        gum.InvalidArgument
18623            If one value is not a value for the node
18624        gum.InvalidArgument
18625            If the size of a value is different from the domain side of the node
18626        gum.FatalError
18627            If one value is a vector of 0s
18628        gum.UndefinedElement
18629            If one node does not belong to the Bayesian network
18630        """
18631        if not isinstance(evidces, dict):
18632            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
18633        self.eraseAllEvidence()
18634        for k,v in evidces.items():
18635            self.addEvidence(k,v)
18636
18637
18638
18639    def updateEvidence(self, evidces):
18640        """
18641        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
18642
18643        Parameters
18644        ----------
18645        evidces : dict
18646          a dict of evidences
18647
18648        Raises
18649        ------
18650        gum.InvalidArgument
18651            If one value is not a value for the node
18652        gum.InvalidArgument
18653            If the size of a value is different from the domain side of the node
18654        gum.FatalError
18655            If one value is a vector of 0s
18656        gum.UndefinedElement
18657            If one node does not belong to the Bayesian network
18658        """
18659        if not isinstance(evidces, dict):
18660            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
18661
18662        for k,v in evidces.items():
18663            if self.hasEvidence(k):
18664                self.chgEvidence(k,v)
18665            else:
18666                self.addEvidence(k,v)
18667
18668
18669
18670    def setTargets(self, targets):
18671        """
18672        Remove all the targets and add the ones in parameter.
18673
18674        Parameters
18675        ----------
18676        targets : set
18677          a set of targets
18678
18679        Raises
18680        ------
18681        gum.UndefinedElement
18682            If one target is not in the Bayes net
18683        """
18684        if not isinstance(targets, set):
18685            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
18686
18687        self.eraseAllTargets()
18688        for k in targets:
18689            self.addTarget(k)
18690
18691
18692
18693    def hardEvidenceNodes(self) -> object:
18694        r"""
18695
18696        Returns
18697        -------
18698        set
18699          the set of nodes with hard evidence
18700
18701        """
18702        return _pyAgrum.LoopyGibbsSampling_hardEvidenceNodes(self)
18703
18704    def softEvidenceNodes(self) -> object:
18705        r"""
18706
18707        Returns
18708        -------
18709        set
18710          the set of nodes with soft evidence
18711
18712        """
18713        return _pyAgrum.LoopyGibbsSampling_softEvidenceNodes(self)
18714
18715    def targets(self) -> object:
18716        r"""
18717
18718        Returns
18719        -------
18720        list
18721          the list of marginal targets
18722
18723        """
18724        return _pyAgrum.LoopyGibbsSampling_targets(self)
18725
18726    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
18727        r"""
18728
18729        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
18730
18731        Parameters
18732        ----------
18733        target : set
18734          a set of targets ids or names.
18735        evs : set
18736          a set of nodes ids or names.
18737
18738        Warnings
18739        --------
18740        if some evs are d-separated, they are not included in the Potential.
18741
18742        Returns
18743        -------
18744        pyAgrum.Potential
18745          a Potential for P(targets|evs)
18746
18747        """
18748        return _pyAgrum.LoopyGibbsSampling_evidenceImpact(self, target, evs)
18749
18750    def setVerbosity(self, v: bool) -> None:
18751        r"""
18752
18753        Parameters
18754        ----------
18755        v : bool
18756                verbosity
18757
18758        """
18759        return _pyAgrum.LoopyGibbsSampling_setVerbosity(self, v)
18760
18761    def setEpsilon(self, eps: float) -> None:
18762        r"""
18763
18764        Parameters
18765        ----------
18766        eps : float
18767        	the epsilon we want to use
18768
18769        Raises
18770        ------
18771        pyAgrum.OutOfBounds
18772        	If eps<0
18773
18774        """
18775        return _pyAgrum.LoopyGibbsSampling_setEpsilon(self, eps)
18776
18777    def setMinEpsilonRate(self, rate: float) -> None:
18778        r"""
18779
18780        Parameters
18781        ----------
18782        rate : float
18783        	the minimal epsilon rate
18784
18785        """
18786        return _pyAgrum.LoopyGibbsSampling_setMinEpsilonRate(self, rate)
18787
18788    def setMaxIter(self, max: int) -> None:
18789        r"""
18790
18791        Parameters
18792        ----------
18793        max : int
18794        	the maximum number of iteration
18795
18796        Raises
18797        ------
18798        pyAgrum.OutOfBounds
18799        	If max <= 1
18800
18801        """
18802        return _pyAgrum.LoopyGibbsSampling_setMaxIter(self, max)
18803
18804    def setMaxTime(self, timeout: float) -> None:
18805        r"""
18806
18807        Parameters
18808        ----------
18809        tiemout : float
18810        	stopping criterion on timeout (in seconds)
18811
18812        Raises
18813        ------
18814        pyAgrum.OutOfBounds
18815        	If timeout<=0.0
18816
18817        """
18818        return _pyAgrum.LoopyGibbsSampling_setMaxTime(self, timeout)
18819
18820    def setPeriodSize(self, p: int) -> None:
18821        r"""
18822
18823        Parameters
18824        ----------
18825        p : int
18826        	number of samples between 2 stopping
18827
18828        Raises
18829        ------
18830        pyAgrum.OutOfBounds
18831        	If p<1
18832
18833        """
18834        return _pyAgrum.LoopyGibbsSampling_setPeriodSize(self, p)
18835
18836    def verbosity(self) -> bool:
18837        r"""
18838
18839        Returns
18840        -------
18841        bool
18842        	True if the verbosity is enabled
18843
18844        """
18845        return _pyAgrum.LoopyGibbsSampling_verbosity(self)
18846
18847    def epsilon(self) -> float:
18848        r"""
18849
18850        Returns
18851        -------
18852        float
18853        	the value of epsilon
18854
18855        """
18856        return _pyAgrum.LoopyGibbsSampling_epsilon(self)
18857
18858    def minEpsilonRate(self) -> float:
18859        r"""
18860
18861        Returns
18862        -------
18863        float
18864        	the value of the minimal epsilon rate
18865
18866        """
18867        return _pyAgrum.LoopyGibbsSampling_minEpsilonRate(self)
18868
18869    def maxIter(self) -> int:
18870        r"""
18871
18872        Returns
18873        -------
18874        int
18875        	the criterion on number of iterations
18876
18877        """
18878        return _pyAgrum.LoopyGibbsSampling_maxIter(self)
18879
18880    def maxTime(self) -> float:
18881        r"""
18882
18883        Returns
18884        -------
18885        float
18886        	the timeout(in seconds)
18887
18888        """
18889        return _pyAgrum.LoopyGibbsSampling_maxTime(self)
18890
18891    def periodSize(self) -> int:
18892        r"""
18893
18894        Returns
18895        -------
18896        int
18897        	the number of samples between 2 stopping
18898
18899        Raises
18900        ------
18901        pyAgrum.OutOfBounds
18902        	If p<1
18903
18904        """
18905        return _pyAgrum.LoopyGibbsSampling_periodSize(self)
18906
18907    def nbrIterations(self) -> int:
18908        r"""
18909
18910        Returns
18911        -------
18912        int
18913        	the number of iterations
18914
18915        """
18916        return _pyAgrum.LoopyGibbsSampling_nbrIterations(self)
18917
18918    def currentTime(self) -> float:
18919        r"""
18920
18921        Returns
18922        -------
18923        float
18924        	get the current running time in second (float)
18925
18926        """
18927        return _pyAgrum.LoopyGibbsSampling_currentTime(self)
18928
18929    def messageApproximationScheme(self) -> str:
18930        r"""
18931
18932        Returns
18933        -------
18934        str
18935        	the approximation scheme message
18936
18937        """
18938        return _pyAgrum.LoopyGibbsSampling_messageApproximationScheme(self)
18939
18940    def history(self) -> List[float]:
18941        r"""
18942
18943        Returns
18944        -------
18945        tuple
18946        	the scheme history
18947
18948        Raises
18949        ------
18950        pyAgrum.OperationNotAllowed
18951        	If the scheme did not performed or if verbosity is set to false
18952
18953        """
18954        return _pyAgrum.LoopyGibbsSampling_history(self)
18955
18956    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
18957        return _pyAgrum.LoopyGibbsSampling__asIApproximationSchemeConfiguration(self)
18958
18959    def makeInference(self) -> None:
18960        r"""
18961
18962        Perform the heavy computations needed to compute the targets' posteriors
18963
18964        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
18965        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
18966
18967        """
18968        return _pyAgrum.LoopyGibbsSampling_makeInference(self)
18969
18970    def posterior(self, *args) -> "pyAgrum.Potential":
18971        r"""
18972
18973        Computes and returns the posterior of a node.
18974
18975        Parameters
18976        ----------
18977        var : int
18978          the node Id of the node for which we need a posterior probability
18979        nodeName : str
18980          the node name of the node for which we need a posterior probability
18981
18982        Returns
18983        -------
18984        pyAgrum.Potential
18985          a const ref to the posterior probability of the node
18986
18987        Raises
18988        ------
18989        pyAgrum.UndefinedElement
18990          If an element of nodes is not in targets
18991
18992        """
18993        return _pyAgrum.LoopyGibbsSampling_posterior(self, *args)
18994
18995    def addEvidence(self, *args) -> None:
18996        r"""
18997
18998        Adds a new evidence on a node (might be soft or hard).
18999
19000        Parameters
19001        ----------
19002        id : int
19003          a node Id
19004        nodeName : int
19005          a node name
19006        val :
19007          (int) a node value
19008        val :
19009          (str) the label of the node value
19010        vals : list
19011          a list of values
19012
19013        Raises
19014        ------
19015        pyAgrum.InvalidArgument
19016          If the node already has an evidence
19017        pyAgrum.InvalidArgument
19018          If val is not a value for the node
19019        pyAgrum.InvalidArgument
19020          If the size of vals is different from the domain side of the node
19021        pyAgrum.FatalError
19022          If vals is a vector of 0s
19023        pyAgrum.UndefinedElement
19024          If the node does not belong to the Bayesian network
19025
19026        """
19027        return _pyAgrum.LoopyGibbsSampling_addEvidence(self, *args)
19028
19029    def chgEvidence(self, *args) -> None:
19030        r"""
19031
19032        Change the value of an already existing evidence on a node (might be soft or hard).
19033
19034        Parameters
19035        ----------
19036        id : int
19037          a node Id
19038        nodeName : int
19039          a node name
19040        val :
19041          (int) a node value
19042        val :
19043          (str) the label of the node value
19044        vals : list
19045          a list of values
19046
19047        Raises
19048        ------
19049        pyAgrum.InvalidArgument
19050          If the node does not already have an evidence
19051        pyAgrum.InvalidArgument
19052          If val is not a value for the node
19053        pyAgrum.InvalidArgument
19054          If the size of vals is different from the domain side of the node
19055        pyAgrum.FatalError
19056          If vals is a vector of 0s
19057        pyAgrum.UndefinedElement
19058          If the node does not belong to the Bayesian network
19059
19060        """
19061        return _pyAgrum.LoopyGibbsSampling_chgEvidence(self, *args)
19062
19063    def hasEvidence(self, *args) -> bool:
19064        r"""
19065
19066        Parameters
19067        ----------
19068        id : int
19069          a node Id
19070        nodeName : str
19071          a node name
19072
19073        Returns
19074        -------
19075        bool
19076          True if some node(s) (or the one in parameters) have received evidence
19077
19078        Raises
19079        ------
19080        pyAgrum.IndexError
19081          If the node does not belong to the Bayesian network
19082
19083        """
19084        return _pyAgrum.LoopyGibbsSampling_hasEvidence(self, *args)
19085
19086    def eraseAllEvidence(self) -> None:
19087        r"""
19088
19089        Removes all the evidence entered into the network.
19090
19091        """
19092        return _pyAgrum.LoopyGibbsSampling_eraseAllEvidence(self)
19093
19094    def eraseEvidence(self, *args) -> None:
19095        r"""
19096
19097        Remove the evidence, if any, corresponding to the node Id or name.
19098
19099        Parameters
19100        ----------
19101        id : int
19102          a node Id
19103        nodeName : int
19104          a node name
19105
19106        Raises
19107        ------
19108        pyAgrum.IndexError
19109          If the node does not belong to the Bayesian network
19110
19111        """
19112        return _pyAgrum.LoopyGibbsSampling_eraseEvidence(self, *args)
19113
19114    def hasHardEvidence(self, nodeName: str) -> bool:
19115        r"""
19116
19117        Parameters
19118        ----------
19119        id : int
19120          a node Id
19121        nodeName : str
19122          a node name
19123
19124        Returns
19125        -------
19126        bool
19127          True if node has received a hard evidence
19128
19129        Raises
19130        ------
19131        pyAgrum.IndexError
19132          If the node does not belong to the Bayesian network
19133
19134        """
19135        return _pyAgrum.LoopyGibbsSampling_hasHardEvidence(self, nodeName)
19136
19137    def hasSoftEvidence(self, *args) -> bool:
19138        r"""
19139
19140        Parameters
19141        ----------
19142        id : int
19143          a node Id
19144        nodeName : str
19145          a node name
19146
19147        Returns
19148        -------
19149        bool
19150          True if node has received a soft evidence
19151
19152        Raises
19153        ------
19154        pyAgrum.IndexError
19155          If the node does not belong to the Bayesian network
19156
19157        """
19158        return _pyAgrum.LoopyGibbsSampling_hasSoftEvidence(self, *args)
19159
19160    def nbrEvidence(self) -> int:
19161        r"""
19162
19163        Returns
19164        -------
19165        int
19166          the number of evidence entered into the Bayesian network
19167
19168        """
19169        return _pyAgrum.LoopyGibbsSampling_nbrEvidence(self)
19170
19171    def nbrHardEvidence(self) -> int:
19172        r"""
19173
19174        Returns
19175        -------
19176        int
19177          the number of hard evidence entered into the Bayesian network
19178
19179        """
19180        return _pyAgrum.LoopyGibbsSampling_nbrHardEvidence(self)
19181
19182    def nbrSoftEvidence(self) -> int:
19183        r"""
19184
19185        Returns
19186        -------
19187        int
19188          the number of soft evidence entered into the Bayesian network
19189
19190        """
19191        return _pyAgrum.LoopyGibbsSampling_nbrSoftEvidence(self)
19192
19193    def eraseAllTargets(self) -> None:
19194        r"""
19195
19196        Clear all previously defined targets (marginal and joint targets).
19197
19198        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
19199
19200        """
19201        return _pyAgrum.LoopyGibbsSampling_eraseAllTargets(self)
19202
19203    def addAllTargets(self) -> None:
19204        r"""
19205
19206        Add all the nodes as targets.
19207
19208        """
19209        return _pyAgrum.LoopyGibbsSampling_addAllTargets(self)
19210
19211    def addTarget(self, *args) -> None:
19212        r"""
19213
19214        Add a marginal target to the list of targets.
19215
19216        Parameters
19217        ----------
19218        target : int
19219          a node Id
19220        nodeName : str
19221          a node name
19222
19223        Raises
19224        ------
19225        pyAgrum.UndefinedElement
19226          If target is not a NodeId in the Bayes net
19227
19228        """
19229        return _pyAgrum.LoopyGibbsSampling_addTarget(self, *args)
19230
19231    def eraseTarget(self, *args) -> None:
19232        r"""
19233
19234        Remove, if existing, the marginal target.
19235
19236        Parameters
19237        ----------
19238        target : int
19239          a node Id
19240        nodeName : int
19241          a node name
19242
19243        Raises
19244        ------
19245        pyAgrum.IndexError
19246          If one of the node does not belong to the Bayesian network
19247        pyAgrum.UndefinedElement
19248          If node Id is not in the Bayesian network
19249
19250        """
19251        return _pyAgrum.LoopyGibbsSampling_eraseTarget(self, *args)
19252
19253    def isTarget(self, *args) -> bool:
19254        r"""
19255
19256        Parameters
19257        ----------
19258        variable : int
19259         a node Id
19260        nodeName : str
19261          a node name
19262
19263        Returns
19264        -------
19265        bool
19266          True if variable is a (marginal) target
19267
19268        Raises
19269        ------
19270        pyAgrum.IndexError
19271          If the node does not belong to the Bayesian network
19272        pyAgrum.UndefinedElement
19273          If node Id is not in the Bayesian network
19274
19275        """
19276        return _pyAgrum.LoopyGibbsSampling_isTarget(self, *args)
19277
19278    def nbrTargets(self) -> int:
19279        r"""
19280
19281        Returns
19282        -------
19283        int
19284          the number of marginal targets
19285
19286        """
19287        return _pyAgrum.LoopyGibbsSampling_nbrTargets(self)
19288
19289    def H(self, *args) -> float:
19290        r"""
19291
19292        Parameters
19293        ----------
19294        X : int
19295          a node Id
19296        nodeName : str
19297          a node name
19298
19299        Returns
19300        -------
19301        float
19302          the computed Shanon's entropy of a node given the observation
19303
19304        """
19305        return _pyAgrum.LoopyGibbsSampling_H(self, *args)
19306
19307    def BN(self) -> "pyAgrum.IBayesNet":
19308        r"""
19309
19310        Returns
19311        -------
19312        pyAgrum.IBayesNet
19313          A constant reference over the IBayesNet referenced by this class.
19314
19315        Raises
19316        ------
19317        pyAgrum.UndefinedElement
19318          If no Bayes net has been assigned to the inference.
19319
19320        """
19321        return _pyAgrum.LoopyGibbsSampling_BN(self)
19322
19323    def currentPosterior(self, *args) -> "pyAgrum.Potential":
19324        r"""
19325
19326        Computes and returns the current posterior of a node.
19327
19328        Parameters
19329        ----------
19330        var : int
19331          the node Id of the node for which we need a posterior probability
19332        nodeName : str
19333          the node name of the node for which we need a posterior probability
19334
19335        Returns
19336        -------
19337        pyAgrum.Potential
19338          a const ref to the current posterior probability of the node
19339
19340        Raises
19341        ------
19342        UndefinedElement
19343          If an element of nodes is not in targets
19344
19345        """
19346        return _pyAgrum.LoopyGibbsSampling_currentPosterior(self, *args)
19347
19348    def nbrDrawnVar(self) -> int:
19349        r"""
19350
19351        Returns
19352        -------
19353        int
19354          the number of variable drawn at each iteration
19355
19356        """
19357        return _pyAgrum.LoopyGibbsSampling_nbrDrawnVar(self)
19358
19359    def setNbrDrawnVar(self, _nbr: int) -> None:
19360        r"""
19361
19362        Parameters
19363        ----------
19364        _nbr : int
19365          the number of variables to be drawn at each iteration
19366
19367        """
19368        return _pyAgrum.LoopyGibbsSampling_setNbrDrawnVar(self, _nbr)
19369
19370    def isDrawnAtRandom(self) -> bool:
19371        r"""
19372
19373        Returns
19374        -------
19375        bool
19376          True if variables are drawn at random
19377
19378        """
19379        return _pyAgrum.LoopyGibbsSampling_isDrawnAtRandom(self)
19380
19381    def setDrawnAtRandom(self, _atRandom: bool) -> None:
19382        r"""
19383
19384        Parameters
19385        ----------
19386        _atRandom : bool
19387          indicates if variables should be drawn at random
19388
19389        """
19390        return _pyAgrum.LoopyGibbsSampling_setDrawnAtRandom(self, _atRandom)
19391
19392    def burnIn(self) -> int:
19393        r"""
19394
19395        Returns
19396        -------
19397        int
19398          size of burn in on number of iteration
19399
19400        """
19401        return _pyAgrum.LoopyGibbsSampling_burnIn(self)
19402
19403    def setBurnIn(self, b: int) -> None:
19404        r"""
19405
19406        Parameters
19407        ----------
19408        b : int
19409          size of burn in on number of iteration
19410
19411        """
19412        return _pyAgrum.LoopyGibbsSampling_setBurnIn(self, b)
19413
19414# Register LoopyGibbsSampling in _pyAgrum:
19415_pyAgrum.LoopyGibbsSampling_swigregister(LoopyGibbsSampling)
19416
19417class LoopyMonteCarloSampling(MonteCarloSampling):
19418    r"""
19419
19420    Class used for inferences using a loopy version of Monte Carlo sampling.
19421
19422    LoopyMonteCarloSampling(bn) -> LoopyMonteCarloSampling
19423        Parameters:
19424            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
19425
19426    """
19427
19428    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
19429    __repr__ = _swig_repr
19430
19431    def __init__(self, bn: "IBayesNet"):
19432        _pyAgrum.LoopyMonteCarloSampling_swiginit(self, _pyAgrum.new_LoopyMonteCarloSampling(bn))
19433
19434        self._model=bn#BN
19435
19436
19437
19438    __swig_destroy__ = _pyAgrum.delete_LoopyMonteCarloSampling
19439
19440    def makeInference_(self) -> None:
19441        return _pyAgrum.LoopyMonteCarloSampling_makeInference_(self)
19442
19443    def setVirtualLBPSize(self, vlbpsize: float) -> None:
19444        r"""
19445
19446        Parameters
19447        ----------
19448        vlbpsize : float
19449          the size of the virtual LBP
19450
19451        """
19452        return _pyAgrum.LoopyMonteCarloSampling_setVirtualLBPSize(self, vlbpsize)
19453
19454    def setEvidence(self, evidces):
19455        """
19456        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
19457
19458        Parameters
19459        ----------
19460        evidces : dict
19461          a dict of evidences
19462
19463        Raises
19464        ------
19465        gum.InvalidArgument
19466            If one value is not a value for the node
19467        gum.InvalidArgument
19468            If the size of a value is different from the domain side of the node
19469        gum.FatalError
19470            If one value is a vector of 0s
19471        gum.UndefinedElement
19472            If one node does not belong to the Bayesian network
19473        """
19474        if not isinstance(evidces, dict):
19475            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
19476        self.eraseAllEvidence()
19477        for k,v in evidces.items():
19478            self.addEvidence(k,v)
19479
19480
19481
19482    def updateEvidence(self, evidces):
19483        """
19484        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
19485
19486        Parameters
19487        ----------
19488        evidces : dict
19489          a dict of evidences
19490
19491        Raises
19492        ------
19493        gum.InvalidArgument
19494            If one value is not a value for the node
19495        gum.InvalidArgument
19496            If the size of a value is different from the domain side of the node
19497        gum.FatalError
19498            If one value is a vector of 0s
19499        gum.UndefinedElement
19500            If one node does not belong to the Bayesian network
19501        """
19502        if not isinstance(evidces, dict):
19503            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
19504
19505        for k,v in evidces.items():
19506            if self.hasEvidence(k):
19507                self.chgEvidence(k,v)
19508            else:
19509                self.addEvidence(k,v)
19510
19511
19512
19513    def setTargets(self, targets):
19514        """
19515        Remove all the targets and add the ones in parameter.
19516
19517        Parameters
19518        ----------
19519        targets : set
19520          a set of targets
19521
19522        Raises
19523        ------
19524        gum.UndefinedElement
19525            If one target is not in the Bayes net
19526        """
19527        if not isinstance(targets, set):
19528            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
19529
19530        self.eraseAllTargets()
19531        for k in targets:
19532            self.addTarget(k)
19533
19534
19535
19536    def hardEvidenceNodes(self) -> object:
19537        r"""
19538
19539        Returns
19540        -------
19541        set
19542          the set of nodes with hard evidence
19543
19544        """
19545        return _pyAgrum.LoopyMonteCarloSampling_hardEvidenceNodes(self)
19546
19547    def softEvidenceNodes(self) -> object:
19548        r"""
19549
19550        Returns
19551        -------
19552        set
19553          the set of nodes with soft evidence
19554
19555        """
19556        return _pyAgrum.LoopyMonteCarloSampling_softEvidenceNodes(self)
19557
19558    def targets(self) -> object:
19559        r"""
19560
19561        Returns
19562        -------
19563        list
19564          the list of marginal targets
19565
19566        """
19567        return _pyAgrum.LoopyMonteCarloSampling_targets(self)
19568
19569    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
19570        r"""
19571
19572        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
19573
19574        Parameters
19575        ----------
19576        target : set
19577          a set of targets ids or names.
19578        evs : set
19579          a set of nodes ids or names.
19580
19581        Warnings
19582        --------
19583        if some evs are d-separated, they are not included in the Potential.
19584
19585        Returns
19586        -------
19587        pyAgrum.Potential
19588          a Potential for P(targets|evs)
19589
19590        """
19591        return _pyAgrum.LoopyMonteCarloSampling_evidenceImpact(self, target, evs)
19592
19593    def setVerbosity(self, v: bool) -> None:
19594        r"""
19595
19596        Parameters
19597        ----------
19598        v : bool
19599                verbosity
19600
19601        """
19602        return _pyAgrum.LoopyMonteCarloSampling_setVerbosity(self, v)
19603
19604    def setEpsilon(self, eps: float) -> None:
19605        r"""
19606
19607        Parameters
19608        ----------
19609        eps : float
19610        	the epsilon we want to use
19611
19612        Raises
19613        ------
19614        pyAgrum.OutOfBounds
19615        	If eps<0
19616
19617        """
19618        return _pyAgrum.LoopyMonteCarloSampling_setEpsilon(self, eps)
19619
19620    def setMinEpsilonRate(self, rate: float) -> None:
19621        r"""
19622
19623        Parameters
19624        ----------
19625        rate : float
19626        	the minimal epsilon rate
19627
19628        """
19629        return _pyAgrum.LoopyMonteCarloSampling_setMinEpsilonRate(self, rate)
19630
19631    def setMaxIter(self, max: int) -> None:
19632        r"""
19633
19634        Parameters
19635        ----------
19636        max : int
19637        	the maximum number of iteration
19638
19639        Raises
19640        ------
19641        pyAgrum.OutOfBounds
19642        	If max <= 1
19643
19644        """
19645        return _pyAgrum.LoopyMonteCarloSampling_setMaxIter(self, max)
19646
19647    def setMaxTime(self, timeout: float) -> None:
19648        r"""
19649
19650        Parameters
19651        ----------
19652        tiemout : float
19653        	stopping criterion on timeout (in seconds)
19654
19655        Raises
19656        ------
19657        pyAgrum.OutOfBounds
19658        	If timeout<=0.0
19659
19660        """
19661        return _pyAgrum.LoopyMonteCarloSampling_setMaxTime(self, timeout)
19662
19663    def setPeriodSize(self, p: int) -> None:
19664        r"""
19665
19666        Parameters
19667        ----------
19668        p : int
19669        	number of samples between 2 stopping
19670
19671        Raises
19672        ------
19673        pyAgrum.OutOfBounds
19674        	If p<1
19675
19676        """
19677        return _pyAgrum.LoopyMonteCarloSampling_setPeriodSize(self, p)
19678
19679    def verbosity(self) -> bool:
19680        r"""
19681
19682        Returns
19683        -------
19684        bool
19685        	True if the verbosity is enabled
19686
19687        """
19688        return _pyAgrum.LoopyMonteCarloSampling_verbosity(self)
19689
19690    def epsilon(self) -> float:
19691        r"""
19692
19693        Returns
19694        -------
19695        float
19696        	the value of epsilon
19697
19698        """
19699        return _pyAgrum.LoopyMonteCarloSampling_epsilon(self)
19700
19701    def minEpsilonRate(self) -> float:
19702        r"""
19703
19704        Returns
19705        -------
19706        float
19707        	the value of the minimal epsilon rate
19708
19709        """
19710        return _pyAgrum.LoopyMonteCarloSampling_minEpsilonRate(self)
19711
19712    def maxIter(self) -> int:
19713        r"""
19714
19715        Returns
19716        -------
19717        int
19718        	the criterion on number of iterations
19719
19720        """
19721        return _pyAgrum.LoopyMonteCarloSampling_maxIter(self)
19722
19723    def maxTime(self) -> float:
19724        r"""
19725
19726        Returns
19727        -------
19728        float
19729        	the timeout(in seconds)
19730
19731        """
19732        return _pyAgrum.LoopyMonteCarloSampling_maxTime(self)
19733
19734    def periodSize(self) -> int:
19735        r"""
19736
19737        Returns
19738        -------
19739        int
19740        	the number of samples between 2 stopping
19741
19742        Raises
19743        ------
19744        pyAgrum.OutOfBounds
19745        	If p<1
19746
19747        """
19748        return _pyAgrum.LoopyMonteCarloSampling_periodSize(self)
19749
19750    def nbrIterations(self) -> int:
19751        r"""
19752
19753        Returns
19754        -------
19755        int
19756        	the number of iterations
19757
19758        """
19759        return _pyAgrum.LoopyMonteCarloSampling_nbrIterations(self)
19760
19761    def currentTime(self) -> float:
19762        r"""
19763
19764        Returns
19765        -------
19766        float
19767        	get the current running time in second (float)
19768
19769        """
19770        return _pyAgrum.LoopyMonteCarloSampling_currentTime(self)
19771
19772    def messageApproximationScheme(self) -> str:
19773        r"""
19774
19775        Returns
19776        -------
19777        str
19778        	the approximation scheme message
19779
19780        """
19781        return _pyAgrum.LoopyMonteCarloSampling_messageApproximationScheme(self)
19782
19783    def history(self) -> List[float]:
19784        r"""
19785
19786        Returns
19787        -------
19788        tuple
19789        	the scheme history
19790
19791        Raises
19792        ------
19793        pyAgrum.OperationNotAllowed
19794        	If the scheme did not performed or if verbosity is set to false
19795
19796        """
19797        return _pyAgrum.LoopyMonteCarloSampling_history(self)
19798
19799    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
19800        return _pyAgrum.LoopyMonteCarloSampling__asIApproximationSchemeConfiguration(self)
19801
19802    def makeInference(self) -> None:
19803        r"""
19804
19805        Perform the heavy computations needed to compute the targets' posteriors
19806
19807        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
19808        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
19809
19810        """
19811        return _pyAgrum.LoopyMonteCarloSampling_makeInference(self)
19812
19813    def posterior(self, *args) -> "pyAgrum.Potential":
19814        r"""
19815
19816        Computes and returns the posterior of a node.
19817
19818        Parameters
19819        ----------
19820        var : int
19821          the node Id of the node for which we need a posterior probability
19822        nodeName : str
19823          the node name of the node for which we need a posterior probability
19824
19825        Returns
19826        -------
19827        pyAgrum.Potential
19828          a const ref to the posterior probability of the node
19829
19830        Raises
19831        ------
19832        pyAgrum.UndefinedElement
19833          If an element of nodes is not in targets
19834
19835        """
19836        return _pyAgrum.LoopyMonteCarloSampling_posterior(self, *args)
19837
19838    def addEvidence(self, *args) -> None:
19839        r"""
19840
19841        Adds a new evidence on a node (might be soft or hard).
19842
19843        Parameters
19844        ----------
19845        id : int
19846          a node Id
19847        nodeName : int
19848          a node name
19849        val :
19850          (int) a node value
19851        val :
19852          (str) the label of the node value
19853        vals : list
19854          a list of values
19855
19856        Raises
19857        ------
19858        pyAgrum.InvalidArgument
19859          If the node already has an evidence
19860        pyAgrum.InvalidArgument
19861          If val is not a value for the node
19862        pyAgrum.InvalidArgument
19863          If the size of vals is different from the domain side of the node
19864        pyAgrum.FatalError
19865          If vals is a vector of 0s
19866        pyAgrum.UndefinedElement
19867          If the node does not belong to the Bayesian network
19868
19869        """
19870        return _pyAgrum.LoopyMonteCarloSampling_addEvidence(self, *args)
19871
19872    def chgEvidence(self, *args) -> None:
19873        r"""
19874
19875        Change the value of an already existing evidence on a node (might be soft or hard).
19876
19877        Parameters
19878        ----------
19879        id : int
19880          a node Id
19881        nodeName : int
19882          a node name
19883        val :
19884          (int) a node value
19885        val :
19886          (str) the label of the node value
19887        vals : list
19888          a list of values
19889
19890        Raises
19891        ------
19892        pyAgrum.InvalidArgument
19893          If the node does not already have an evidence
19894        pyAgrum.InvalidArgument
19895          If val is not a value for the node
19896        pyAgrum.InvalidArgument
19897          If the size of vals is different from the domain side of the node
19898        pyAgrum.FatalError
19899          If vals is a vector of 0s
19900        pyAgrum.UndefinedElement
19901          If the node does not belong to the Bayesian network
19902
19903        """
19904        return _pyAgrum.LoopyMonteCarloSampling_chgEvidence(self, *args)
19905
19906    def hasEvidence(self, *args) -> bool:
19907        r"""
19908
19909        Parameters
19910        ----------
19911        id : int
19912          a node Id
19913        nodeName : str
19914          a node name
19915
19916        Returns
19917        -------
19918        bool
19919          True if some node(s) (or the one in parameters) have received evidence
19920
19921        Raises
19922        ------
19923        pyAgrum.IndexError
19924          If the node does not belong to the Bayesian network
19925
19926        """
19927        return _pyAgrum.LoopyMonteCarloSampling_hasEvidence(self, *args)
19928
19929    def eraseAllEvidence(self) -> None:
19930        r"""
19931
19932        Removes all the evidence entered into the network.
19933
19934        """
19935        return _pyAgrum.LoopyMonteCarloSampling_eraseAllEvidence(self)
19936
19937    def eraseEvidence(self, *args) -> None:
19938        r"""
19939
19940        Remove the evidence, if any, corresponding to the node Id or name.
19941
19942        Parameters
19943        ----------
19944        id : int
19945          a node Id
19946        nodeName : int
19947          a node name
19948
19949        Raises
19950        ------
19951        pyAgrum.IndexError
19952          If the node does not belong to the Bayesian network
19953
19954        """
19955        return _pyAgrum.LoopyMonteCarloSampling_eraseEvidence(self, *args)
19956
19957    def hasHardEvidence(self, nodeName: str) -> bool:
19958        r"""
19959
19960        Parameters
19961        ----------
19962        id : int
19963          a node Id
19964        nodeName : str
19965          a node name
19966
19967        Returns
19968        -------
19969        bool
19970          True if node has received a hard evidence
19971
19972        Raises
19973        ------
19974        pyAgrum.IndexError
19975          If the node does not belong to the Bayesian network
19976
19977        """
19978        return _pyAgrum.LoopyMonteCarloSampling_hasHardEvidence(self, nodeName)
19979
19980    def hasSoftEvidence(self, *args) -> bool:
19981        r"""
19982
19983        Parameters
19984        ----------
19985        id : int
19986          a node Id
19987        nodeName : str
19988          a node name
19989
19990        Returns
19991        -------
19992        bool
19993          True if node has received a soft evidence
19994
19995        Raises
19996        ------
19997        pyAgrum.IndexError
19998          If the node does not belong to the Bayesian network
19999
20000        """
20001        return _pyAgrum.LoopyMonteCarloSampling_hasSoftEvidence(self, *args)
20002
20003    def nbrEvidence(self) -> int:
20004        r"""
20005
20006        Returns
20007        -------
20008        int
20009          the number of evidence entered into the Bayesian network
20010
20011        """
20012        return _pyAgrum.LoopyMonteCarloSampling_nbrEvidence(self)
20013
20014    def nbrHardEvidence(self) -> int:
20015        r"""
20016
20017        Returns
20018        -------
20019        int
20020          the number of hard evidence entered into the Bayesian network
20021
20022        """
20023        return _pyAgrum.LoopyMonteCarloSampling_nbrHardEvidence(self)
20024
20025    def nbrSoftEvidence(self) -> int:
20026        r"""
20027
20028        Returns
20029        -------
20030        int
20031          the number of soft evidence entered into the Bayesian network
20032
20033        """
20034        return _pyAgrum.LoopyMonteCarloSampling_nbrSoftEvidence(self)
20035
20036    def eraseAllTargets(self) -> None:
20037        r"""
20038
20039        Clear all previously defined targets (marginal and joint targets).
20040
20041        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
20042
20043        """
20044        return _pyAgrum.LoopyMonteCarloSampling_eraseAllTargets(self)
20045
20046    def addAllTargets(self) -> None:
20047        r"""
20048
20049        Add all the nodes as targets.
20050
20051        """
20052        return _pyAgrum.LoopyMonteCarloSampling_addAllTargets(self)
20053
20054    def addTarget(self, *args) -> None:
20055        r"""
20056
20057        Add a marginal target to the list of targets.
20058
20059        Parameters
20060        ----------
20061        target : int
20062          a node Id
20063        nodeName : str
20064          a node name
20065
20066        Raises
20067        ------
20068        pyAgrum.UndefinedElement
20069          If target is not a NodeId in the Bayes net
20070
20071        """
20072        return _pyAgrum.LoopyMonteCarloSampling_addTarget(self, *args)
20073
20074    def eraseTarget(self, *args) -> None:
20075        r"""
20076
20077        Remove, if existing, the marginal target.
20078
20079        Parameters
20080        ----------
20081        target : int
20082          a node Id
20083        nodeName : int
20084          a node name
20085
20086        Raises
20087        ------
20088        pyAgrum.IndexError
20089          If one of the node does not belong to the Bayesian network
20090        pyAgrum.UndefinedElement
20091          If node Id is not in the Bayesian network
20092
20093        """
20094        return _pyAgrum.LoopyMonteCarloSampling_eraseTarget(self, *args)
20095
20096    def isTarget(self, *args) -> bool:
20097        r"""
20098
20099        Parameters
20100        ----------
20101        variable : int
20102         a node Id
20103        nodeName : str
20104          a node name
20105
20106        Returns
20107        -------
20108        bool
20109          True if variable is a (marginal) target
20110
20111        Raises
20112        ------
20113        pyAgrum.IndexError
20114          If the node does not belong to the Bayesian network
20115        pyAgrum.UndefinedElement
20116          If node Id is not in the Bayesian network
20117
20118        """
20119        return _pyAgrum.LoopyMonteCarloSampling_isTarget(self, *args)
20120
20121    def nbrTargets(self) -> int:
20122        r"""
20123
20124        Returns
20125        -------
20126        int
20127          the number of marginal targets
20128
20129        """
20130        return _pyAgrum.LoopyMonteCarloSampling_nbrTargets(self)
20131
20132    def H(self, *args) -> float:
20133        r"""
20134
20135        Parameters
20136        ----------
20137        X : int
20138          a node Id
20139        nodeName : str
20140          a node name
20141
20142        Returns
20143        -------
20144        float
20145          the computed Shanon's entropy of a node given the observation
20146
20147        """
20148        return _pyAgrum.LoopyMonteCarloSampling_H(self, *args)
20149
20150    def BN(self) -> "pyAgrum.IBayesNet":
20151        r"""
20152
20153        Returns
20154        -------
20155        pyAgrum.IBayesNet
20156          A constant reference over the IBayesNet referenced by this class.
20157
20158        Raises
20159        ------
20160        pyAgrum.UndefinedElement
20161          If no Bayes net has been assigned to the inference.
20162
20163        """
20164        return _pyAgrum.LoopyMonteCarloSampling_BN(self)
20165
20166    def currentPosterior(self, *args) -> "pyAgrum.Potential":
20167        r"""
20168
20169        Computes and returns the current posterior of a node.
20170
20171        Parameters
20172        ----------
20173        var : int
20174          the node Id of the node for which we need a posterior probability
20175        nodeName : str
20176          the node name of the node for which we need a posterior probability
20177
20178        Returns
20179        -------
20180        pyAgrum.Potential
20181          a const ref to the current posterior probability of the node
20182
20183        Raises
20184        ------
20185        UndefinedElement
20186          If an element of nodes is not in targets
20187
20188        """
20189        return _pyAgrum.LoopyMonteCarloSampling_currentPosterior(self, *args)
20190
20191# Register LoopyMonteCarloSampling in _pyAgrum:
20192_pyAgrum.LoopyMonteCarloSampling_swigregister(LoopyMonteCarloSampling)
20193
20194class LoopyBeliefPropagation(object):
20195    r"""
20196
20197    Class used for inferences using loopy belief propagation algorithm.
20198
20199    LoopyBeliefPropagation(bn) -> LoopyBeliefPropagation
20200        Parameters:
20201            * **bn** (*pyAgrum.BayesNet*) -- a Bayesian network
20202
20203    """
20204
20205    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
20206    __repr__ = _swig_repr
20207
20208    def __init__(self, bn: "IBayesNet"):
20209        _pyAgrum.LoopyBeliefPropagation_swiginit(self, _pyAgrum.new_LoopyBeliefPropagation(bn))
20210
20211        self._model=bn#BN
20212
20213
20214
20215    __swig_destroy__ = _pyAgrum.delete_LoopyBeliefPropagation
20216
20217    def setEvidence(self, evidces):
20218        """
20219        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
20220
20221        Parameters
20222        ----------
20223        evidces : dict
20224          a dict of evidences
20225
20226        Raises
20227        ------
20228        gum.InvalidArgument
20229            If one value is not a value for the node
20230        gum.InvalidArgument
20231            If the size of a value is different from the domain side of the node
20232        gum.FatalError
20233            If one value is a vector of 0s
20234        gum.UndefinedElement
20235            If one node does not belong to the Bayesian network
20236        """
20237        if not isinstance(evidces, dict):
20238            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
20239        self.eraseAllEvidence()
20240        for k,v in evidces.items():
20241            self.addEvidence(k,v)
20242
20243
20244
20245    def updateEvidence(self, evidces):
20246        """
20247        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
20248
20249        Parameters
20250        ----------
20251        evidces : dict
20252          a dict of evidences
20253
20254        Raises
20255        ------
20256        gum.InvalidArgument
20257            If one value is not a value for the node
20258        gum.InvalidArgument
20259            If the size of a value is different from the domain side of the node
20260        gum.FatalError
20261            If one value is a vector of 0s
20262        gum.UndefinedElement
20263            If one node does not belong to the Bayesian network
20264        """
20265        if not isinstance(evidces, dict):
20266            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
20267
20268        for k,v in evidces.items():
20269            if self.hasEvidence(k):
20270                self.chgEvidence(k,v)
20271            else:
20272                self.addEvidence(k,v)
20273
20274
20275
20276    def setTargets(self, targets):
20277        """
20278        Remove all the targets and add the ones in parameter.
20279
20280        Parameters
20281        ----------
20282        targets : set
20283          a set of targets
20284
20285        Raises
20286        ------
20287        gum.UndefinedElement
20288            If one target is not in the Bayes net
20289        """
20290        if not isinstance(targets, set):
20291            raise TypeError("setTargets parameter must be a set, not %s"%(type(targets)))
20292
20293        self.eraseAllTargets()
20294        for k in targets:
20295            self.addTarget(k)
20296
20297
20298
20299    def hardEvidenceNodes(self) -> object:
20300        r"""
20301
20302        Returns
20303        -------
20304        set
20305          the set of nodes with hard evidence
20306
20307        """
20308        return _pyAgrum.LoopyBeliefPropagation_hardEvidenceNodes(self)
20309
20310    def softEvidenceNodes(self) -> object:
20311        r"""
20312
20313        Returns
20314        -------
20315        set
20316          the set of nodes with soft evidence
20317
20318        """
20319        return _pyAgrum.LoopyBeliefPropagation_softEvidenceNodes(self)
20320
20321    def targets(self) -> object:
20322        r"""
20323
20324        Returns
20325        -------
20326        list
20327          the list of marginal targets
20328
20329        """
20330        return _pyAgrum.LoopyBeliefPropagation_targets(self)
20331
20332    def evidenceImpact(self, target: object, evs: object) -> "pyAgrum.Potential":
20333        r"""
20334
20335        Create a pyAgrum.Potential for P(target|evs) (for all instanciation of target and evs)
20336
20337        Parameters
20338        ----------
20339        target : set
20340          a set of targets ids or names.
20341        evs : set
20342          a set of nodes ids or names.
20343
20344        Warnings
20345        --------
20346        if some evs are d-separated, they are not included in the Potential.
20347
20348        Returns
20349        -------
20350        pyAgrum.Potential
20351          a Potential for P(targets|evs)
20352
20353        """
20354        return _pyAgrum.LoopyBeliefPropagation_evidenceImpact(self, target, evs)
20355
20356    def setVerbosity(self, v: bool) -> None:
20357        r"""
20358
20359        Parameters
20360        ----------
20361        v : bool
20362                verbosity
20363
20364        """
20365        return _pyAgrum.LoopyBeliefPropagation_setVerbosity(self, v)
20366
20367    def setEpsilon(self, eps: float) -> None:
20368        r"""
20369
20370        Parameters
20371        ----------
20372        eps : float
20373        	the epsilon we want to use
20374
20375        Raises
20376        ------
20377        pyAgrum.OutOfBounds
20378        	If eps<0
20379
20380        """
20381        return _pyAgrum.LoopyBeliefPropagation_setEpsilon(self, eps)
20382
20383    def setMinEpsilonRate(self, rate: float) -> None:
20384        r"""
20385
20386        Parameters
20387        ----------
20388        rate : float
20389        	the minimal epsilon rate
20390
20391        """
20392        return _pyAgrum.LoopyBeliefPropagation_setMinEpsilonRate(self, rate)
20393
20394    def setMaxIter(self, max: int) -> None:
20395        r"""
20396
20397        Parameters
20398        ----------
20399        max : int
20400        	the maximum number of iteration
20401
20402        Raises
20403        ------
20404        pyAgrum.OutOfBounds
20405        	If max <= 1
20406
20407        """
20408        return _pyAgrum.LoopyBeliefPropagation_setMaxIter(self, max)
20409
20410    def setMaxTime(self, timeout: float) -> None:
20411        r"""
20412
20413        Parameters
20414        ----------
20415        tiemout : float
20416        	stopping criterion on timeout (in seconds)
20417
20418        Raises
20419        ------
20420        pyAgrum.OutOfBounds
20421        	If timeout<=0.0
20422
20423        """
20424        return _pyAgrum.LoopyBeliefPropagation_setMaxTime(self, timeout)
20425
20426    def setPeriodSize(self, p: int) -> None:
20427        r"""
20428
20429        Parameters
20430        ----------
20431        p : int
20432        	number of samples between 2 stopping
20433
20434        Raises
20435        ------
20436        pyAgrum.OutOfBounds
20437        	If p<1
20438
20439        """
20440        return _pyAgrum.LoopyBeliefPropagation_setPeriodSize(self, p)
20441
20442    def verbosity(self) -> bool:
20443        r"""
20444
20445        Returns
20446        -------
20447        bool
20448        	True if the verbosity is enabled
20449
20450        """
20451        return _pyAgrum.LoopyBeliefPropagation_verbosity(self)
20452
20453    def epsilon(self) -> float:
20454        r"""
20455
20456        Returns
20457        -------
20458        float
20459        	the value of epsilon
20460
20461        """
20462        return _pyAgrum.LoopyBeliefPropagation_epsilon(self)
20463
20464    def minEpsilonRate(self) -> float:
20465        r"""
20466
20467        Returns
20468        -------
20469        float
20470        	the value of the minimal epsilon rate
20471
20472        """
20473        return _pyAgrum.LoopyBeliefPropagation_minEpsilonRate(self)
20474
20475    def maxIter(self) -> int:
20476        r"""
20477
20478        Returns
20479        -------
20480        int
20481        	the criterion on number of iterations
20482
20483        """
20484        return _pyAgrum.LoopyBeliefPropagation_maxIter(self)
20485
20486    def maxTime(self) -> float:
20487        r"""
20488
20489        Returns
20490        -------
20491        float
20492        	the timeout(in seconds)
20493
20494        """
20495        return _pyAgrum.LoopyBeliefPropagation_maxTime(self)
20496
20497    def periodSize(self) -> int:
20498        r"""
20499
20500        Returns
20501        -------
20502        int
20503        	the number of samples between 2 stopping
20504
20505        Raises
20506        ------
20507        pyAgrum.OutOfBounds
20508        	If p<1
20509
20510        """
20511        return _pyAgrum.LoopyBeliefPropagation_periodSize(self)
20512
20513    def nbrIterations(self) -> int:
20514        r"""
20515
20516        Returns
20517        -------
20518        int
20519        	the number of iterations
20520
20521        """
20522        return _pyAgrum.LoopyBeliefPropagation_nbrIterations(self)
20523
20524    def currentTime(self) -> float:
20525        r"""
20526
20527        Returns
20528        -------
20529        float
20530        	get the current running time in second (float)
20531
20532        """
20533        return _pyAgrum.LoopyBeliefPropagation_currentTime(self)
20534
20535    def messageApproximationScheme(self) -> str:
20536        r"""
20537
20538        Returns
20539        -------
20540        str
20541        	the approximation scheme message
20542
20543        """
20544        return _pyAgrum.LoopyBeliefPropagation_messageApproximationScheme(self)
20545
20546    def history(self) -> List[float]:
20547        r"""
20548
20549        Returns
20550        -------
20551        tuple
20552        	the scheme history
20553
20554        Raises
20555        ------
20556        pyAgrum.OperationNotAllowed
20557        	If the scheme did not performed or if verbosity is set to false
20558
20559        """
20560        return _pyAgrum.LoopyBeliefPropagation_history(self)
20561
20562    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
20563        return _pyAgrum.LoopyBeliefPropagation__asIApproximationSchemeConfiguration(self)
20564
20565    def makeInference(self) -> None:
20566        r"""
20567
20568        Perform the heavy computations needed to compute the targets' posteriors
20569
20570        In a Junction tree propagation scheme, for instance, the heavy computations are those of the messages sent in the JT.
20571        This is precisely what makeInference should compute. Later, the computations of the posteriors can be done 'lightly' by multiplying and projecting those messages.
20572
20573        """
20574        return _pyAgrum.LoopyBeliefPropagation_makeInference(self)
20575
20576    def posterior(self, *args) -> "pyAgrum.Potential":
20577        r"""
20578
20579        Computes and returns the posterior of a node.
20580
20581        Parameters
20582        ----------
20583        var : int
20584          the node Id of the node for which we need a posterior probability
20585        nodeName : str
20586          the node name of the node for which we need a posterior probability
20587
20588        Returns
20589        -------
20590        pyAgrum.Potential
20591          a const ref to the posterior probability of the node
20592
20593        Raises
20594        ------
20595        pyAgrum.UndefinedElement
20596          If an element of nodes is not in targets
20597
20598        """
20599        return _pyAgrum.LoopyBeliefPropagation_posterior(self, *args)
20600
20601    def addEvidence(self, *args) -> None:
20602        r"""
20603
20604        Adds a new evidence on a node (might be soft or hard).
20605
20606        Parameters
20607        ----------
20608        id : int
20609          a node Id
20610        nodeName : int
20611          a node name
20612        val :
20613          (int) a node value
20614        val :
20615          (str) the label of the node value
20616        vals : list
20617          a list of values
20618
20619        Raises
20620        ------
20621        pyAgrum.InvalidArgument
20622          If the node already has an evidence
20623        pyAgrum.InvalidArgument
20624          If val is not a value for the node
20625        pyAgrum.InvalidArgument
20626          If the size of vals is different from the domain side of the node
20627        pyAgrum.FatalError
20628          If vals is a vector of 0s
20629        pyAgrum.UndefinedElement
20630          If the node does not belong to the Bayesian network
20631
20632        """
20633        return _pyAgrum.LoopyBeliefPropagation_addEvidence(self, *args)
20634
20635    def chgEvidence(self, *args) -> None:
20636        r"""
20637
20638        Change the value of an already existing evidence on a node (might be soft or hard).
20639
20640        Parameters
20641        ----------
20642        id : int
20643          a node Id
20644        nodeName : int
20645          a node name
20646        val :
20647          (int) a node value
20648        val :
20649          (str) the label of the node value
20650        vals : list
20651          a list of values
20652
20653        Raises
20654        ------
20655        pyAgrum.InvalidArgument
20656          If the node does not already have an evidence
20657        pyAgrum.InvalidArgument
20658          If val is not a value for the node
20659        pyAgrum.InvalidArgument
20660          If the size of vals is different from the domain side of the node
20661        pyAgrum.FatalError
20662          If vals is a vector of 0s
20663        pyAgrum.UndefinedElement
20664          If the node does not belong to the Bayesian network
20665
20666        """
20667        return _pyAgrum.LoopyBeliefPropagation_chgEvidence(self, *args)
20668
20669    def hasEvidence(self, *args) -> bool:
20670        r"""
20671
20672        Parameters
20673        ----------
20674        id : int
20675          a node Id
20676        nodeName : str
20677          a node name
20678
20679        Returns
20680        -------
20681        bool
20682          True if some node(s) (or the one in parameters) have received evidence
20683
20684        Raises
20685        ------
20686        pyAgrum.IndexError
20687          If the node does not belong to the Bayesian network
20688
20689        """
20690        return _pyAgrum.LoopyBeliefPropagation_hasEvidence(self, *args)
20691
20692    def eraseAllEvidence(self) -> None:
20693        r"""
20694
20695        Removes all the evidence entered into the network.
20696
20697        """
20698        return _pyAgrum.LoopyBeliefPropagation_eraseAllEvidence(self)
20699
20700    def eraseEvidence(self, *args) -> None:
20701        r"""
20702
20703        Remove the evidence, if any, corresponding to the node Id or name.
20704
20705        Parameters
20706        ----------
20707        id : int
20708          a node Id
20709        nodeName : int
20710          a node name
20711
20712        Raises
20713        ------
20714        pyAgrum.IndexError
20715          If the node does not belong to the Bayesian network
20716
20717        """
20718        return _pyAgrum.LoopyBeliefPropagation_eraseEvidence(self, *args)
20719
20720    def hasHardEvidence(self, nodeName: str) -> bool:
20721        r"""
20722
20723        Parameters
20724        ----------
20725        id : int
20726          a node Id
20727        nodeName : str
20728          a node name
20729
20730        Returns
20731        -------
20732        bool
20733          True if node has received a hard evidence
20734
20735        Raises
20736        ------
20737        pyAgrum.IndexError
20738          If the node does not belong to the Bayesian network
20739
20740        """
20741        return _pyAgrum.LoopyBeliefPropagation_hasHardEvidence(self, nodeName)
20742
20743    def hasSoftEvidence(self, *args) -> bool:
20744        r"""
20745
20746        Parameters
20747        ----------
20748        id : int
20749          a node Id
20750        nodeName : str
20751          a node name
20752
20753        Returns
20754        -------
20755        bool
20756          True if node has received a soft evidence
20757
20758        Raises
20759        ------
20760        pyAgrum.IndexError
20761          If the node does not belong to the Bayesian network
20762
20763        """
20764        return _pyAgrum.LoopyBeliefPropagation_hasSoftEvidence(self, *args)
20765
20766    def nbrEvidence(self) -> int:
20767        r"""
20768
20769        Returns
20770        -------
20771        int
20772          the number of evidence entered into the Bayesian network
20773
20774        """
20775        return _pyAgrum.LoopyBeliefPropagation_nbrEvidence(self)
20776
20777    def nbrHardEvidence(self) -> int:
20778        r"""
20779
20780        Returns
20781        -------
20782        int
20783          the number of hard evidence entered into the Bayesian network
20784
20785        """
20786        return _pyAgrum.LoopyBeliefPropagation_nbrHardEvidence(self)
20787
20788    def nbrSoftEvidence(self) -> int:
20789        r"""
20790
20791        Returns
20792        -------
20793        int
20794          the number of soft evidence entered into the Bayesian network
20795
20796        """
20797        return _pyAgrum.LoopyBeliefPropagation_nbrSoftEvidence(self)
20798
20799    def eraseAllTargets(self) -> None:
20800        r"""
20801
20802        Clear all previously defined targets (marginal and joint targets).
20803
20804        As a result, no posterior can be computed (since we can only compute the posteriors of the marginal or joint targets that have been added by the user).
20805
20806        """
20807        return _pyAgrum.LoopyBeliefPropagation_eraseAllTargets(self)
20808
20809    def addAllTargets(self) -> None:
20810        r"""
20811
20812        Add all the nodes as targets.
20813
20814        """
20815        return _pyAgrum.LoopyBeliefPropagation_addAllTargets(self)
20816
20817    def addTarget(self, *args) -> None:
20818        r"""
20819
20820        Add a marginal target to the list of targets.
20821
20822        Parameters
20823        ----------
20824        target : int
20825          a node Id
20826        nodeName : str
20827          a node name
20828
20829        Raises
20830        ------
20831        pyAgrum.UndefinedElement
20832          If target is not a NodeId in the Bayes net
20833
20834        """
20835        return _pyAgrum.LoopyBeliefPropagation_addTarget(self, *args)
20836
20837    def eraseTarget(self, *args) -> None:
20838        r"""
20839
20840        Remove, if existing, the marginal target.
20841
20842        Parameters
20843        ----------
20844        target : int
20845          a node Id
20846        nodeName : int
20847          a node name
20848
20849        Raises
20850        ------
20851        pyAgrum.IndexError
20852          If one of the node does not belong to the Bayesian network
20853        pyAgrum.UndefinedElement
20854          If node Id is not in the Bayesian network
20855
20856        """
20857        return _pyAgrum.LoopyBeliefPropagation_eraseTarget(self, *args)
20858
20859    def isTarget(self, *args) -> bool:
20860        r"""
20861
20862        Parameters
20863        ----------
20864        variable : int
20865         a node Id
20866        nodeName : str
20867          a node name
20868
20869        Returns
20870        -------
20871        bool
20872          True if variable is a (marginal) target
20873
20874        Raises
20875        ------
20876        pyAgrum.IndexError
20877          If the node does not belong to the Bayesian network
20878        pyAgrum.UndefinedElement
20879          If node Id is not in the Bayesian network
20880
20881        """
20882        return _pyAgrum.LoopyBeliefPropagation_isTarget(self, *args)
20883
20884    def nbrTargets(self) -> int:
20885        r"""
20886
20887        Returns
20888        -------
20889        int
20890          the number of marginal targets
20891
20892        """
20893        return _pyAgrum.LoopyBeliefPropagation_nbrTargets(self)
20894
20895    def H(self, *args) -> float:
20896        r"""
20897
20898        Parameters
20899        ----------
20900        X : int
20901          a node Id
20902        nodeName : str
20903          a node name
20904
20905        Returns
20906        -------
20907        float
20908          the computed Shanon's entropy of a node given the observation
20909
20910        """
20911        return _pyAgrum.LoopyBeliefPropagation_H(self, *args)
20912
20913    def BN(self) -> "pyAgrum.IBayesNet":
20914        r"""
20915
20916        Returns
20917        -------
20918        pyAgrum.IBayesNet
20919          A constant reference over the IBayesNet referenced by this class.
20920
20921        Raises
20922        ------
20923        pyAgrum.UndefinedElement
20924          If no Bayes net has been assigned to the inference.
20925
20926        """
20927        return _pyAgrum.LoopyBeliefPropagation_BN(self)
20928
20929# Register LoopyBeliefPropagation in _pyAgrum:
20930_pyAgrum.LoopyBeliefPropagation_swigregister(LoopyBeliefPropagation)
20931
20932class ExactBNdistance(object):
20933    r"""
20934
20935    Class representing exacte computation of divergence and distance between BNs
20936
20937    ExactBNdistance(P,Q) -> ExactBNdistance
20938        Parameters:
20939            * **P** (*pyAgrum.BayesNet*)
20940              a Bayesian network
20941            * **Q** (*pyAgrum.BayesNet*)
20942              another Bayesian network to compare with the first one
20943
20944    ExactBNdistance(ebnd) -> ExactBNdistance
20945        Parameters:
20946            * **ebnd** (*pyAgrum.ExactBNdistance*)
20947              the exact BNdistance to copy
20948
20949    Raises
20950    ------
20951    pyAgrum.OperationNotAllowed
20952    	If the 2BNs have not the same domain size of compatible node sets
20953
20954    """
20955
20956    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
20957    __repr__ = _swig_repr
20958
20959    def __init__(self, *args):
20960        _pyAgrum.ExactBNdistance_swiginit(self, _pyAgrum.new_ExactBNdistance(*args))
20961    __swig_destroy__ = _pyAgrum.delete_ExactBNdistance
20962
20963    def compute(self) -> object:
20964        r"""
20965
20966        Returns
20967        -------
20968        Dict[str,float]
20969        	a dictionnary containing the different values after the computation.
20970
20971        """
20972        return _pyAgrum.ExactBNdistance_compute(self)
20973
20974# Register ExactBNdistance in _pyAgrum:
20975_pyAgrum.ExactBNdistance_swigregister(ExactBNdistance)
20976
20977class GibbsBNdistance(ApproximationScheme):
20978    r"""
20979
20980    Class representing a Gibbs-Approximated computation of divergence and distance between BNs
20981
20982
20983    GibbsBNdistance(P,Q) -> GibbsBNdistance
20984        Parameters:
20985            * **P** (*pyAgrum.BayesNet*) -- a Bayesian network
20986            * **Q** (*pyAgrum.BayesNet*) -- another Bayesian network to compare with the first one
20987
20988    GibbsBNdistance(gbnd) -> GibbsBNdistance
20989        Parameters:
20990            * **gbnd** (*pyAgrum.GibbsBNdistance*) -- the Gibbs BNdistance to copy
20991
20992    Raises
20993    ------
20994    pyAgrum.OperationNotAllowed
20995    	If the 2BNs have not the same domain size of compatible node sets
20996
20997    """
20998
20999    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
21000    __repr__ = _swig_repr
21001
21002    def __init__(self, *args):
21003        _pyAgrum.GibbsBNdistance_swiginit(self, _pyAgrum.new_GibbsBNdistance(*args))
21004    __swig_destroy__ = _pyAgrum.delete_GibbsBNdistance
21005
21006    def setBurnIn(self, b: int) -> None:
21007        r"""
21008
21009        Parameters
21010        ----------
21011        b : int
21012        	size of burn in on number of iteration
21013
21014        """
21015        return _pyAgrum.GibbsBNdistance_setBurnIn(self, b)
21016
21017    def burnIn(self) -> int:
21018        r"""
21019
21020        Returns
21021        -------
21022        int
21023        	size of burn in on number of iteration
21024
21025        """
21026        return _pyAgrum.GibbsBNdistance_burnIn(self)
21027
21028    def compute(self) -> object:
21029        r"""
21030
21031        Returns
21032        -------
21033        Dict[str,float]
21034        	a dictionnary containing the different values after the computation.
21035
21036        """
21037        return _pyAgrum.GibbsBNdistance_compute(self)
21038
21039    def setVerbosity(self, v: bool) -> None:
21040        r"""
21041
21042        Parameters
21043        ----------
21044        v : bool
21045                verbosity
21046
21047        """
21048        return _pyAgrum.GibbsBNdistance_setVerbosity(self, v)
21049
21050    def setEpsilon(self, eps: float) -> None:
21051        r"""
21052
21053        Parameters
21054        ----------
21055        eps : float
21056        	the epsilon we want to use
21057
21058        Raises
21059        ------
21060        pyAgrum.OutOfBounds
21061        	If eps<0
21062
21063        """
21064        return _pyAgrum.GibbsBNdistance_setEpsilon(self, eps)
21065
21066    def setMinEpsilonRate(self, rate: float) -> None:
21067        r"""
21068
21069        Parameters
21070        ----------
21071        rate : float
21072        	the minimal epsilon rate
21073
21074        """
21075        return _pyAgrum.GibbsBNdistance_setMinEpsilonRate(self, rate)
21076
21077    def setMaxIter(self, max: int) -> None:
21078        r"""
21079
21080        Parameters
21081        ----------
21082        max : int
21083        	the maximum number of iteration
21084
21085        Raises
21086        ------
21087        pyAgrum.OutOfBounds
21088        	If max <= 1
21089
21090        """
21091        return _pyAgrum.GibbsBNdistance_setMaxIter(self, max)
21092
21093    def setMaxTime(self, timeout: float) -> None:
21094        r"""
21095
21096        Parameters
21097        ----------
21098        tiemout : float
21099        	stopping criterion on timeout (in seconds)
21100
21101        Raises
21102        ------
21103        pyAgrum.OutOfBounds
21104        	If timeout<=0.0
21105
21106        """
21107        return _pyAgrum.GibbsBNdistance_setMaxTime(self, timeout)
21108
21109    def setPeriodSize(self, p: int) -> None:
21110        r"""
21111
21112        Parameters
21113        ----------
21114        p : int
21115        	number of samples between 2 stopping
21116
21117        Raises
21118        ------
21119        pyAgrum.OutOfBounds
21120        	If p<1
21121
21122        """
21123        return _pyAgrum.GibbsBNdistance_setPeriodSize(self, p)
21124
21125    def verbosity(self) -> bool:
21126        r"""
21127
21128        Returns
21129        -------
21130        bool
21131        	True if the verbosity is enabled
21132
21133        """
21134        return _pyAgrum.GibbsBNdistance_verbosity(self)
21135
21136    def epsilon(self) -> float:
21137        r"""
21138
21139        Returns
21140        -------
21141        float
21142        	the value of epsilon
21143
21144        """
21145        return _pyAgrum.GibbsBNdistance_epsilon(self)
21146
21147    def minEpsilonRate(self) -> float:
21148        r"""
21149
21150        Returns
21151        -------
21152        float
21153        	the value of the minimal epsilon rate
21154
21155        """
21156        return _pyAgrum.GibbsBNdistance_minEpsilonRate(self)
21157
21158    def maxIter(self) -> int:
21159        r"""
21160
21161        Returns
21162        -------
21163        int
21164        	the criterion on number of iterations
21165
21166        """
21167        return _pyAgrum.GibbsBNdistance_maxIter(self)
21168
21169    def maxTime(self) -> float:
21170        r"""
21171
21172        Returns
21173        -------
21174        float
21175        	the timeout(in seconds)
21176
21177        """
21178        return _pyAgrum.GibbsBNdistance_maxTime(self)
21179
21180    def periodSize(self) -> int:
21181        r"""
21182
21183        Returns
21184        -------
21185        int
21186        	the number of samples between 2 stopping
21187
21188        Raises
21189        ------
21190        pyAgrum.OutOfBounds
21191        	If p<1
21192
21193        """
21194        return _pyAgrum.GibbsBNdistance_periodSize(self)
21195
21196    def nbrIterations(self) -> int:
21197        r"""
21198
21199        Returns
21200        -------
21201        int
21202        	the number of iterations
21203
21204        """
21205        return _pyAgrum.GibbsBNdistance_nbrIterations(self)
21206
21207    def currentTime(self) -> float:
21208        r"""
21209
21210        Returns
21211        -------
21212        float
21213        	get the current running time in second (float)
21214
21215        """
21216        return _pyAgrum.GibbsBNdistance_currentTime(self)
21217
21218    def messageApproximationScheme(self) -> str:
21219        r"""
21220
21221        Returns
21222        -------
21223        str
21224        	the approximation scheme message
21225
21226        """
21227        return _pyAgrum.GibbsBNdistance_messageApproximationScheme(self)
21228
21229    def history(self) -> List[float]:
21230        r"""
21231
21232        Returns
21233        -------
21234        tuple
21235        	the scheme history
21236
21237        Raises
21238        ------
21239        pyAgrum.OperationNotAllowed
21240        	If the scheme did not performed or if verbosity is set to false
21241
21242        """
21243        return _pyAgrum.GibbsBNdistance_history(self)
21244
21245    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
21246        return _pyAgrum.GibbsBNdistance__asIApproximationSchemeConfiguration(self)
21247
21248    def nbrDrawnVar(self) -> int:
21249        r"""
21250
21251        Returns
21252        -------
21253        int
21254          the number of variable drawn at each iteration
21255
21256        """
21257        return _pyAgrum.GibbsBNdistance_nbrDrawnVar(self)
21258
21259    def setNbrDrawnVar(self, _nbr: int) -> None:
21260        r"""
21261
21262        Parameters
21263        ----------
21264        _nbr : int
21265          the number of variables to be drawn at each iteration
21266
21267        """
21268        return _pyAgrum.GibbsBNdistance_setNbrDrawnVar(self, _nbr)
21269
21270    def isDrawnAtRandom(self) -> bool:
21271        r"""
21272
21273        Returns
21274        -------
21275        bool
21276          True if variables are drawn at random
21277
21278        """
21279        return _pyAgrum.GibbsBNdistance_isDrawnAtRandom(self)
21280
21281    def setDrawnAtRandom(self, _atRandom: bool) -> None:
21282        r"""
21283
21284        Parameters
21285        ----------
21286        _atRandom : bool
21287          indicates if variables should be drawn at random
21288
21289        """
21290        return _pyAgrum.GibbsBNdistance_setDrawnAtRandom(self, _atRandom)
21291
21292# Register GibbsBNdistance in _pyAgrum:
21293_pyAgrum.GibbsBNdistance_swigregister(GibbsBNdistance)
21294
21295class CredalNet(object):
21296    r"""
21297
21298    Constructor used to create a CredalNet (step by step or with two BayesNet)
21299
21300    CredalNet() -> CredalNet
21301        default constructor
21302
21303    CredalNet(src_min_num,src_max_den) -> CredalNet
21304
21305    Parameters
21306    ----------
21307    src_min_num : str or pyAgrum.BayesNet
21308                The path to a BayesNet or the BN itself which contains lower probabilities.
21309    src_max_den : str or pyAgrum.BayesNet
21310                The (optional) path to a BayesNet or the BN itself which contains upper probabilities.
21311
21312
21313    """
21314
21315    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
21316    NodeType_Precise = _pyAgrum.CredalNet_NodeType_Precise
21317    NodeType_Credal = _pyAgrum.CredalNet_NodeType_Credal
21318    NodeType_Vacuous = _pyAgrum.CredalNet_NodeType_Vacuous
21319    NodeType_Indic = _pyAgrum.CredalNet_NodeType_Indic
21320
21321    def __init__(self, *args):
21322        _pyAgrum.CredalNet_swiginit(self, _pyAgrum.new_CredalNet(*args))
21323    __swig_destroy__ = _pyAgrum.delete_CredalNet
21324
21325    def addVariable(self, name: str, card: int) -> int:
21326        r"""
21327
21328        Parameters
21329        ----------
21330        name : str
21331        	the name of the new variable
21332        card: int
21333            the domainSize of the new variable
21334
21335        Returns
21336        -------
21337        int
21338        	the id of the new node
21339
21340        """
21341        return _pyAgrum.CredalNet_addVariable(self, name, card)
21342
21343    def addArc(self, tail: int, head: int) -> None:
21344        r"""
21345
21346        Adds an arc between two nodes
21347
21348        Parameters
21349        ----------
21350        tail :
21351        	the id of the tail node
21352        head : int
21353        	the id of the head node
21354
21355        Raises
21356        ------
21357        pyAgrum.InvalidDirectedCircle
21358        	If any (directed) cycle is created by this arc
21359        pyAgrum.InvalidNode
21360        	If head or tail does not belong to the graph nodes
21361        pyAgrum.DuplicateElement
21362        	If one of the arc already exists
21363
21364        """
21365        return _pyAgrum.CredalNet_addArc(self, tail, head)
21366
21367    def setCPTs(self, id: int, cpt: "pyAgrum.YetUnWrapped") -> None:
21368        r"""
21369
21370        Warnings
21371        --------
21372        (experimental function) - Parameters to be wrapped
21373
21374
21375        Set the vertices of the credal sets (all of the conditionals) of a given node
21376
21377        Parameters
21378        ----------
21379        id : int
21380        	the NodeId of the node
21381        cpt	: tbw
21382        	the vertices of every credal set (for each instantiation of the parents)
21383
21384        Warning
21385        -------
21386        DOES not change the BayesNet (s) associated to this credal net !
21387
21388        """
21389        return _pyAgrum.CredalNet_setCPTs(self, id, cpt)
21390
21391    def setCPT(self, *args) -> None:
21392        r"""
21393
21394        Warnings
21395        --------
21396        (experimental function) - Parameters to be wrapped
21397
21398
21399        Set the vertices of one credal set of a given node (any instantiation index)
21400
21401        Parameters
21402        ----------
21403        id : int
21404        	the Id of the node
21405        entry : int
21406        	the index of the instantiation (from 0 to K - 1) excluding the given node (only the parents are used to compute the index of the credal set)
21407        ins : pyAgrum.Instantiation
21408        	the Instantiation (only the parents matter to find the credal set index)
21409        cpt	: tbw
21410        	the vertices of every credal set (for each instantiation of the parents)
21411
21412        Warnings
21413        --------
21414        DOES not change the BayesNet(s) associated to this credal net !
21415
21416        """
21417        return _pyAgrum.CredalNet_setCPT(self, *args)
21418
21419    def fillConstraints(self, id: int, lower: "Vector", upper: "Vector") -> None:
21420        r"""
21421
21422        Set the interval constraints of the credal sets of a given node (all instantiations)
21423
21424        Parameters
21425        ----------
21426        id : int
21427        	The id of the node
21428        lower : list
21429        	The lower value for each probability in correct order
21430        upper : list
21431        	The upper value for each probability in correct order
21432
21433        Warnings
21434        --------
21435        You need to call intervalToCredal when done filling all constraints.
21436
21437        Warning
21438        -------
21439        DOES change the BayesNet (s) associated to this credal net !
21440
21441        """
21442        return _pyAgrum.CredalNet_fillConstraints(self, id, lower, upper)
21443
21444    def fillConstraint(self, *args) -> None:
21445        r"""
21446
21447        Set the interval constraints of a credal set of a given node (from an instantiation index)
21448
21449        Parameters
21450        ----------
21451        id : int
21452        	The id of the node
21453        entry : int
21454        	The index of the instantiation excluding the given node (only the parents are used to compute the index of the credal set)
21455        ins : pyAgrum.Instantiation
21456        	The Instantiation
21457        lower : list
21458        	The lower value for each probability in correct order
21459        upper : list
21460        	The upper value for each probability in correct order
21461
21462        Warnings
21463        --------
21464        You need to call intervalToCredal when done filling all constraints.
21465
21466        Warning
21467        -------
21468        DOES change the BayesNet (s) associated to this credal net !
21469
21470        """
21471        return _pyAgrum.CredalNet_fillConstraint(self, *args)
21472
21473    def instantiation(self, id: int) -> "pyAgrum.Instantiation":
21474        r"""
21475
21476        Get an Instantiation from a node id, usefull to fill the constraints of the network.
21477
21478        bnet accessors / shortcuts.
21479
21480        Parameters
21481        ----------
21482        id : int
21483        	the id of the node we want an instantiation from
21484
21485        Returns
21486        -------
21487        pyAgrum.Instantiation
21488            the instantiation
21489
21490        """
21491        return _pyAgrum.CredalNet_instantiation(self, id)
21492
21493    def domainSize(self, id: int) -> int:
21494        r"""
21495
21496        Parameters
21497        ----------
21498        id : int
21499        	The id of the node
21500
21501        Returns
21502        -------
21503        int
21504            The cardinality of the node
21505
21506        """
21507        return _pyAgrum.CredalNet_domainSize(self, id)
21508
21509    def bnToCredal(self, beta: float, oneNet: bool, keepZeroes: bool=False) -> None:
21510        r"""
21511
21512        Perturbates the BayesNet provided as input for this CredalNet by generating intervals instead of point probabilities and then computes each vertex of each credal set.
21513
21514        Parameters
21515        ----------
21516        beta : float
21517        	The beta used to perturbate the network
21518        oneNet : bool
21519        	used as a flag. Set to True if one BayesNet if provided with counts, to False if two BayesNet are provided; one with probabilities (the lower net) and one with denominators over the first modalities (the upper net)
21520        keepZeroes : bool
21521        	used as a flag as whether or not - respectively True or False - we keep zeroes as zeroes. Default is False, i.e. zeroes are not kept
21522
21523        """
21524        return _pyAgrum.CredalNet_bnToCredal(self, beta, oneNet, keepZeroes)
21525
21526    def intervalToCredalWithFiles(self) -> None:
21527        r"""
21528
21529        Warnings
21530        --------
21531        Deprecated : use intervalToCredal (lrsWrapper with no input / output files needed).
21532
21533
21534        Computes the vertices of each credal set according to their interval definition (uses lrs).
21535
21536        Use this method when using a single BayesNet storing counts of events.
21537
21538        """
21539        return _pyAgrum.CredalNet_intervalToCredalWithFiles(self)
21540
21541    def intervalToCredal(self) -> None:
21542        r"""
21543
21544        Computes the vertices of each credal set according to their interval definition (uses lrs).
21545
21546        Use this method when using two BayesNet, one with lower probabilities and one with upper probabilities.
21547
21548        """
21549        return _pyAgrum.CredalNet_intervalToCredal(self)
21550
21551    def lagrangeNormalization(self) -> None:
21552        r"""
21553
21554        Normalize counts of a BayesNet storing counts of each events such that no probability is 0.
21555
21556        Use this method when using a single BayesNet storing counts of events. Lagrange normalization. This call is irreversible and modify counts stored by __src_bn.
21557
21558        Doest not performs computations of the parameters but keeps normalized counts of events only. Call idmLearning to compute the probabilities (with any parameter value).
21559
21560        """
21561        return _pyAgrum.CredalNet_lagrangeNormalization(self)
21562
21563    def idmLearning(self, s: int=0, keepZeroes: bool=False) -> None:
21564        r"""
21565
21566        Learns parameters from a BayesNet storing counts of events.
21567
21568        Use this method when using a single BayesNet storing counts of events. IDM model if s > 0, standard point probability if s = 0 (default value if none precised).
21569
21570        Parameters
21571        ----------
21572        s : int
21573        	the IDM parameter.
21574        keepZeroes : bool
21575        	used as a flag as whether or not - respectively True or False - we keep zeroes as zeroes. Default is False, i.e. zeroes are not kept.
21576
21577        """
21578        return _pyAgrum.CredalNet_idmLearning(self, s, keepZeroes)
21579
21580    def approximatedBinarization(self) -> None:
21581        r"""
21582
21583        Approximate binarization.
21584
21585        Each bit has a lower and upper probability which is the lowest - resp. highest - over all vertices of the credal set. Enlarge the orignal credal sets and may induce huge imprecision.
21586
21587        Warnings
21588        --------
21589        Enlarge the orignal credal sets and therefor induce huge imprecision by propagation. Not recommended, use MCSampling or something else instead
21590
21591        """
21592        return _pyAgrum.CredalNet_approximatedBinarization(self)
21593
21594    def saveBNsMinMax(self, min_path: str, max_path: str) -> None:
21595        r"""
21596
21597        If this CredalNet was built over a perturbed BayesNet, one can save the intervals as two BayesNet.
21598
21599        to call after bnToCredal(GUM_SCALAR beta) save a BN with lower probabilities and a BN with upper ones
21600
21601        Parameters
21602        ----------
21603        min_path : str
21604        	the path to save the BayesNet which contains the lower probabilities of each node X.
21605        max_path : str
21606        	the path to save the BayesNet which contains the upper probabilities of each node X.
21607
21608        """
21609        return _pyAgrum.CredalNet_saveBNsMinMax(self, min_path, max_path)
21610
21611    def computeBinaryCPTMinMax(self) -> None:
21612        return _pyAgrum.CredalNet_computeBinaryCPTMinMax(self)
21613
21614    def src_bn(self) -> "pyAgrum.BayesNet":
21615        r"""
21616
21617        Returns
21618        -------
21619        pyAgrum.BayesNet
21620            Returns a constant reference to the original BayesNet (used as a DAG, it's CPTs does not matter).
21621
21622        """
21623        return _pyAgrum.CredalNet_src_bn(self)
21624
21625    def current_bn(self) -> "pyAgrum.BayesNet":
21626        r"""
21627
21628        Returns
21629        -------
21630        pyAgrum.BayesNet
21631            Returs a constant reference to the actual BayesNet (used as a DAG, it's CPTs does not matter).
21632
21633        """
21634        return _pyAgrum.CredalNet_current_bn(self)
21635
21636    def credalNet_currentCpt(self) -> "pyAgrum.YetUnWrapped":
21637        r"""
21638
21639        Warnings
21640        --------
21641        Experimental function - Return type to be wrapped
21642
21643        Returns
21644        -------
21645        tbw
21646            a constant reference to the (up-to-date) CredalNet CPTs.
21647
21648        """
21649        return _pyAgrum.CredalNet_credalNet_currentCpt(self)
21650
21651    def credalNet_srcCpt(self) -> "pyAgrum.YetUnWrapped":
21652        r"""
21653
21654        Warnings
21655        --------
21656        Experimental function - Return type to be wrapped
21657
21658        Returns
21659        -------
21660        tbw
21661            a constant reference to the (up-to-date) CredalNet CPTs.
21662
21663        """
21664        return _pyAgrum.CredalNet_credalNet_srcCpt(self)
21665
21666    def currentNodeType(self, id: int) -> int:
21667        r"""
21668
21669        Parameters
21670        ----------
21671        id : int
21672        	The constant reference to the choosen NodeId
21673
21674        Returns
21675        -------
21676        pyAgrum.CredalNet
21677            the type of the choosen node in the (up-to-date) CredalNet __current_bn if any, __src_bn otherwise.
21678
21679        """
21680        return _pyAgrum.CredalNet_currentNodeType(self, id)
21681
21682    def nodeType(self, id: int) -> int:
21683        r"""
21684
21685        Parameters
21686        ----------
21687        id : int
21688        	the constant reference to the choosen NodeId
21689
21690        Returns
21691        -------
21692        pyAgrum.CredalNet
21693        	the type of the choosen node in the (up-to-date) CredalNet in __src_bn.
21694
21695        """
21696        return _pyAgrum.CredalNet_nodeType(self, id)
21697
21698    def epsilonMin(self) -> float:
21699        r"""
21700
21701        Returns
21702        -------
21703        float
21704            a constant reference to the lowest perturbation of the BayesNet provided as input for this CredalNet.
21705
21706        """
21707        return _pyAgrum.CredalNet_epsilonMin(self)
21708
21709    def epsilonMax(self) -> float:
21710        r"""
21711
21712        Returns
21713        -------
21714        float
21715            a constant reference to the highest perturbation of the BayesNet provided as input for this CredalNet.
21716
21717        """
21718        return _pyAgrum.CredalNet_epsilonMax(self)
21719
21720    def epsilonMean(self) -> float:
21721        r"""
21722
21723        Returns
21724        -------
21725        float
21726            a constant reference to the average perturbation of the BayesNet provided as input for this CredalNet.
21727
21728        """
21729        return _pyAgrum.CredalNet_epsilonMean(self)
21730
21731    def isSeparatelySpecified(self) -> bool:
21732        r"""
21733
21734        Returns
21735        -------
21736        bool
21737        	True if this CredalNet is separately and interval specified, False otherwise.
21738
21739        """
21740        return _pyAgrum.CredalNet_isSeparatelySpecified(self)
21741
21742    def hasComputedBinaryCPTMinMax(self) -> bool:
21743        return _pyAgrum.CredalNet_hasComputedBinaryCPTMinMax(self)
21744
21745    def get_binaryCPT_min(self) -> "pyAgrum.YetUnWrapped":
21746        r"""
21747
21748        Warnings
21749        --------
21750        Experimental function - Return type to be wrapped
21751
21752        Returns
21753        -------
21754        tbw
21755        	a constant reference to the lower probabilities of each node X over the 'True' modality
21756
21757        """
21758        return _pyAgrum.CredalNet_get_binaryCPT_min(self)
21759
21760    def get_binaryCPT_max(self) -> "pyAgrum.YetUnWrapped":
21761        r"""
21762
21763        Warnings
21764        --------
21765        Experimental function - Return type to be wrapped
21766
21767        Returns
21768        -------
21769        tbw
21770        	a constant reference to the upper probabilities of each node X over the 'True' modality
21771
21772        """
21773        return _pyAgrum.CredalNet_get_binaryCPT_max(self)
21774
21775    def __repr__(self) -> str:
21776        return _pyAgrum.CredalNet___repr__(self)
21777
21778    def __str__(self) -> str:
21779        return _pyAgrum.CredalNet___str__(self)
21780
21781# Register CredalNet in _pyAgrum:
21782_pyAgrum.CredalNet_swigregister(CredalNet)
21783
21784class CNMonteCarloSampling(object):
21785    r"""
21786
21787    Class used for inferences in credal networks with Monte Carlo sampling algorithm.
21788
21789    CNMonteCarloSampling(cn) -> CNMonteCarloSampling
21790        Parameters:
21791            * **cn** (*pyAgrum.CredalNet*) -- a credal network
21792
21793    """
21794
21795    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
21796    __repr__ = _swig_repr
21797
21798    def __init__(self, credalNet: "CredalNet"):
21799        _pyAgrum.CNMonteCarloSampling_swiginit(self, _pyAgrum.new_CNMonteCarloSampling(credalNet))
21800
21801        self._model=credalNet
21802
21803
21804
21805    __swig_destroy__ = _pyAgrum.delete_CNMonteCarloSampling
21806
21807    def makeInference(self) -> None:
21808        r"""
21809
21810        Starts the inference.
21811
21812        """
21813        return _pyAgrum.CNMonteCarloSampling_makeInference(self)
21814
21815    def insertEvidenceFile(self, path: str) -> None:
21816        r"""
21817
21818        Insert evidence from file.
21819
21820        Parameters
21821        ----------
21822        path : str
21823        	the path to the evidence file.
21824
21825        """
21826        return _pyAgrum.CNMonteCarloSampling_insertEvidenceFile(self, path)
21827
21828    def setVerbosity(self, v: bool) -> None:
21829        r"""
21830
21831        Parameters
21832        ----------
21833        v : bool
21834                verbosity
21835
21836        """
21837        return _pyAgrum.CNMonteCarloSampling_setVerbosity(self, v)
21838
21839    def setEpsilon(self, eps: float) -> None:
21840        r"""
21841
21842        Parameters
21843        ----------
21844        eps : float
21845        	the epsilon we want to use
21846
21847        Raises
21848        ------
21849        pyAgrum.OutOfBounds
21850        	If eps<0
21851
21852        """
21853        return _pyAgrum.CNMonteCarloSampling_setEpsilon(self, eps)
21854
21855    def setMinEpsilonRate(self, rate: float) -> None:
21856        r"""
21857
21858        Parameters
21859        ----------
21860        rate : float
21861        	the minimal epsilon rate
21862
21863        """
21864        return _pyAgrum.CNMonteCarloSampling_setMinEpsilonRate(self, rate)
21865
21866    def setMaxIter(self, max: int) -> None:
21867        r"""
21868
21869        Parameters
21870        ----------
21871        max : int
21872        	the maximum number of iteration
21873
21874        Raises
21875        ------
21876        pyAgrum.OutOfBounds
21877        	If max <= 1
21878
21879        """
21880        return _pyAgrum.CNMonteCarloSampling_setMaxIter(self, max)
21881
21882    def setMaxTime(self, timeout: float) -> None:
21883        r"""
21884
21885        Parameters
21886        ----------
21887        tiemout : float
21888        	stopping criterion on timeout (in seconds)
21889
21890        Raises
21891        ------
21892        pyAgrum.OutOfBounds
21893        	If timeout<=0.0
21894
21895        """
21896        return _pyAgrum.CNMonteCarloSampling_setMaxTime(self, timeout)
21897
21898    def setPeriodSize(self, p: int) -> None:
21899        r"""
21900
21901        Parameters
21902        ----------
21903        p : int
21904        	number of samples between 2 stopping
21905
21906        Raises
21907        ------
21908        pyAgrum.OutOfBounds
21909        	If p<1
21910
21911        """
21912        return _pyAgrum.CNMonteCarloSampling_setPeriodSize(self, p)
21913
21914    def verbosity(self) -> bool:
21915        r"""
21916
21917        Returns
21918        -------
21919        bool
21920        	True if the verbosity is enabled
21921
21922        """
21923        return _pyAgrum.CNMonteCarloSampling_verbosity(self)
21924
21925    def epsilon(self) -> float:
21926        r"""
21927
21928        Returns
21929        -------
21930        float
21931        	the value of epsilon
21932
21933        """
21934        return _pyAgrum.CNMonteCarloSampling_epsilon(self)
21935
21936    def minEpsilonRate(self) -> float:
21937        r"""
21938
21939        Returns
21940        -------
21941        float
21942        	the value of the minimal epsilon rate
21943
21944        """
21945        return _pyAgrum.CNMonteCarloSampling_minEpsilonRate(self)
21946
21947    def maxIter(self) -> int:
21948        r"""
21949
21950        Returns
21951        -------
21952        int
21953        	the criterion on number of iterations
21954
21955        """
21956        return _pyAgrum.CNMonteCarloSampling_maxIter(self)
21957
21958    def maxTime(self) -> float:
21959        r"""
21960
21961        Returns
21962        -------
21963        float
21964        	the timeout(in seconds)
21965
21966        """
21967        return _pyAgrum.CNMonteCarloSampling_maxTime(self)
21968
21969    def periodSize(self) -> int:
21970        r"""
21971
21972        Returns
21973        -------
21974        int
21975        	the number of samples between 2 stopping
21976
21977        Raises
21978        ------
21979        pyAgrum.OutOfBounds
21980        	If p<1
21981
21982        """
21983        return _pyAgrum.CNMonteCarloSampling_periodSize(self)
21984
21985    def nbrIterations(self) -> int:
21986        r"""
21987
21988        Returns
21989        -------
21990        int
21991        	the number of iterations
21992
21993        """
21994        return _pyAgrum.CNMonteCarloSampling_nbrIterations(self)
21995
21996    def currentTime(self) -> float:
21997        r"""
21998
21999        Returns
22000        -------
22001        float
22002        	get the current running time in second (float)
22003
22004        """
22005        return _pyAgrum.CNMonteCarloSampling_currentTime(self)
22006
22007    def messageApproximationScheme(self) -> str:
22008        r"""
22009
22010        Returns
22011        -------
22012        str
22013        	the approximation scheme message
22014
22015        """
22016        return _pyAgrum.CNMonteCarloSampling_messageApproximationScheme(self)
22017
22018    def history(self) -> List[float]:
22019        r"""
22020
22021        Returns
22022        -------
22023        tuple
22024        	the scheme history
22025
22026        Raises
22027        ------
22028        pyAgrum.OperationNotAllowed
22029        	If the scheme did not performed or if verbosity is set to false
22030
22031        """
22032        return _pyAgrum.CNMonteCarloSampling_history(self)
22033
22034    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
22035        return _pyAgrum.CNMonteCarloSampling__asIApproximationSchemeConfiguration(self)
22036
22037    def setRepetitiveInd(self, flag: bool) -> None:
22038        r"""
22039
22040        Parameters
22041        ----------
22042        flag : bool
22043        	True if repetitive independence is to be used, false otherwise. Only usefull with dynamic networks.
22044
22045        """
22046        return _pyAgrum.CNMonteCarloSampling_setRepetitiveInd(self, flag)
22047
22048    def marginalMax(self, *args) -> "pyAgrum.Potential":
22049        r"""
22050
22051        Get the upper marginals of a given node id.
22052
22053        Parameters
22054        ----------
22055        id : int
22056        	the node id which upper marginals we want.
22057        varName : str
22058        	the variable name which upper marginals we want.
22059
22060        Returns
22061        -------
22062        list
22063            a constant reference to this node upper marginals.
22064
22065        Raises
22066        ------
22067        pyAgrum.IndexError
22068        	If the node does not belong to the Credal network
22069
22070        """
22071        return _pyAgrum.CNMonteCarloSampling_marginalMax(self, *args)
22072
22073    def marginalMin(self, *args) -> "pyAgrum.Potential":
22074        r"""
22075
22076        Get the lower marginals of a given node id.
22077
22078        Parameters
22079        ----------
22080        id : int
22081        	the node id which lower marginals we want.
22082        varName : str
22083        	the variable name which lower marginals we want.
22084
22085        Returns
22086        -------
22087        list
22088            a constant reference to this node lower marginals.
22089
22090        Raises
22091        ------
22092        pyAgrum.IndexError
22093        	If the node does not belong to the Credal network
22094
22095        """
22096        return _pyAgrum.CNMonteCarloSampling_marginalMin(self, *args)
22097
22098    def insertModalsFile(self, path: str) -> None:
22099        r"""
22100
22101        Insert variables modalities from file to compute expectations.
22102
22103        Parameters
22104        ----------
22105        path : str
22106        	The path to the modalities file.
22107
22108        """
22109        return _pyAgrum.CNMonteCarloSampling_insertModalsFile(self, path)
22110
22111    def dynamicExpMax(self, varName: str) -> List[float]:
22112        r"""
22113
22114        Get the upper dynamic expectation of a given variable prefix.
22115
22116        Parameters
22117        ----------
22118        varName : str
22119        	the variable name prefix which upper expectation we want.
22120
22121        Returns
22122        -------
22123        float
22124            a constant reference to the variable upper expectation over all time steps.
22125
22126        """
22127        return _pyAgrum.CNMonteCarloSampling_dynamicExpMax(self, varName)
22128
22129    def dynamicExpMin(self, varName: str) -> List[float]:
22130        r"""
22131
22132        Get the lower dynamic expectation of a given variable prefix.
22133
22134        Parameters
22135        ----------
22136        varName : str
22137        	the variable name prefix which lower expectation we want.
22138
22139        Returns
22140        -------
22141        float
22142            a constant reference to the variable lower expectation over all time steps.
22143
22144        """
22145        return _pyAgrum.CNMonteCarloSampling_dynamicExpMin(self, varName)
22146
22147    def CN(self) -> "pyAgrum.CredalNet":
22148        return _pyAgrum.CNMonteCarloSampling_CN(self)
22149
22150# Register CNMonteCarloSampling in _pyAgrum:
22151_pyAgrum.CNMonteCarloSampling_swigregister(CNMonteCarloSampling)
22152
22153class CNLoopyPropagation(object):
22154    r"""
22155
22156    Class used for inferences in credal networks with Loopy Propagation algorithm.
22157
22158    CNLoopyPropagation(cn) -> CNLoopyPropagation
22159        Parameters:
22160          * **cn** (*pyAgrum.CredalNet*) -- a Credal network
22161
22162    """
22163
22164    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
22165    __repr__ = _swig_repr
22166    InferenceType_nodeToNeighbours = _pyAgrum.CNLoopyPropagation_InferenceType_nodeToNeighbours
22167    InferenceType_ordered = _pyAgrum.CNLoopyPropagation_InferenceType_ordered
22168    InferenceType_randomOrder = _pyAgrum.CNLoopyPropagation_InferenceType_randomOrder
22169
22170    def makeInference(self) -> None:
22171        r"""
22172
22173        Starts the inference.
22174
22175        """
22176        return _pyAgrum.CNLoopyPropagation_makeInference(self)
22177
22178    def inferenceType(self, *args) -> int:
22179        r"""
22180
22181        Returns
22182        -------
22183        int
22184        	the inference type
22185
22186        """
22187        return _pyAgrum.CNLoopyPropagation_inferenceType(self, *args)
22188
22189    def eraseAllEvidence(self) -> None:
22190        r"""
22191
22192        Erase all inference related data to perform another one.
22193
22194        You need to insert evidence again if needed but modalities are kept. You can insert new ones by using the appropriate method which will delete the old ones.
22195
22196        """
22197        return _pyAgrum.CNLoopyPropagation_eraseAllEvidence(self)
22198
22199    def saveInference(self, path: str) -> None:
22200        r"""
22201
22202        Saves marginals.
22203
22204        Parameters
22205        ----------
22206        path : str
22207        	The path to the file to save marginals.
22208
22209        """
22210        return _pyAgrum.CNLoopyPropagation_saveInference(self, path)
22211
22212    def __init__(self, cnet: "CredalNet"):
22213        _pyAgrum.CNLoopyPropagation_swiginit(self, _pyAgrum.new_CNLoopyPropagation(cnet))
22214
22215        self._model=cnet
22216
22217
22218
22219    __swig_destroy__ = _pyAgrum.delete_CNLoopyPropagation
22220
22221    def insertEvidenceFile(self, path: str) -> None:
22222        r"""
22223
22224        Insert evidence from file.
22225
22226        Parameters
22227        ----------
22228        path : str
22229        	the path to the evidence file.
22230
22231        """
22232        return _pyAgrum.CNLoopyPropagation_insertEvidenceFile(self, path)
22233
22234    def setVerbosity(self, v: bool) -> None:
22235        r"""
22236
22237        Parameters
22238        ----------
22239        v : bool
22240                verbosity
22241
22242        """
22243        return _pyAgrum.CNLoopyPropagation_setVerbosity(self, v)
22244
22245    def setEpsilon(self, eps: float) -> None:
22246        r"""
22247
22248        Parameters
22249        ----------
22250        eps : float
22251        	the epsilon we want to use
22252
22253        Raises
22254        ------
22255        pyAgrum.OutOfBounds
22256        	If eps<0
22257
22258        """
22259        return _pyAgrum.CNLoopyPropagation_setEpsilon(self, eps)
22260
22261    def setMinEpsilonRate(self, rate: float) -> None:
22262        r"""
22263
22264        Parameters
22265        ----------
22266        rate : float
22267        	the minimal epsilon rate
22268
22269        """
22270        return _pyAgrum.CNLoopyPropagation_setMinEpsilonRate(self, rate)
22271
22272    def setMaxIter(self, max: int) -> None:
22273        r"""
22274
22275        Parameters
22276        ----------
22277        max : int
22278        	the maximum number of iteration
22279
22280        Raises
22281        ------
22282        pyAgrum.OutOfBounds
22283        	If max <= 1
22284
22285        """
22286        return _pyAgrum.CNLoopyPropagation_setMaxIter(self, max)
22287
22288    def setMaxTime(self, timeout: float) -> None:
22289        r"""
22290
22291        Parameters
22292        ----------
22293        tiemout : float
22294        	stopping criterion on timeout (in seconds)
22295
22296        Raises
22297        ------
22298        pyAgrum.OutOfBounds
22299        	If timeout<=0.0
22300
22301        """
22302        return _pyAgrum.CNLoopyPropagation_setMaxTime(self, timeout)
22303
22304    def setPeriodSize(self, p: int) -> None:
22305        r"""
22306
22307        Parameters
22308        ----------
22309        p : int
22310        	number of samples between 2 stopping
22311
22312        Raises
22313        ------
22314        pyAgrum.OutOfBounds
22315        	If p<1
22316
22317        """
22318        return _pyAgrum.CNLoopyPropagation_setPeriodSize(self, p)
22319
22320    def verbosity(self) -> bool:
22321        r"""
22322
22323        Returns
22324        -------
22325        bool
22326        	True if the verbosity is enabled
22327
22328        """
22329        return _pyAgrum.CNLoopyPropagation_verbosity(self)
22330
22331    def epsilon(self) -> float:
22332        r"""
22333
22334        Returns
22335        -------
22336        float
22337        	the value of epsilon
22338
22339        """
22340        return _pyAgrum.CNLoopyPropagation_epsilon(self)
22341
22342    def minEpsilonRate(self) -> float:
22343        r"""
22344
22345        Returns
22346        -------
22347        float
22348        	the value of the minimal epsilon rate
22349
22350        """
22351        return _pyAgrum.CNLoopyPropagation_minEpsilonRate(self)
22352
22353    def maxIter(self) -> int:
22354        r"""
22355
22356        Returns
22357        -------
22358        int
22359        	the criterion on number of iterations
22360
22361        """
22362        return _pyAgrum.CNLoopyPropagation_maxIter(self)
22363
22364    def maxTime(self) -> float:
22365        r"""
22366
22367        Returns
22368        -------
22369        float
22370        	the timeout(in seconds)
22371
22372        """
22373        return _pyAgrum.CNLoopyPropagation_maxTime(self)
22374
22375    def periodSize(self) -> int:
22376        r"""
22377
22378        Returns
22379        -------
22380        int
22381        	the number of samples between 2 stopping
22382
22383        Raises
22384        ------
22385        pyAgrum.OutOfBounds
22386        	If p<1
22387
22388        """
22389        return _pyAgrum.CNLoopyPropagation_periodSize(self)
22390
22391    def nbrIterations(self) -> int:
22392        r"""
22393
22394        Returns
22395        -------
22396        int
22397        	the number of iterations
22398
22399        """
22400        return _pyAgrum.CNLoopyPropagation_nbrIterations(self)
22401
22402    def currentTime(self) -> float:
22403        r"""
22404
22405        Returns
22406        -------
22407        float
22408        	get the current running time in second (float)
22409
22410        """
22411        return _pyAgrum.CNLoopyPropagation_currentTime(self)
22412
22413    def messageApproximationScheme(self) -> str:
22414        r"""
22415
22416        Returns
22417        -------
22418        str
22419        	the approximation scheme message
22420
22421        """
22422        return _pyAgrum.CNLoopyPropagation_messageApproximationScheme(self)
22423
22424    def history(self) -> List[float]:
22425        r"""
22426
22427        Returns
22428        -------
22429        tuple
22430        	the scheme history
22431
22432        Raises
22433        ------
22434        pyAgrum.OperationNotAllowed
22435        	If the scheme did not performed or if verbosity is set to false
22436
22437        """
22438        return _pyAgrum.CNLoopyPropagation_history(self)
22439
22440    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
22441        return _pyAgrum.CNLoopyPropagation__asIApproximationSchemeConfiguration(self)
22442
22443    def setRepetitiveInd(self, flag: bool) -> None:
22444        r"""
22445
22446        Parameters
22447        ----------
22448        flag : bool
22449        	True if repetitive independence is to be used, false otherwise. Only usefull with dynamic networks.
22450
22451        """
22452        return _pyAgrum.CNLoopyPropagation_setRepetitiveInd(self, flag)
22453
22454    def marginalMax(self, *args) -> "pyAgrum.Potential":
22455        r"""
22456
22457        Get the upper marginals of a given node id.
22458
22459        Parameters
22460        ----------
22461        id : int
22462        	the node id which upper marginals we want.
22463        varName : str
22464        	the variable name which upper marginals we want.
22465
22466        Returns
22467        -------
22468        list
22469            a constant reference to this node upper marginals.
22470
22471        Raises
22472        ------
22473        pyAgrum.IndexError
22474        	If the node does not belong to the Credal network
22475
22476        """
22477        return _pyAgrum.CNLoopyPropagation_marginalMax(self, *args)
22478
22479    def marginalMin(self, *args) -> "pyAgrum.Potential":
22480        r"""
22481
22482        Get the lower marginals of a given node id.
22483
22484        Parameters
22485        ----------
22486        id : int
22487        	the node id which lower marginals we want.
22488        varName : str
22489        	the variable name which lower marginals we want.
22490
22491        Returns
22492        -------
22493        list
22494            a constant reference to this node lower marginals.
22495
22496        Raises
22497        ------
22498        pyAgrum.IndexError
22499        	If the node does not belong to the Credal network
22500
22501        """
22502        return _pyAgrum.CNLoopyPropagation_marginalMin(self, *args)
22503
22504    def insertModalsFile(self, path: str) -> None:
22505        r"""
22506
22507        Insert variables modalities from file to compute expectations.
22508
22509        Parameters
22510        ----------
22511        path : str
22512        	The path to the modalities file.
22513
22514        """
22515        return _pyAgrum.CNLoopyPropagation_insertModalsFile(self, path)
22516
22517    def dynamicExpMax(self, varName: str) -> List[float]:
22518        r"""
22519
22520        Get the upper dynamic expectation of a given variable prefix.
22521
22522        Parameters
22523        ----------
22524        varName : str
22525        	the variable name prefix which upper expectation we want.
22526
22527        Returns
22528        -------
22529        float
22530            a constant reference to the variable upper expectation over all time steps.
22531
22532        """
22533        return _pyAgrum.CNLoopyPropagation_dynamicExpMax(self, varName)
22534
22535    def dynamicExpMin(self, varName: str) -> List[float]:
22536        r"""
22537
22538        Get the lower dynamic expectation of a given variable prefix.
22539
22540        Parameters
22541        ----------
22542        varName : str
22543        	the variable name prefix which lower expectation we want.
22544
22545        Returns
22546        -------
22547        float
22548            a constant reference to the variable lower expectation over all time steps.
22549
22550        """
22551        return _pyAgrum.CNLoopyPropagation_dynamicExpMin(self, varName)
22552
22553    def CN(self) -> "pyAgrum.CredalNet":
22554        return _pyAgrum.CNLoopyPropagation_CN(self)
22555
22556# Register CNLoopyPropagation in _pyAgrum:
22557_pyAgrum.CNLoopyPropagation_swigregister(CNLoopyPropagation)
22558
22559class InfluenceDiagram(DAGmodel):
22560    r"""
22561
22562    InfluenceDiagram represents an Influence Diagram.
22563
22564    InfluenceDiagram() -> InfluenceDiagram
22565        default constructor
22566
22567    InfluenceDiagram(source) -> InfluenceDiagram
22568        Parameters:
22569            * **source** (*pyAgrum.InfluenceDiagram*) -- the InfluenceDiagram to copy
22570
22571    """
22572
22573    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
22574
22575    @staticmethod
22576    def fastPrototype(dotlike: str, domainSize: int=2) -> "pyAgrum.InfluenceDiagram":
22577        r"""
22578
22579        Create an Influence Diagram with a dot-like syntax which specifies:
22580            - the structure 'a->b<-c;b->d;c<-e;'.
22581            - a prefix for the type of node (chance/decision/utiliy nodes):
22582
22583              - `a` : a chance node named 'a' (by default)
22584              - `$a` : a utility node named 'a'
22585              - `*a` : a decision node named 'a'
22586
22587            - the type of the variables with different syntax as postfix:
22588
22589              - by default, a variable is a pyAgrum.RangeVariable using the default domain size (second argument)
22590              - with `'a[10]'`, the variable is a pyAgrum.RangeVariable using 10 as domain size (from 0 to 9)
22591              - with `'a[3,7]'`, the variable is a pyAgrum.RangeVariable using a domainSize from 3 to 7
22592              - with `'a[1,3.14,5,6.2]'`, the variable is a pyAgrum.DiscretizedVariable using the given ticks (at least 3 values)
22593              - with `'a{top|middle|bottom}'`, the variable is a pyAgrum.LabelizedVariable using the given labels.
22594              - with 'a{-1|5|0|3}', the variable is a pyAgrum.IntegerVariable using the sorted given values.
22595
22596        Note
22597        ----
22598          - If the dot-like string contains such a specification more than once for a variable, the first specification will be used.
22599          - the potentials (probabilities, utilities) are randomly generated.
22600          - see also pyAgrum.fastID.
22601
22602        Examples
22603        --------
22604        >>> import pyAgrum as gum
22605        >>> bn=pyAgrum.fastID('A->B[1,3]<-*C{yes|No}->$D<-E[1,2.5,3.9]',6)
22606
22607        Parameters
22608        ----------
22609        dotlike : str
22610                the string containing the specification
22611        domainSize : int
22612                the default domain size for variables
22613
22614        Returns
22615        -------
22616        pyAgrum.InfluenceDiagram
22617                the resulting Influence Diagram
22618
22619        """
22620        return _pyAgrum.InfluenceDiagram_fastPrototype(dotlike, domainSize)
22621    __swig_destroy__ = _pyAgrum.delete_InfluenceDiagram
22622
22623    def __init__(self, *args):
22624        _pyAgrum.InfluenceDiagram_swiginit(self, _pyAgrum.new_InfluenceDiagram(*args))
22625
22626    def toDot(self) -> str:
22627        r"""
22628
22629        Returns
22630        -------
22631        str
22632            a friendly display of the graph in DOT format
22633
22634        """
22635        return _pyAgrum.InfluenceDiagram_toDot(self)
22636
22637    def clear(self) -> None:
22638        return _pyAgrum.InfluenceDiagram_clear(self)
22639
22640    def cpt(self, *args) -> "pyAgrum.Potential":
22641        r"""
22642
22643        Returns the CPT of a variable.
22644
22645        Parameters
22646        ----------
22647        VarId : int
22648        	A variable's id in the pyAgrum.BayesNet.
22649
22650        Returns
22651        -------
22652        pyAgrum.Potential
22653        	The variable's CPT.
22654
22655        Raises
22656        ------
22657        pyAgrum.NotFound
22658        	If no variable's id matches varId.
22659
22660        """
22661        return _pyAgrum.InfluenceDiagram_cpt(self, *args)
22662
22663    def utility(self, *args) -> "pyAgrum.Potential":
22664        r"""
22665
22666        Parameters
22667        ----------
22668        varId : int
22669        	the tested node id.
22670
22671        Returns
22672        -------
22673        pyAgrum.Potential
22674        	the utility table of the node
22675
22676        Raises
22677        ------
22678        pyAgrum.IndexError
22679        	If the InfluenceDiagram does not contain the variable
22680
22681        """
22682        return _pyAgrum.InfluenceDiagram_utility(self, *args)
22683
22684    def isUtilityNode(self, *args) -> bool:
22685        r"""
22686
22687        Parameters
22688        ----------
22689        varId : int
22690        	the tested node id.
22691
22692        Returns
22693        -------
22694        bool
22695        	true if node is an utility node
22696
22697        """
22698        return _pyAgrum.InfluenceDiagram_isUtilityNode(self, *args)
22699
22700    def isDecisionNode(self, *args) -> bool:
22701        r"""
22702
22703        Parameters
22704        ----------
22705        varId : int
22706        	the tested node id.
22707
22708        Returns
22709        -------
22710        bool
22711        	true if node is a decision node
22712
22713        """
22714        return _pyAgrum.InfluenceDiagram_isDecisionNode(self, *args)
22715
22716    def isChanceNode(self, *args) -> bool:
22717        r"""
22718
22719        Parameters
22720        ----------
22721        varId : int
22722        	the tested node id.
22723
22724        Returns
22725        -------
22726        bool
22727        	true if node is a chance node
22728
22729        """
22730        return _pyAgrum.InfluenceDiagram_isChanceNode(self, *args)
22731
22732    def utilityNodeSize(self) -> int:
22733        r"""
22734
22735        Returns
22736        -------
22737        int
22738        	the number of utility nodes
22739
22740        """
22741        return _pyAgrum.InfluenceDiagram_utilityNodeSize(self)
22742
22743    def chanceNodeSize(self) -> int:
22744        r"""
22745
22746        Returns
22747        -------
22748        int
22749        	the number of chance nodes.
22750
22751        """
22752        return _pyAgrum.InfluenceDiagram_chanceNodeSize(self)
22753
22754    def decisionNodeSize(self) -> int:
22755        r"""
22756
22757        Returns
22758        -------
22759        int
22760        	the number of decision nodes
22761
22762        """
22763        return _pyAgrum.InfluenceDiagram_decisionNodeSize(self)
22764
22765    def variable(self, *args) -> "pyAgrum.DiscreteVariable":
22766        r"""
22767
22768        Parameters
22769        ----------
22770        id : int
22771         	the node id
22772
22773        Returns
22774        ------
22775        pyAgrum.DiscreteVariable
22776        	a constant reference over a variabe given it's node id
22777
22778        Raises
22779        ------
22780        pyAgrum.NotFound
22781        	If no variable's id matches the parameter
22782
22783        """
22784        return _pyAgrum.InfluenceDiagram_variable(self, *args)
22785
22786    def nodeId(self, var: "pyAgrum.DiscreteVariable") -> int:
22787        r"""
22788
22789        Parameters
22790        ----------
22791        var : pyAgrum.DiscreteVariable
22792        	a variable
22793
22794        Returns
22795        -------
22796        int
22797        	the id of the variable
22798
22799        Raises
22800        ------
22801        pyAgrum.IndexError
22802        	If the InfluenceDiagram does not contain the variable
22803
22804        """
22805        return _pyAgrum.InfluenceDiagram_nodeId(self, var)
22806
22807    def idFromName(self, name: str) -> int:
22808        r"""
22809
22810        Returns a variable's id given its name.
22811
22812        Parameters
22813        ----------
22814        name : str
22815        	the variable's name from which the id is returned.
22816
22817        Returns
22818        -------
22819        int
22820        	the variable's node id.
22821
22822        Raises
22823        ------
22824        pyAgrum.NotFound
22825        	If no such name exists in the graph.
22826
22827        """
22828        return _pyAgrum.InfluenceDiagram_idFromName(self, name)
22829
22830    def variableFromName(self, name: str) -> "pyAgrum.DiscreteVariable":
22831        r"""
22832
22833        Parameters
22834        ----------
22835        name : str
22836        	a variable's name
22837
22838        Returns
22839        -------
22840        pyAgrum.DiscreteVariable
22841        	the variable
22842
22843        Raises
22844        ------
22845        pyAgrum.IndexError
22846        	If the InfluenceDiagram does not contain the variable
22847
22848        """
22849        return _pyAgrum.InfluenceDiagram_variableFromName(self, name)
22850
22851    def add(self, variable: "pyAgrum.DiscreteVariable", id: int=0) -> int:
22852        r"""
22853
22854        Add a chance variable, it's associate node and it's CPT.
22855
22856        The id of the new variable is automatically generated.
22857
22858        Parameters
22859        ----------
22860        variable : pyAgrum.DiscreteVariable
22861        	The variable added by copy.
22862        id : int
22863        	The chosen id. If 0, the NodeGraphPart will choose.
22864
22865        Warnings
22866        --------
22867        give an id (not 0) should be reserved for rare and specific situations !!!
22868
22869        Returns
22870        -------
22871        int
22872            the id of the added variable.
22873
22874        Raises
22875        ------
22876        pyAgrum.DuplicateElement
22877        	If id(<>0) is already used
22878
22879        """
22880        return _pyAgrum.InfluenceDiagram_add(self, variable, id)
22881
22882    def addDecisionNode(self, variable: "pyAgrum.DiscreteVariable", id: int=0) -> int:
22883        r"""
22884
22885        Add a decision variable.
22886
22887        The id of the new variable is automatically generated.
22888
22889        Parameters
22890        ----------
22891        variable : pyAgrum.DiscreteVariable
22892        	the variable added by copy.
22893        id : int
22894        	the chosen id. If 0, the NodeGraphPart will choose.
22895
22896        Warnings
22897        --------
22898        give an id (not 0) should be reserved for rare and specific situations !!!
22899
22900        Returns
22901        -------
22902        int
22903            the id of the added variable.
22904
22905        Raises
22906        ------
22907        pyAgrum.DuplicateElement
22908        	If id(<>0) is already used
22909
22910        """
22911        return _pyAgrum.InfluenceDiagram_addDecisionNode(self, variable, id)
22912
22913    def addChanceNode(self, *args) -> int:
22914        r"""
22915
22916        Add a chance variable, it's associate node and it's CPT.
22917
22918        The id of the new variable is automatically generated.
22919
22920        Parameters
22921        ----------
22922        variable : pyAgrum.DiscreteVariable
22923        	the variable added by copy.
22924        id : int
22925        	the chosen id. If 0, the NodeGraphPart will choose.
22926
22927        Warnings
22928        --------
22929        give an id (not 0) should be reserved for rare and specific situations !!!
22930
22931        Returns
22932        -------
22933        int
22934            the id of the added variable.
22935
22936        Raises
22937        ------
22938        pyAgrum.DuplicateElement
22939        	If id(<>0) is already used
22940
22941        """
22942        return _pyAgrum.InfluenceDiagram_addChanceNode(self, *args)
22943
22944    def addUtilityNode(self, *args) -> int:
22945        r"""
22946
22947        Add a utility variable, it's associate node and it's UT.
22948
22949        The id of the new variable is automatically generated.
22950
22951        Parameters
22952        ----------
22953        variable : pyAgrum.DiscreteVariable
22954        	the variable added by copy
22955        id : int
22956        	the chosen id. If 0, the NodeGraphPart will choose
22957
22958        Warnings
22959        --------
22960        give an id (not 0) should be reserved for rare and specific situations !!!
22961
22962        Returns
22963        -------
22964        int
22965            the id of the added variable.
22966
22967        Raises
22968        ------
22969        pyAgrum.InvalidArgument
22970        	If variable has more than one label
22971        pyAgrum.DuplicateElement
22972        	If id(<>0) is already used
22973
22974        """
22975        return _pyAgrum.InfluenceDiagram_addUtilityNode(self, *args)
22976
22977    def erase(self, *args) -> None:
22978        r"""
22979
22980        Erase a Variable from the network and remove the variable from all his childs.
22981
22982        If no variable matches the id, then nothing is done.
22983
22984        Parameters
22985        ----------
22986        id : int
22987        	The id of the variable to erase.
22988        var : pyAgrum.DiscreteVariable
22989        	The reference on the variable to remove.
22990
22991        """
22992        return _pyAgrum.InfluenceDiagram_erase(self, *args)
22993
22994    def changeVariableName(self, *args) -> None:
22995        r"""
22996
22997        Parameters
22998        ----------
22999        id : int
23000        	the node Id
23001        new_name : str
23002        	the name of the variable
23003
23004        Raises
23005        ------
23006        pyAgrum.DuplicateLabel
23007        	If this name already exists
23008        pyAgrum.NotFound
23009        	If no nodes matches id.
23010
23011        """
23012        return _pyAgrum.InfluenceDiagram_changeVariableName(self, *args)
23013
23014    def addArc(self, *args) -> None:
23015        r"""
23016
23017        Add an arc in the ID, and update diagram's potential nodes cpt if necessary.
23018
23019        Parameters
23020        ----------
23021        tail : int
23022          the id of the tail node
23023        head : int
23024          the id of the head node
23025
23026        Raises
23027        ------
23028        pyAgrum.InvalidEdge
23029        	If arc.tail and/or arc.head are not in the ID.
23030        pyAgrum.InvalidEdge
23031        	If tail is a utility node
23032
23033        """
23034        return _pyAgrum.InfluenceDiagram_addArc(self, *args)
23035
23036    def eraseArc(self, *args) -> None:
23037        r"""
23038
23039        Removes an arc in the ID, and update diagram's potential nodes cpt if necessary.
23040
23041        If (tail, head) doesn't exist, the nothing happens.
23042
23043        Parameters
23044        ----------
23045        arc : pyAgrum.Arc
23046        	The arc to be removed.
23047        tail : int
23048          the id of the tail node
23049        head : int
23050          the id of the head node
23051
23052        """
23053        return _pyAgrum.InfluenceDiagram_eraseArc(self, *args)
23054
23055    def decisionOrderExists(self) -> bool:
23056        r"""
23057
23058        Returns
23059        -------
23060        bool
23061        	True if a directed path exist with all decision node
23062
23063        """
23064        return _pyAgrum.InfluenceDiagram_decisionOrderExists(self)
23065
23066    def getDecisionGraph(self) -> "pyAgrum.DAG":
23067        r"""
23068
23069        Returns
23070        -------
23071        pyAgrum.DAG
23072        	the temporal Graph.
23073
23074        """
23075        return _pyAgrum.InfluenceDiagram_getDecisionGraph(self)
23076
23077    def decisionOrder(self) -> "pyAgrum.YetUnWrapped":
23078        return _pyAgrum.InfluenceDiagram_decisionOrder(self)
23079
23080    def existsPathBetween(self, *args) -> bool:
23081        r"""
23082
23083        Returns
23084        -------
23085        bool
23086        	true if a path exists between two nodes.
23087
23088        """
23089        return _pyAgrum.InfluenceDiagram_existsPathBetween(self, *args)
23090
23091    def loadBIFXML(self, *args) -> bool:
23092        r"""
23093
23094        Load a BIFXML file.
23095
23096        Parameters
23097        ----------
23098        name : str
23099        	the name's file
23100
23101        Raises
23102        ------
23103        pyAgrum.IOError
23104        	If file not found
23105        pyAgrum.FatalError
23106        	If file is not valid
23107
23108        """
23109        return _pyAgrum.InfluenceDiagram_loadBIFXML(self, *args)
23110
23111    def saveBIFXML(self, name: str) -> None:
23112        r"""
23113
23114        Save the BayesNet in a BIFXML file.
23115
23116        Parameters
23117        ----------
23118        name : str
23119        	the file's name
23120
23121        """
23122        return _pyAgrum.InfluenceDiagram_saveBIFXML(self, name)
23123
23124    def names(self) -> object:
23125        r"""
23126
23127        Returns
23128        -------
23129        list
23130        	The names of the InfluenceDiagram variables
23131
23132        """
23133        return _pyAgrum.InfluenceDiagram_names(self)
23134
23135    def nodes(self) -> object:
23136        r"""
23137
23138        Returns
23139        -------
23140        set
23141            the set of ids
23142
23143        """
23144        return _pyAgrum.InfluenceDiagram_nodes(self)
23145
23146    def connectedComponents(self):
23147      """ connected components from a graph/BN
23148
23149      Compute the connected components of a pyAgrum's graph or Bayesian Network
23150      (more generally an object that has `nodes`, `children`/`parents` or `neighbours` methods)
23151
23152      The firstly visited node for each component is called a 'root' and is used as a key for the component.
23153      This root has been arbitrarily chosen during the algorithm.
23154
23155      Returns
23156      -------
23157      dict(int,Set[int])
23158        dict of connected components (as set of nodeIds (int)) with a nodeId (root) of each component as key.
23159
23160      """
23161      nodes=self.nodes()
23162      connected_components=dict()
23163
23164      def parcours(node,orig):
23165          cc={node}
23166          nodes.discard(node)
23167          if hasattr(self,'children'):
23168              for chi in self.children(node):
23169                  if chi!=orig:
23170                      if chi in nodes:
23171                          cc|=parcours(chi,node)
23172
23173          if hasattr(self,'parents'):
23174              for par in self.parents(node):
23175                  if par!=orig:
23176                      if par in nodes:
23177                          cc|=parcours(par,node)
23178
23179          if hasattr(self,'neighbours'):
23180              for nei in self.neighbours(node):
23181                  if nei!=orig:
23182                      if nei in nodes:
23183                          cc|=parcours(nei,node)
23184          return cc
23185
23186      while (len(nodes)>0):
23187          root=nodes.pop()
23188          connected_components[root]=parcours(root,None)
23189      return connected_components
23190
23191
23192    def arcs(self) -> object:
23193        r"""
23194
23195        Returns
23196        -------
23197        list:
23198        	the list of all the arcs in the Influence Diagram.
23199
23200        """
23201        return _pyAgrum.InfluenceDiagram_arcs(self)
23202
23203    def parents(self, norid: object) -> object:
23204        r"""
23205
23206        Parameters
23207        ----------
23208        id :
23209        	The id of the child node
23210
23211        Returns
23212        -------
23213        set
23214            the set of the parents ids.
23215
23216        """
23217        return _pyAgrum.InfluenceDiagram_parents(self, norid)
23218
23219    def children(self, norid: object) -> object:
23220        r"""
23221
23222        Parameters
23223        ----------
23224        id : int
23225          the id of the parent
23226
23227        Returns
23228        -------
23229        Set
23230        	the set of all the children
23231
23232        """
23233        return _pyAgrum.InfluenceDiagram_children(self, norid)
23234
23235    def family(self, norid: object) -> object:
23236        return _pyAgrum.InfluenceDiagram_family(self, norid)
23237
23238    def descendants(self, norid: object) -> object:
23239        return _pyAgrum.InfluenceDiagram_descendants(self, norid)
23240
23241    def ancestors(self, norid: object) -> object:
23242        return _pyAgrum.InfluenceDiagram_ancestors(self, norid)
23243
23244    def moralizedAncestralGraph(self, nodes: object) -> "pyAgrum.UndiGraph":
23245        return _pyAgrum.InfluenceDiagram_moralizedAncestralGraph(self, nodes)
23246
23247    def __repr__(self) -> str:
23248        return _pyAgrum.InfluenceDiagram___repr__(self)
23249
23250    def __str__(self) -> str:
23251        return _pyAgrum.InfluenceDiagram___str__(self)
23252
23253# Register InfluenceDiagram in _pyAgrum:
23254_pyAgrum.InfluenceDiagram_swigregister(InfluenceDiagram)
23255
23256def InfluenceDiagram_fastPrototype(dotlike: str, domainSize: int=2) -> "pyAgrum.InfluenceDiagram":
23257    r"""
23258
23259    Create an Influence Diagram with a dot-like syntax which specifies:
23260        - the structure 'a->b<-c;b->d;c<-e;'.
23261        - a prefix for the type of node (chance/decision/utiliy nodes):
23262
23263          - `a` : a chance node named 'a' (by default)
23264          - `$a` : a utility node named 'a'
23265          - `*a` : a decision node named 'a'
23266
23267        - the type of the variables with different syntax as postfix:
23268
23269          - by default, a variable is a pyAgrum.RangeVariable using the default domain size (second argument)
23270          - with `'a[10]'`, the variable is a pyAgrum.RangeVariable using 10 as domain size (from 0 to 9)
23271          - with `'a[3,7]'`, the variable is a pyAgrum.RangeVariable using a domainSize from 3 to 7
23272          - with `'a[1,3.14,5,6.2]'`, the variable is a pyAgrum.DiscretizedVariable using the given ticks (at least 3 values)
23273          - with `'a{top|middle|bottom}'`, the variable is a pyAgrum.LabelizedVariable using the given labels.
23274          - with 'a{-1|5|0|3}', the variable is a pyAgrum.IntegerVariable using the sorted given values.
23275
23276    Note
23277    ----
23278      - If the dot-like string contains such a specification more than once for a variable, the first specification will be used.
23279      - the potentials (probabilities, utilities) are randomly generated.
23280      - see also pyAgrum.fastID.
23281
23282    Examples
23283    --------
23284    >>> import pyAgrum as gum
23285    >>> bn=pyAgrum.fastID('A->B[1,3]<-*C{yes|No}->$D<-E[1,2.5,3.9]',6)
23286
23287    Parameters
23288    ----------
23289    dotlike : str
23290            the string containing the specification
23291    domainSize : int
23292            the default domain size for variables
23293
23294    Returns
23295    -------
23296    pyAgrum.InfluenceDiagram
23297            the resulting Influence Diagram
23298
23299    """
23300    return _pyAgrum.InfluenceDiagram_fastPrototype(dotlike, domainSize)
23301
23302class ShaferShenoyLIMIDInference(object):
23303    r"""
23304
23305    This inference considers the provided model as a LIMID rather than an influence diagram. It is an optimized
23306    implementation of the LIMID resolution algorithm. However an inference on a classical influence diagram can be performed
23307    by adding a assumption of the existence of the sequence of decision nodes to be solved, which also implies that the
23308    decision choices can have an impact on the rest of the sequence (Non Forgetting Assumption,
23309    cf. pyAgrum.ShaferShenoyLIMIDInference.addNoForgettingAssumption).
23310
23311    """
23312
23313    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
23314    __repr__ = _swig_repr
23315
23316    def __init__(self, infDiag: "InfluenceDiagram"):
23317        _pyAgrum.ShaferShenoyLIMIDInference_swiginit(self, _pyAgrum.new_ShaferShenoyLIMIDInference(infDiag))
23318
23319        self._model=infDiag
23320
23321
23322
23323    __swig_destroy__ = _pyAgrum.delete_ShaferShenoyLIMIDInference
23324
23325    def junctionTree(self) -> "pyAgrum.JunctionTree":
23326        val = _pyAgrum.ShaferShenoyLIMIDInference_junctionTree(self)
23327
23328        val._engine=self
23329
23330
23331        return val
23332
23333
23334    def clear(self) -> None:
23335        return _pyAgrum.ShaferShenoyLIMIDInference_clear(self)
23336
23337    def addNoForgettingAssumption(self, *args) -> None:
23338        return _pyAgrum.ShaferShenoyLIMIDInference_addNoForgettingAssumption(self, *args)
23339
23340    def hasNoForgettingAssumption(self) -> bool:
23341        return _pyAgrum.ShaferShenoyLIMIDInference_hasNoForgettingAssumption(self)
23342
23343    def reducedGraph(self) -> "pyAgrum.DAG":
23344        return _pyAgrum.ShaferShenoyLIMIDInference_reducedGraph(self)
23345
23346    def reversePartialOrder(self) -> "pyAgrum.YetUnWrapped":
23347        return _pyAgrum.ShaferShenoyLIMIDInference_reversePartialOrder(self)
23348
23349    def reducedLIMID(self) -> "pyAgrum.InfluenceDiagram":
23350        return _pyAgrum.ShaferShenoyLIMIDInference_reducedLIMID(self)
23351
23352    def isSolvable(self) -> bool:
23353        return _pyAgrum.ShaferShenoyLIMIDInference_isSolvable(self)
23354
23355    def optimalDecision(self, *args) -> "pyAgrum.Potential":
23356        r"""
23357
23358        Returns best choice for decision variable given in parameter ( based upon MEU criteria )
23359
23360        Parameters
23361        ----------
23362        decisionId : int,str
23363        	the id or name of the decision variable
23364
23365        Raises
23366        ------
23367        pyAgrum.OperationNotAllowed
23368        	If no inference have yet been made
23369        pyAgrum.InvalidNode
23370        	If node given in parmaeter is not a decision node
23371
23372        """
23373        return _pyAgrum.ShaferShenoyLIMIDInference_optimalDecision(self, *args)
23374
23375    def posteriorUtility(self, *args) -> "pyAgrum.Potential":
23376        return _pyAgrum.ShaferShenoyLIMIDInference_posteriorUtility(self, *args)
23377
23378    def setEvidence(self, evidces):
23379        """
23380        Erase all the evidences and apply addEvidence(key,value) for every pairs in evidces.
23381
23382        Parameters
23383        ----------
23384        evidces : dict
23385          a dict of evidences
23386
23387        Raises
23388        ------
23389        gum.InvalidArgument
23390            If one value is not a value for the node
23391        gum.InvalidArgument
23392            If the size of a value is different from the domain side of the node
23393        gum.FatalError
23394            If one value is a vector of 0s
23395        gum.UndefinedElement
23396            If one node does not belong to the influence diagram
23397        """
23398        if not isinstance(evidces, dict):
23399            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
23400        self.eraseAllEvidence()
23401        for k,v in evidces.items():
23402            self.addEvidence(k,v)
23403
23404
23405
23406    def updateEvidence(self, evidces):
23407        """
23408        Apply chgEvidence(key,value) for every pairs in evidces (or addEvidence).
23409
23410        Parameters
23411        ----------
23412        evidces : dict
23413          a dict of evidences
23414
23415        Raises
23416        ------
23417        gum.InvalidArgument
23418            If one value is not a value for the node
23419        gum.InvalidArgument
23420            If the size of a value is different from the domain side of the node
23421        gum.FatalError
23422            If one value is a vector of 0s
23423        gum.UndefinedElement
23424            If one node does not belong to the Bayesian network
23425        """
23426        if not isinstance(evidces, dict):
23427            raise TypeError("setEvidence parameter must be a dict, not %s"%(type(evidces)))
23428
23429        for k,v in evidces.items():
23430            if self.hasEvidence(k):
23431                self.chgEvidence(k,v)
23432            else:
23433                self.addEvidence(k,v)
23434
23435
23436
23437    def hardEvidenceNodes(self) -> object:
23438        return _pyAgrum.ShaferShenoyLIMIDInference_hardEvidenceNodes(self)
23439
23440    def softEvidenceNodes(self) -> object:
23441        return _pyAgrum.ShaferShenoyLIMIDInference_softEvidenceNodes(self)
23442
23443    def MEU(self, *args) -> object:
23444        r"""
23445
23446        Returns maximum expected utility obtained from inference.
23447
23448        Raises
23449        ------
23450        pyAgrum.OperationNotAllowed
23451        	If no inference have yet been made
23452
23453        """
23454        return _pyAgrum.ShaferShenoyLIMIDInference_MEU(self, *args)
23455
23456    def meanVar(self, *args) -> object:
23457        return _pyAgrum.ShaferShenoyLIMIDInference_meanVar(self, *args)
23458
23459    def makeInference(self) -> None:
23460        r"""
23461
23462        Makes the inference.
23463
23464        """
23465        return _pyAgrum.ShaferShenoyLIMIDInference_makeInference(self)
23466
23467    def posterior(self, *args) -> "pyAgrum.Potential":
23468        return _pyAgrum.ShaferShenoyLIMIDInference_posterior(self, *args)
23469
23470    def addEvidence(self, *args) -> None:
23471        return _pyAgrum.ShaferShenoyLIMIDInference_addEvidence(self, *args)
23472
23473    def chgEvidence(self, *args) -> None:
23474        return _pyAgrum.ShaferShenoyLIMIDInference_chgEvidence(self, *args)
23475
23476    def hasEvidence(self, *args) -> bool:
23477        return _pyAgrum.ShaferShenoyLIMIDInference_hasEvidence(self, *args)
23478
23479    def eraseAllEvidence(self) -> None:
23480        r"""
23481
23482        Removes all the evidence entered into the diagram.
23483
23484        """
23485        return _pyAgrum.ShaferShenoyLIMIDInference_eraseAllEvidence(self)
23486
23487    def eraseEvidence(self, *args) -> None:
23488        r"""
23489
23490        Parameters
23491        ----------
23492        evidence : pyAgrum.Potential
23493        	the evidence to remove
23494
23495        Raises
23496        ------
23497        pyAgrum.IndexError
23498        	If the evidence does not belong to the influence diagram
23499
23500        """
23501        return _pyAgrum.ShaferShenoyLIMIDInference_eraseEvidence(self, *args)
23502
23503    def hasHardEvidence(self, nodeName: str) -> bool:
23504        return _pyAgrum.ShaferShenoyLIMIDInference_hasHardEvidence(self, nodeName)
23505
23506    def hasSoftEvidence(self, *args) -> bool:
23507        return _pyAgrum.ShaferShenoyLIMIDInference_hasSoftEvidence(self, *args)
23508
23509    def nbrEvidence(self) -> int:
23510        return _pyAgrum.ShaferShenoyLIMIDInference_nbrEvidence(self)
23511
23512    def nbrHardEvidence(self) -> int:
23513        return _pyAgrum.ShaferShenoyLIMIDInference_nbrHardEvidence(self)
23514
23515    def nbrSoftEvidence(self) -> int:
23516        return _pyAgrum.ShaferShenoyLIMIDInference_nbrSoftEvidence(self)
23517
23518    def influenceDiagram(self) -> "pyAgrum.InfluenceDiagram":
23519        r"""
23520
23521        Returns a constant reference over the InfluenceDiagram on which this class work.
23522
23523        Returns
23524        -------
23525        pyAgrum.InfluenceDiagram
23526        	the InfluenceDiagram on which this class work
23527
23528        """
23529        return _pyAgrum.ShaferShenoyLIMIDInference_influenceDiagram(self)
23530
23531# Register ShaferShenoyLIMIDInference in _pyAgrum:
23532_pyAgrum.ShaferShenoyLIMIDInference_swigregister(ShaferShenoyLIMIDInference)
23533
23534class BNLearner(object):
23535    r"""
23536
23537    BNLearner(filename,inducedTypes=True) -> BNLearner
23538        Parameters:
23539            * **filename** (*str*) -- the file to learn from
23540            * **inducedTypes** (*Bool*) -- whether BNLearner should try to automatically find the type of each variable
23541
23542    BNLearner(filename,src) -> BNLearner
23543        Parameters:
23544            * **filename** (*str*) -- the file to learn from
23545            * **src** (*pyAgrum.BayesNet*) -- the Bayesian network used to find those modalities
23546
23547    BNLearner(learner) -> BNLearner
23548        Parameters:
23549            * **learner** (*pyAgrum.BNLearner*) -- the BNLearner to copy
23550
23551    """
23552
23553    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
23554
23555    def __init__(self, *args):
23556        _pyAgrum.BNLearner_swiginit(self, _pyAgrum.new_BNLearner(*args))
23557    __swig_destroy__ = _pyAgrum.delete_BNLearner
23558
23559    def learnBN(self) -> "pyAgrum.BayesNet":
23560        r"""
23561
23562        learn a BayesNet from a file (must have read the db before)
23563
23564        Returns
23565        -------
23566        pyAgrum.BayesNet
23567        	the learned BayesNet
23568
23569        """
23570        return _pyAgrum.BNLearner_learnBN(self)
23571
23572    def learnParameters(self, *args) -> "pyAgrum.BayesNet":
23573        r"""
23574
23575        learns a BN (its parameters) when its structure is known.
23576
23577        Parameters
23578        ----------
23579        dag : pyAgrum.DAG
23580        bn : pyAgrum.BayesNet
23581        take_into_account_score : bool
23582        	The dag passed in argument may have been learnt from a structure learning. In this case, if the score used to learn the structure has an implicit apriori (like K2 which has a 1-smoothing apriori), it is important to also take into account this implicit apriori for parameter learning. By default, if a score exists, we will learn parameters by taking into account the apriori specified by methods useAprioriXXX () + the implicit apriori of the score, else we just take into account the apriori specified by useAprioriXXX ()
23583
23584        Returns
23585        -------
23586        pyAgrum.BayesNet
23587        	the learned BayesNet
23588
23589        Raises
23590        ------
23591        pyAgrum.MissingVariableInDatabase
23592        	If a variable of the BN is not found in the database
23593        pyAgrum.UnknownLabelInDatabase
23594        	If a label is found in the database that do not correspond to the variable
23595
23596        """
23597        return _pyAgrum.BNLearner_learnParameters(self, *args)
23598
23599    def __repr__(self) -> str:
23600        return _pyAgrum.BNLearner___repr__(self)
23601
23602    def __str__(self) -> str:
23603        return _pyAgrum.BNLearner___str__(self)
23604
23605    def chi2(self, *args) -> object:
23606        r"""
23607
23608        chi2 computes the chi2 statistic and pvalue for two columns, given a list of other columns.
23609
23610
23611        Parameters
23612        ----------
23613        name1: str
23614        	the name of the first column
23615
23616        name2 : str
23617        	the name of the second column
23618
23619        knowing : [str]
23620        	the list of names of conditioning columns
23621
23622        Returns
23623        -------
23624        statistic,pvalue
23625        	the chi2 statistic and the associated p-value as a Tuple
23626
23627        """
23628        return _pyAgrum.BNLearner_chi2(self, *args)
23629
23630    def G2(self, *args) -> object:
23631        r"""
23632
23633        G2 computes the G2 statistic and pvalue for two columns, given a list of other columns.
23634
23635
23636        Parameters
23637        ----------
23638        name1: str
23639        	the name of the first column
23640
23641        name2 : str
23642        	the name of the second column
23643
23644        knowing : [str]
23645        	the list of names of conditioning columns
23646
23647        Returns
23648        -------
23649        statistic,pvalue
23650        	the G2 statistic and the associated p-value as a Tuple
23651
23652        """
23653        return _pyAgrum.BNLearner_G2(self, *args)
23654
23655    def state(self) -> object:
23656        return _pyAgrum.BNLearner_state(self)
23657
23658    def pseudoCount(self,vars):
23659        """ access to pseudo-count (priors taken into account)
23660
23661        Parameters
23662        ----------
23663        vars : list[str]
23664          a list of name of vars to add in the pseudo_count
23665
23666        Returns
23667        -------
23668        a Potential containing this pseudo-counts
23669        """
23670        p=Potential()
23671        lv=list()
23672        for i in vars:
23673            if type(i) is str:
23674                name=i
23675            else:
23676                name=self.nameFromId(i)
23677            p.add(RangeVariable(name,name,0,self.domainSize(i)-1))
23678            lv.append(name)
23679        p.fillWith(self.rawPseudoCount(lv))
23680        return p
23681
23682
23683    def setVerbosity(self, v: bool) -> None:
23684        r"""
23685
23686        Parameters
23687        ----------
23688        v : bool
23689                verbosity
23690
23691        """
23692        return _pyAgrum.BNLearner_setVerbosity(self, v)
23693
23694    def setEpsilon(self, eps: float) -> None:
23695        r"""
23696
23697        Parameters
23698        ----------
23699        eps : float
23700        	the epsilon we want to use
23701
23702        Raises
23703        ------
23704        pyAgrum.OutOfBounds
23705        	If eps<0
23706
23707        """
23708        return _pyAgrum.BNLearner_setEpsilon(self, eps)
23709
23710    def setMinEpsilonRate(self, rate: float) -> None:
23711        r"""
23712
23713        Parameters
23714        ----------
23715        rate : float
23716        	the minimal epsilon rate
23717
23718        """
23719        return _pyAgrum.BNLearner_setMinEpsilonRate(self, rate)
23720
23721    def setMaxIter(self, max: int) -> None:
23722        r"""
23723
23724        Parameters
23725        ----------
23726        max : int
23727        	the maximum number of iteration
23728
23729        Raises
23730        ------
23731        pyAgrum.OutOfBounds
23732        	If max <= 1
23733
23734        """
23735        return _pyAgrum.BNLearner_setMaxIter(self, max)
23736
23737    def setMaxTime(self, timeout: float) -> None:
23738        r"""
23739
23740        Parameters
23741        ----------
23742        tiemout : float
23743        	stopping criterion on timeout (in seconds)
23744
23745        Raises
23746        ------
23747        pyAgrum.OutOfBounds
23748        	If timeout<=0.0
23749
23750        """
23751        return _pyAgrum.BNLearner_setMaxTime(self, timeout)
23752
23753    def setPeriodSize(self, p: int) -> None:
23754        r"""
23755
23756        Parameters
23757        ----------
23758        p : int
23759        	number of samples between 2 stopping
23760
23761        Raises
23762        ------
23763        pyAgrum.OutOfBounds
23764        	If p<1
23765
23766        """
23767        return _pyAgrum.BNLearner_setPeriodSize(self, p)
23768
23769    def verbosity(self) -> bool:
23770        r"""
23771
23772        Returns
23773        -------
23774        bool
23775        	True if the verbosity is enabled
23776
23777        """
23778        return _pyAgrum.BNLearner_verbosity(self)
23779
23780    def epsilon(self) -> float:
23781        r"""
23782
23783        Returns
23784        -------
23785        float
23786        	the value of epsilon
23787
23788        """
23789        return _pyAgrum.BNLearner_epsilon(self)
23790
23791    def minEpsilonRate(self) -> float:
23792        r"""
23793
23794        Returns
23795        -------
23796        float
23797        	the value of the minimal epsilon rate
23798
23799        """
23800        return _pyAgrum.BNLearner_minEpsilonRate(self)
23801
23802    def maxIter(self) -> int:
23803        r"""
23804
23805        Returns
23806        -------
23807        int
23808        	the criterion on number of iterations
23809
23810        """
23811        return _pyAgrum.BNLearner_maxIter(self)
23812
23813    def maxTime(self) -> float:
23814        r"""
23815
23816        Returns
23817        -------
23818        float
23819        	the timeout(in seconds)
23820
23821        """
23822        return _pyAgrum.BNLearner_maxTime(self)
23823
23824    def periodSize(self) -> int:
23825        r"""
23826
23827        Returns
23828        -------
23829        int
23830        	the number of samples between 2 stopping
23831
23832        Raises
23833        ------
23834        pyAgrum.OutOfBounds
23835        	If p<1
23836
23837        """
23838        return _pyAgrum.BNLearner_periodSize(self)
23839
23840    def nbrIterations(self) -> int:
23841        r"""
23842
23843        Returns
23844        -------
23845        int
23846        	the number of iterations
23847
23848        """
23849        return _pyAgrum.BNLearner_nbrIterations(self)
23850
23851    def currentTime(self) -> float:
23852        r"""
23853
23854        Returns
23855        -------
23856        float
23857        	get the current running time in second (float)
23858
23859        """
23860        return _pyAgrum.BNLearner_currentTime(self)
23861
23862    def messageApproximationScheme(self) -> str:
23863        r"""
23864
23865        Returns
23866        -------
23867        str
23868        	the approximation scheme message
23869
23870        """
23871        return _pyAgrum.BNLearner_messageApproximationScheme(self)
23872
23873    def history(self) -> List[float]:
23874        r"""
23875
23876        Returns
23877        -------
23878        tuple
23879        	the scheme history
23880
23881        Raises
23882        ------
23883        pyAgrum.OperationNotAllowed
23884        	If the scheme did not performed or if verbosity is set to false
23885
23886        """
23887        return _pyAgrum.BNLearner_history(self)
23888
23889    def _asIApproximationSchemeConfiguration(self) -> "pyAgrum.YetUnWrapped":
23890        return _pyAgrum.BNLearner__asIApproximationSchemeConfiguration(self)
23891
23892    def learnDAG(self) -> "pyAgrum.DAG":
23893        r"""
23894
23895        learn a structure from a file
23896
23897        Returns
23898        -------
23899        pyAgrum.DAG
23900        	the learned DAG
23901
23902        """
23903        return _pyAgrum.BNLearner_learnDAG(self)
23904
23905    def names(self) -> List[str]:
23906        r"""
23907
23908        Returns
23909        -------
23910        List[str]
23911        	the names of the variables in the database
23912
23913        """
23914        return _pyAgrum.BNLearner_names(self)
23915
23916    def idFromName(self, var_name: str) -> int:
23917        r"""
23918
23919        Parameters
23920        ----------
23921        var_names : str
23922        	a variable's name
23923
23924        Returns
23925        -------
23926        int
23927        	the column id corresponding to a variable name
23928
23929        Raises
23930        ------
23931        pyAgrum.MissingVariableInDatabase
23932        	If a variable of the BN is not found in the database.
23933
23934        """
23935        return _pyAgrum.BNLearner_idFromName(self, var_name)
23936
23937    def nameFromId(self, id: int) -> str:
23938        r"""
23939
23940        Parameters
23941        ----------
23942        id
23943        	a node id
23944
23945        Returns
23946        -------
23947        str
23948        	the variable's name
23949
23950        """
23951        return _pyAgrum.BNLearner_nameFromId(self, id)
23952
23953    def useScoreAIC(self) -> None:
23954        return _pyAgrum.BNLearner_useScoreAIC(self)
23955
23956    def useScoreBD(self) -> None:
23957        return _pyAgrum.BNLearner_useScoreBD(self)
23958
23959    def useScoreBDeu(self) -> None:
23960        return _pyAgrum.BNLearner_useScoreBDeu(self)
23961
23962    def useScoreBIC(self) -> None:
23963        return _pyAgrum.BNLearner_useScoreBIC(self)
23964
23965    def useScoreK2(self) -> None:
23966        return _pyAgrum.BNLearner_useScoreK2(self)
23967
23968    def useScoreLog2Likelihood(self) -> None:
23969        return _pyAgrum.BNLearner_useScoreLog2Likelihood(self)
23970
23971    def setDatabaseWeight(self, new_weight: float) -> None:
23972        r"""
23973
23974        Set the database weight which is given as an equivalent sample size.
23975
23976        Parameters
23977        ----------
23978        weight : float
23979        	the database weight
23980
23981        """
23982        return _pyAgrum.BNLearner_setDatabaseWeight(self, new_weight)
23983
23984    def setRecordWeight(self, i: int, weight: float) -> None:
23985        return _pyAgrum.BNLearner_setRecordWeight(self, i, weight)
23986
23987    def databaseWeight(self) -> float:
23988        return _pyAgrum.BNLearner_databaseWeight(self)
23989
23990    def recordWeight(self, i: int) -> float:
23991        return _pyAgrum.BNLearner_recordWeight(self, i)
23992
23993    def useNoApriori(self) -> None:
23994        return _pyAgrum.BNLearner_useNoApriori(self)
23995
23996    def useAprioriSmoothing(self, *args) -> None:
23997        return _pyAgrum.BNLearner_useAprioriSmoothing(self, *args)
23998
23999    def useAprioriDirichlet(self, *args) -> None:
24000        return _pyAgrum.BNLearner_useAprioriDirichlet(self, *args)
24001
24002    def useAprioriBDeu(self, *args) -> None:
24003        r"""
24004
24005        The BDeu apriori adds weight to all the cells of the counting tables.
24006        In other words, it adds weight rows in the database with equally probable
24007        values.
24008
24009        Parameters
24010        ----------
24011        weight : float
24012        	the apriori weight
24013
24014        """
24015        return _pyAgrum.BNLearner_useAprioriBDeu(self, *args)
24016
24017    def useGreedyHillClimbing(self) -> None:
24018        return _pyAgrum.BNLearner_useGreedyHillClimbing(self)
24019
24020    def useLocalSearchWithTabuList(self, *args) -> None:
24021        r"""
24022
24023        Indicate that we wish to use a local search with tabu list
24024
24025        Parameters
24026        ----------
24027        tabu_size : int
24028                The size of the tabu list
24029
24030        nb_decrease : int
24031                The max number of changes decreasing the score consecutively that we allow to apply
24032
24033        """
24034        return _pyAgrum.BNLearner_useLocalSearchWithTabuList(self, *args)
24035
24036    def useK2(self, *args) -> None:
24037        r"""
24038
24039        Indicate to use the K2 algorithm (which needs a total ordering of the variables).
24040
24041        Parameters
24042        ----------
24043        order : list[int or str]
24044              sequences of (ids or name)
24045
24046        """
24047        return _pyAgrum.BNLearner_useK2(self, *args)
24048
24049    def setMaxIndegree(self, max_indegree: int) -> None:
24050        return _pyAgrum.BNLearner_setMaxIndegree(self, max_indegree)
24051
24052    def setSliceOrder(self, *args) -> None:
24053        r"""
24054
24055        Set a partial order on the nodes.
24056
24057        Parameters
24058        ----------
24059        l : list
24060                a list of sequences (composed of ids of rows or string)
24061
24062        """
24063        return _pyAgrum.BNLearner_setSliceOrder(self, *args)
24064
24065    def setPossibleSkeleton(self, skeleton: "pyAgrum.UndiGraph") -> None:
24066        return _pyAgrum.BNLearner_setPossibleSkeleton(self, skeleton)
24067
24068    def addPossibleEdge(self, *args) -> None:
24069        return _pyAgrum.BNLearner_addPossibleEdge(self, *args)
24070
24071    def erasePossibleEdge(self, *args) -> None:
24072        r"""
24073
24074        Allow the 2 arcs to be added if necessary.
24075
24076        Parameters
24077        ----------
24078        arc : pyAgrum
24079        	an arc
24080        head :
24081        	a variable's id (int)
24082        tail :
24083        	a variable's id (int)
24084        head :
24085        	a variable's name (str)
24086        tail :
24087        	a variable's name (str)
24088
24089        """
24090        return _pyAgrum.BNLearner_erasePossibleEdge(self, *args)
24091
24092    def addForbiddenArc(self, *args) -> None:
24093        r"""
24094
24095        The arc in parameters won't be added.
24096
24097        Parameters
24098        ----------
24099        arc : pyAgrum.Arc
24100        	an arc
24101        head :
24102        	a variable's id (int)
24103        tail :
24104        	a variable's id (int)
24105        head :
24106        	a variable's name (str)
24107        tail :
24108        	a variable's name (str)
24109
24110        """
24111        return _pyAgrum.BNLearner_addForbiddenArc(self, *args)
24112
24113    def eraseForbiddenArc(self, *args) -> None:
24114        r"""
24115
24116        Allow the arc to be added if necessary.
24117
24118        Parameters
24119        ----------
24120        arc : pyAgrum
24121        	an arc
24122        head :
24123        	a variable's id (int)
24124        tail :
24125        	a variable's id (int)
24126        head :
24127        	a variable's name (str)
24128        tail :
24129        	a variable's name (str)
24130
24131        """
24132        return _pyAgrum.BNLearner_eraseForbiddenArc(self, *args)
24133
24134    def addMandatoryArc(self, *args) -> None:
24135        r"""
24136
24137        Allow to add prior structural knowledge.
24138
24139        Parameters
24140        ----------
24141        arc : pyAgrum.Arc
24142        	an arc
24143        head :
24144        	a variable's id (int)
24145        tail :
24146        	a variable's id (int)
24147        head :
24148        	a variable's name (str)
24149        tail :
24150        	a variable's name (str)
24151
24152        Raises
24153        ------
24154        pyAgrum.InvalidDirectedCycle
24155        	If the added arc creates a directed cycle in the DAG
24156
24157        """
24158        return _pyAgrum.BNLearner_addMandatoryArc(self, *args)
24159
24160    def eraseMandatoryArc(self, *args) -> None:
24161        r"""
24162
24163        Parameters
24164        ----------
24165        arc : pyAgrum
24166        	an arc
24167        head :
24168        	a variable's id (int)
24169        tail :
24170        	a variable's id (int)
24171        head :
24172        	a variable's name (str)
24173        tail :
24174        	a variable's name (str)
24175
24176        """
24177        return _pyAgrum.BNLearner_eraseMandatoryArc(self, *args)
24178
24179    def useEM(self, epsilon: float) -> None:
24180        r"""
24181
24182        Indicates if we use EM for parameter learning.
24183
24184        Parameters
24185        ----------
24186        epsilon : float
24187        	if epsilon=0.0 then EM is not used
24188        	if epsilon>0 then EM is used and stops when the sum of the cumulative squared error on parameters is les than epsilon.
24189
24190        """
24191        return _pyAgrum.BNLearner_useEM(self, epsilon)
24192
24193    def hasMissingValues(self) -> bool:
24194        r"""
24195
24196        Indicates whether there are missing values in the database.
24197
24198        Returns
24199        -------
24200        bool
24201            True if there are some missing values in the database.
24202
24203        """
24204        return _pyAgrum.BNLearner_hasMissingValues(self)
24205
24206    def logLikelihood(self, *args) -> float:
24207        r"""
24208
24209        logLikelihood computes the log-likelihood for the columns in vars, given the columns in the list knowing (optional)
24210
24211
24212        Parameters
24213        ----------
24214        vars: List[str]
24215        	the name of the columns of interest
24216
24217        knowing : List[str]
24218        	the (optional) list of names of conditioning columns
24219
24220        Returns
24221        -------
24222        float
24223        	the log-likelihood (base 2)
24224
24225        """
24226        return _pyAgrum.BNLearner_logLikelihood(self, *args)
24227
24228    def rawPseudoCount(self, *args) -> List[float]:
24229        return _pyAgrum.BNLearner_rawPseudoCount(self, *args)
24230
24231    def nbRows(self) -> int:
24232        r"""
24233
24234        Return the number of row in the database
24235
24236
24237        Returns
24238        -------
24239        int
24240        	the number of rows in the database
24241
24242        """
24243        return _pyAgrum.BNLearner_nbRows(self)
24244
24245    def nbCols(self) -> int:
24246        r"""
24247
24248        Return the nimber of columns in the database
24249
24250
24251        Returns
24252        -------
24253        int
24254        	the number of columns in the database
24255
24256        """
24257        return _pyAgrum.BNLearner_nbCols(self)
24258
24259    def domainSize(self, *args) -> int:
24260        return _pyAgrum.BNLearner_domainSize(self, *args)
24261
24262    def setInitialDAG(self, g: "DAG") -> None:
24263        r"""
24264
24265        Parameters
24266        ----------
24267        dag : pyAgrum.DAG
24268        	an initial DAG structure
24269
24270        """
24271        return _pyAgrum.BNLearner_setInitialDAG(self, g)
24272
24273    def use3off2(self) -> None:
24274        r"""
24275
24276        Indicate that we wish to use 3off2.
24277
24278        """
24279        return _pyAgrum.BNLearner_use3off2(self)
24280
24281    def useMIIC(self) -> None:
24282        r"""
24283
24284        Indicate that we wish to use MIIC.
24285
24286        """
24287        return _pyAgrum.BNLearner_useMIIC(self)
24288
24289    def useNMLCorrection(self) -> None:
24290        r"""
24291
24292        Indicate that we wish to use the NML correction for 3off2 or MIIC
24293
24294        """
24295        return _pyAgrum.BNLearner_useNMLCorrection(self)
24296
24297    def useMDLCorrection(self) -> None:
24298        r"""
24299
24300        Indicate that we wish to use the MDL correction for 3off2 or MIIC
24301
24302        """
24303        return _pyAgrum.BNLearner_useMDLCorrection(self)
24304
24305    def useNoCorrection(self) -> None:
24306        r"""
24307
24308        Indicate that we wish to use the NoCorr correction for 3off2 or MIIC
24309
24310        """
24311        return _pyAgrum.BNLearner_useNoCorrection(self)
24312
24313    def latentVariables(self, *args) -> List[Tuple[int,int]]:
24314        r"""
24315
24316        Warnings
24317        --------
24318        learner must be using 3off2 or MIIC algorithm
24319
24320        Returns
24321        -------
24322        list
24323        	the list of latent variables
24324
24325        """
24326        return _pyAgrum.BNLearner_latentVariables(self, *args)
24327
24328    def learnMixedStructure(self) -> "pyAgrum.MixedGraph":
24329        r"""
24330
24331        Warnings
24332        --------
24333        learner must be using 3off2 or MIIC algorithm
24334
24335        Returns
24336        -------
24337        pyAgrum.EssentialGraph
24338        	the learned structure as an EssentialGraph
24339
24340        """
24341        val = _pyAgrum.BNLearner_learnMixedStructure(self)
24342
24343        bn=BayesNet()
24344        for i in range(len(self.names())):
24345          bn.add(self.nameFromId(i),2)
24346        ge=EssentialGraph(bn,val)
24347        ge._bn=bn
24348        return ge
24349
24350
24351        return val
24352
24353
24354# Register BNLearner in _pyAgrum:
24355_pyAgrum.BNLearner_swigregister(BNLearner)
24356
24357class BNDatabaseGenerator(object):
24358    r"""
24359
24360    BNDatabaseGenerator is used to easily generate databases from a pyAgrum.BayesNet.
24361
24362    Parameters
24363    ----------
24364    bn: pyAgrum.BayesNet
24365      the Bayesian network used to generate data.
24366
24367    """
24368
24369    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
24370    __repr__ = _swig_repr
24371
24372    def __init__(self, bn: "pyAgrum.BayesNet"):
24373        r"""
24374
24375        BNDatabaseGenerator is used to easily generate databases from a pyAgrum.BayesNet.
24376
24377        Parameters
24378        ----------
24379        bn: pyAgrum.BayesNet
24380          the Bayesian network used to generate data.
24381
24382        """
24383        _pyAgrum.BNDatabaseGenerator_swiginit(self, _pyAgrum.new_BNDatabaseGenerator(bn))
24384    __swig_destroy__ = _pyAgrum.delete_BNDatabaseGenerator
24385
24386    def drawSamples(self, nbSamples: int) -> float:
24387        return _pyAgrum.BNDatabaseGenerator_drawSamples(self, nbSamples)
24388
24389    def toCSV(self, *args) -> None:
24390        return _pyAgrum.BNDatabaseGenerator_toCSV(self, *args)
24391
24392    def toDatabaseTable(self, useLabels: bool=True) -> "pyAgrum.YetUnWrapped":
24393        return _pyAgrum.BNDatabaseGenerator_toDatabaseTable(self, useLabels)
24394
24395    def database(self) -> "pyAgrum.YetUnWrapped":
24396        return _pyAgrum.BNDatabaseGenerator_database(self)
24397
24398    def setVarOrder(self, *args) -> None:
24399        return _pyAgrum.BNDatabaseGenerator_setVarOrder(self, *args)
24400
24401    def setVarOrderFromCSV(self, *args) -> None:
24402        return _pyAgrum.BNDatabaseGenerator_setVarOrderFromCSV(self, *args)
24403
24404    def setTopologicalVarOrder(self) -> None:
24405        return _pyAgrum.BNDatabaseGenerator_setTopologicalVarOrder(self)
24406
24407    def setAntiTopologicalVarOrder(self) -> None:
24408        return _pyAgrum.BNDatabaseGenerator_setAntiTopologicalVarOrder(self)
24409
24410    def setRandomVarOrder(self) -> None:
24411        return _pyAgrum.BNDatabaseGenerator_setRandomVarOrder(self)
24412
24413    def varOrder(self) -> "pyAgrum.YetUnWrapped":
24414        return _pyAgrum.BNDatabaseGenerator_varOrder(self)
24415
24416    def varOrderNames(self) -> List[str]:
24417        return _pyAgrum.BNDatabaseGenerator_varOrderNames(self)
24418
24419    def log2likelihood(self) -> float:
24420        return _pyAgrum.BNDatabaseGenerator_log2likelihood(self)
24421
24422# Register BNDatabaseGenerator in _pyAgrum:
24423_pyAgrum.BNDatabaseGenerator_swigregister(BNDatabaseGenerator)
24424
24425
24426def statsObj() -> None:
24427    return _pyAgrum.statsObj()
24428
24429
24430