aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
MarkovBlanket.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Class building the markovBlanket from a DAGmodel and a node name
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27  *
28  */
29 #ifndef GUM_MARKOVBLANKET_H
30 #define GUM_MARKOVBLANKET_H
31 
32 #include <agrum/tools/graphicalModels/DAGmodel.h>
33 #include <agrum/tools/graphs/diGraph.h>
34 #include <agrum/tools/graphs/graphElements.h>
35 
36 namespace gum {
37 
38  /**
39 * @class MarkovBlanket
40 * @headerfile MarkovBlanket.h <agrum/BN/algorithms/MarkovBlanket.h>
41  * @brief Class building the markov Blanket from a BN and a nodeName.
42  * @ingroup bn_group
43 
44  * The main goal of this class is to build and to encapsulate the DiGraph which
45  represents the Markov Blanket.
46  *
47  */
48  class MarkovBlanket {
49  public:
50  MarkovBlanket(const DAGmodel& m, NodeId n, int level = 1);
51  MarkovBlanket(const DAGmodel& m, const std::string& name, int level = 1);
52 
53  ~MarkovBlanket();
54 
55  /// @return a copy of the graph
56  DAG dag();
57 
58  // @return a dot representation of this MarkovBlanket
59  // node of interest is in red
60  // special arcs (not used during the construction of the Markov Blanket) are in
61  // grey
62  std::string toDot() const;
63 
64  /// wrapping @ref DAG::parents(id)
65  const NodeSet& parents(NodeId id) const;
66 
67  /// wrapping @ref DAG::children(id)
68  const NodeSet& children(NodeId id) const;
69 
70  /// wrapping @ref DAG::parents(ids)
71  NodeSet parents(const NodeSet& ids) const;
72 
73  /// wrapping @ref DAG::children(ids)
74  NodeSet children(const NodeSet& ids) const;
75 
76  /// wrapping @ref DAG::sizeArcs()
77  Size sizeArcs() const;
78 
79  /// wrapping @ref DAG::arcs()
80  const ArcSet& arcs() const;
81 
82  /// wrapping @ref DAG::sizeNodes()
83  Size sizeNodes() const;
84 
85  /// wrapping @ref DAG::size()
86  Size size() const;
87 
88  /// wrapping @ref DAG::nodes()
89  const NodeGraphPart& nodes() const;
90 
91  /// @return true if all the named node are the same and all the named arcs are
92  /// the same
93  bool hasSameStructure(const DAGmodel& other);
94 
95  private:
96  bool _buildMarkovBlanket_(const NodeId id);
97 
98  const DAGmodel& _model_;
100  const NodeId _node_;
102  };
103 } // namespace gum
104 
105 #ifndef GUM_NO_INLINE
106 # include <agrum/BN/algorithms/MarkovBlanket_inl.h>
107 #endif // GUM_NOINLINE
108 
109 #endif // GUM_MARKOVBLANKET_H
const DAGmodel & _model_
Definition: MarkovBlanket.h:98
Size sizeArcs() const
wrapping DAG::sizeArcs()
NodeSet children(const NodeSet &ids) const
wrapping DAG::children(ids)
Size sizeNodes() const
wrapping DAG::sizeNodes()
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
Class building the markov Blanket from a BN and a nodeName.
Definition: MarkovBlanket.h:48
const NodeId _node_
const NodeSet & children(NodeId id) const
wrapping DAG::children(id)
std::string toDot() const
Size size() const
wrapping DAG::size()
bool hasSameStructure(const DAGmodel &other)
NodeSet parents(const NodeSet &ids) const
wrapping DAG::parents(ids)
const ArcSet & arcs() const
wrapping DAG::arcs()
const NodeSet & parents(NodeId id) const
wrapping DAG::parents(id)
MarkovBlanket(const DAGmodel &m, NodeId n, int level=1)
MarkovBlanket(const DAGmodel &m, const std::string &name, int level=1)
bool _buildMarkovBlanket_(const NodeId id)
const NodeGraphPart & nodes() const
wrapping DAG::nodes()