aGrUM  0.15.1
BayesNetFragment.h
Go to the documentation of this file.
1 
30 #ifndef GUM_BAYES_NET_FRAGMENT_H
31 #define GUM_BAYES_NET_FRAGMENT_H
32 
33 #include <agrum/agrum.h>
34 
35 #include <agrum/BN/IBayesNet.h>
37 
38 #include <agrum/BN/BayesNet.h>
39 
40 namespace gum {
72  template < typename GUM_SCALAR >
74  : public IBayesNet< GUM_SCALAR >
75  , public gum::DiGraphListener {
76  private:
79 
83 
84  public:
87  BayesNetFragment() = delete;
88  BayesNetFragment(const BayesNetFragment< GUM_SCALAR >& fragment) = delete;
90 
91  explicit BayesNetFragment(const IBayesNet< GUM_SCALAR >& bn);
92 
93  virtual ~BayesNetFragment();
95 
98 
100 
102  virtual void whenNodeAdded(const void* src, NodeId id) noexcept override;
103 
105 
107  virtual void whenNodeDeleted(const void* src, NodeId id) noexcept override;
108 
110 
113  virtual void
114  whenArcAdded(const void* src, NodeId from, NodeId to) noexcept override;
115 
117 
120  virtual void
121  whenArcDeleted(const void* src, NodeId from, NodeId to) noexcept override;
123 
126 
132  virtual const Potential< GUM_SCALAR >& cpt(NodeId varId) const override;
133 
137  virtual const VariableNodeMap& variableNodeMap() const override;
138 
144  virtual const DiscreteVariable& variable(NodeId id) const override;
145 
151  virtual NodeId nodeId(const DiscreteVariable& var) const override;
152 
158  virtual NodeId idFromName(const std::string& name) const override;
159 
165  virtual const DiscreteVariable&
166  variableFromName(const std::string& name) const override;
167 
172  virtual std::string toDot() const override;
173 
175 
178 
182  bool isInstalledNode(NodeId id) const noexcept;
183 
190  void installNode(NodeId id);
191 
198  void installAscendants(NodeId id);
199 
205  void uninstallNode(NodeId id) noexcept;
206 
217  void installMarginal(NodeId id, const Potential< GUM_SCALAR >* pot);
218 
233  void installCPT(NodeId id, const Potential< GUM_SCALAR >* pot);
234 
242  void uninstallCPT(NodeId id) noexcept;
243 
250  bool checkConsistency(NodeId id) const;
251 
255  bool checkConsistency() const noexcept;
256 
258 
259  using IBayesNet< GUM_SCALAR >::nodes;
260  using IBayesNet< GUM_SCALAR >::dag;
261 
262  protected:
263  // remove an arc
264  void _uninstallArc(NodeId from, NodeId to) noexcept;
265 
266  // add an arc
267  void _installArc(NodeId from, NodeId to) noexcept;
268 
269  // install a CPT, create or delete arcs. Checks are made in public methods
270  // In particular, it is assumed that all the variables in the pot are in the
271  // fragment
272  void _installCPT(NodeId id, const Potential< GUM_SCALAR >* pot) noexcept;
273 
278  void _uninstallCPT(NodeId id) noexcept;
279  };
280 
281 
282 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
283  extern template class BayesNetFragment< double >;
284 #endif
285 
286 } // namespace gum
287 
289 
290 #endif // GUM_BAYES_NET_FRAGMENT_H
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
virtual NodeId nodeId(const DiscreteVariable &var) const override
Return id node from discrete var pointer.
Abstract Base class for all diGraph Listener.
virtual void whenNodeDeleted(const void *src, NodeId id) noexcept override
the action to take when a node has just been removed from the graph
void uninstallCPT(NodeId id) noexcept
uninstall a local CPT.
NodeProperty< const Potential< GUM_SCALAR > *> __localCPTs
Mapping between the variable&#39;s id and their CPT specific to this Fragment.
virtual const DiscreteVariable & variableFromName(const std::string &name) const override
Getter by name.
void _installCPT(NodeId id, const Potential< GUM_SCALAR > *pot) noexcept
void installCPT(NodeId id, const Potential< GUM_SCALAR > *pot)
install a local cpt for a node into the fragment.
virtual void whenArcAdded(const void *src, NodeId from, NodeId to) noexcept override
the action to take when a new arc is inserted into the graph
virtual const VariableNodeMap & variableNodeMap() const override
Returns a constant reference to the VariableNodeMap of this BN.
Container used to map discrete variables with nodes.
void _installArc(NodeId from, NodeId to) noexcept
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Base class for discrete random variable.
void installAscendants(NodeId id)
install a node and all its ascendants
Class representing the minimal interface for Bayesian Network.
Definition: IBayesNet.h:62
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
The class for generic Hash Tables.
Definition: hashTable.h:679
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const override
Returns the CPT of a variable.
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
virtual const DiscreteVariable & variable(NodeId id) const override
Returns a constant reference over a variabe given it&#39;s node id.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:115
virtual void whenArcDeleted(const void *src, NodeId from, NodeId to) noexcept override
the action to take when an arc has just been removed from the graph
Portion of a BN identified by the list of nodes and a BayesNet.
void installNode(NodeId id)
install a node referenced by its nodeId
virtual std::string toDot() const override
creates a dot representing the whole referred BN hilighting the fragment.
void uninstallNode(NodeId id) noexcept
uninstall a node referenced by its nodeId
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
void installMarginal(NodeId id, const Potential< GUM_SCALAR > *pot)
install a local marginal for a node into the fragment.
bool checkConsistency() const noexcept
returns true if all nodes in the fragment are consistent
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual NodeId idFromName(const std::string &name) const override
Getter by name.
virtual void whenNodeAdded(const void *src, NodeId id) noexcept override
the action to take when a new node is inserted into the graph
void _uninstallArc(NodeId from, NodeId to) noexcept
void _uninstallCPT(NodeId id) noexcept
uninstall a local CPT.
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:63
Size NodeId
Type for node ids.
Definition: graphElements.h:98