aGrUM  0.14.2
gum::BayesNetFragment< GUM_SCALAR > Class Template Reference

Portion of a BN identified by the list of nodes and a BayesNet. More...

#include <agrum/BN/BayesNetFragment.h>

+ Inheritance diagram for gum::BayesNetFragment< GUM_SCALAR >:
+ Collaboration diagram for gum::BayesNetFragment< GUM_SCALAR >:

Public Member Functions

bool operator== (const IBayesNet< GUM_SCALAR > &from) const
 This operator compares 2 BNs ! More...
 
bool operator!= (const IBayesNet< GUM_SCALAR > &from) const
 
Size dim () const
 Returns the dimension (the number of free parameters) in this bayes net. More...
 
Size maxVarDomainSize () const
 
GUM_SCALAR minParam () const
 
GUM_SCALAR maxParam () const
 
GUM_SCALAR minNonZeroParam () const
 
GUM_SCALAR maxNonOneParam () const
 
std::string toString () const
 
NodeSet minimalCondSet (NodeId target, const NodeSet &soids) const
 
NodeSet minimalCondSet (const NodeSet &targets, const NodeSet &soids) const
 
double log10DomainSize () const
 
bool hasSameStructure (const DAGmodel &other)
 
void attachSignal__ (__sig__::ISignaler *sender)
 
void detachSignal__ (__sig__::ISignaler *sender)
 
Constructors / Destructors
 BayesNetFragment ()=delete
 
 BayesNetFragment (const BayesNetFragment< GUM_SCALAR > &fragment)=delete
 
 BayesNetFragment (BayesNetFragment< GUM_SCALAR > &&fragment)=delete
 
 BayesNetFragment (const IBayesNet< GUM_SCALAR > &bn)
 
virtual ~BayesNetFragment ()
 
signals
virtual void whenNodeAdded (const void *src, NodeId id) noexcept override
 the action to take when a new node is inserted into the graph More...
 
virtual void whenNodeDeleted (const void *src, NodeId id) noexcept override
 the action to take when a node has just been removed from the graph More...
 
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 More...
 
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 More...
 
IBayesNet interface
virtual const Potential< GUM_SCALAR > & cpt (NodeId varId) const override
 Returns the CPT of a variable. More...
 
virtual const VariableNodeMapvariableNodeMap () const override
 Returns a constant reference to the VariableNodeMap of this BN. More...
 
virtual const DiscreteVariablevariable (NodeId id) const override
 Returns a constant reference over a variabe given it's node id. More...
 
virtual NodeId nodeId (const DiscreteVariable &var) const override
 Return id node from discrete var pointer. More...
 
virtual NodeId idFromName (const std::string &name) const override
 Getter by name. More...
 
virtual const DiscreteVariablevariableFromName (const std::string &name) const override
 Getter by name. More...
 
virtual std::string toDot () const override
 creates a dot representing the whole referred BN hilighting the fragment. More...
 
API for Fragment
bool isInstalledNode (NodeId id) const noexcept
 check if a certain NodeId exists in the fragment More...
 
void installNode (NodeId id)
 install a node referenced by its nodeId More...
 
void installAscendants (NodeId id)
 install a node and all its ascendants More...
 
void uninstallNode (NodeId id) noexcept
 uninstall a node referenced by its nodeId More...
 
void installMarginal (NodeId id, const Potential< GUM_SCALAR > *pot)
 install a local marginal for a node into the fragment. More...
 
void installCPT (NodeId id, const Potential< GUM_SCALAR > *pot)
 install a local cpt for a node into the fragment. More...
 
void uninstallCPT (NodeId id) noexcept
 uninstall a local CPT. More...
 
bool checkConsistency (NodeId id) const
 returns true if the nodeId's (local or not) cpt is consistent with its parents in the fragment More...
 
bool checkConsistency () const noexcept
 returns true if all nodes in the fragment are consistent More...
 
Joint Probability manipulation methods
GUM_SCALAR jointProbability (const Instantiation &i) const
 Compute a parameter of the joint probability for the BN (given an instantiation of the vars) More...
 
GUM_SCALAR log2JointProbability (const Instantiation &i) const
 Compute a parameter of the log joint probability for the BN (given an instantiation of the vars) More...
 
Getter and setters
const std::string & property (const std::string &name) const
 Return the value of the property name of this DAGModel. More...
 
const std::string & propertyWithDefault (const std::string &name, const std::string &byDefault) const
 Return the value of the property name of this DAGModel. More...
 
void setProperty (const std::string &name, const std::string &value)
 Add or change a property of this DAGModel. More...
 
Variable manipulation methods.
const DAGdag () const
 Returns a constant reference to the dag of this Bayes Net. More...
 
Size size () const
 Returns the number of variables in this Directed Graphical Model. More...
 
Size sizeArcs () const
 Returns the number of arcs in this Directed Graphical Model. More...
 
bool empty () const
 Retursn true if this Directed Graphical Model is empty. More...
 
const NodeGraphPartnodes () const
 Returns a constant reference to the dag of this Bayes Net. More...
 
virtual Instantiation completeInstantiation () const final
 Get an instantiation over all the variables of the model. More...
 
Arc manipulation methods.
const ArcSetarcs () const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetparents (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetparents (const std::string &name) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetchildren (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node More...
 
const NodeSetchildren (const std::string &name) const
 returns the set of nodes with arc ingoing to a given node More...
 
Graphical methods
const UndiGraphmoralGraph (bool clear=true) const
 The node's id are coherent with the variables and nodes of the topology. More...
 
const Sequence< NodeId > & topologicalOrder (bool clear=true) const
 The topological order stays the same as long as no variable or arcs are added or erased src the topology. More...
 

Protected Attributes

DAG _dag
 The DAG of this Directed Graphical Model. More...
 
DiGraph_graph
 the graph to listen to More...
 

Protected Member Functions

void _uninstallArc (NodeId from, NodeId to) noexcept
 
void _installArc (NodeId from, NodeId to) noexcept
 
void _installCPT (NodeId id, const Potential< GUM_SCALAR > *pot) noexcept
 
void _uninstallCPT (NodeId id) noexcept
 uninstall a local CPT. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::BayesNetFragment< GUM_SCALAR >

Portion of a BN identified by the list of nodes and a BayesNet.

Author
Pierre-Henri WUILLEMIN

This class is a decorator of a BayesNet implementing the IBayesNet interface. CPTs can be shared with the BN or can be specific to the Fragment if different.

BayesNetFragment is a DiGraphListener in order to be synchronized (especially when removing nodes or arcs).

In a BayesNetFragment, one can install or remove nodes. An arc can be in the fragment if and only if its head and tail are installed in the fragment. *When installing a node, all the arcs that can be added in the fragment are *effectively installed (resp. *when uninstalling a node, etc.).

A BayesNetFragment can redefine potential for node. The main reason is to be able to install a node without installing all its parents (and its ascendants). So local CPT to the node can be installed. However, it is not done automatically.

If a cpt is not locally defined, the fragment uses the cpt defined in the referred BN. The checkConsistency() method verifies that, for all installed nodes, either all the parents are installed or a local CPT is defined.

Definition at line 70 of file BayesNetFragment.h.

Constructor & Destructor Documentation

◆ BayesNetFragment() [1/4]

template<typename GUM_SCALAR>
gum::BayesNetFragment< GUM_SCALAR >::BayesNetFragment ( )
delete

◆ BayesNetFragment() [2/4]

template<typename GUM_SCALAR>
gum::BayesNetFragment< GUM_SCALAR >::BayesNetFragment ( const BayesNetFragment< GUM_SCALAR > &  fragment)
delete

◆ BayesNetFragment() [3/4]

template<typename GUM_SCALAR>
gum::BayesNetFragment< GUM_SCALAR >::BayesNetFragment ( BayesNetFragment< GUM_SCALAR > &&  fragment)
delete

◆ BayesNetFragment() [4/4]

template<typename GUM_SCALAR >
gum::BayesNetFragment< GUM_SCALAR >::BayesNetFragment ( const IBayesNet< GUM_SCALAR > &  bn)
explicit

Definition at line 32 of file BayesNetFragment_tpl.h.

33  :
34  DiGraphListener(&bn.dag()),
35  __bn(bn) {
36  GUM_CONSTRUCTOR(BayesNetFragment);
37  }
DiGraphListener(const DiGraph *g)
default constructor
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.

◆ ~BayesNetFragment()

template<typename GUM_SCALAR >
gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment ( )
virtual

Definition at line 40 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__localCPTs, gum::BayesNetFragment< GUM_SCALAR >::_uninstallCPT(), and gum::DAGmodel::nodes().

40  {
41  GUM_DESTRUCTOR(BayesNetFragment);
42 
43  for (auto node : nodes())
44  if (__localCPTs.exists(node)) _uninstallCPT(node);
45  }
NodeProperty< const Potential< GUM_SCALAR > *> __localCPTs
Mapping between the variable&#39;s id and their CPT specific to this Fragment.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
void _uninstallCPT(NodeId id) noexcept
uninstall a local CPT.
+ Here is the call graph for this function:

Member Function Documentation

◆ _installArc()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::_installArc ( NodeId  from,
NodeId  to 
)
protectednoexcept

Definition at line 185 of file BayesNetFragment_tpl.h.

References gum::DAGmodel::_dag, and gum::DAG::addArc().

Referenced by gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), and gum::BayesNetFragment< GUM_SCALAR >::uninstallCPT().

186  {
187  this->_dag.addArc(from, to);
188  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: DAG_inl.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _installCPT()

template<typename GUM_SCALAR >
void gum::BayesNetFragment< GUM_SCALAR >::_installCPT ( NodeId  id,
const Potential< GUM_SCALAR > *  pot 
)
protectednoexcept

Definition at line 191 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, gum::BayesNetFragment< GUM_SCALAR >::__localCPTs, gum::BayesNetFragment< GUM_SCALAR >::_installArc(), gum::BayesNetFragment< GUM_SCALAR >::_uninstallArc(), gum::BayesNetFragment< GUM_SCALAR >::_uninstallCPT(), gum::Set< Key, Alloc >::beginSafe(), gum::Set< Key, Alloc >::endSafe(), gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode(), and gum::DAGmodel::parents().

Referenced by gum::BayesNetFragment< GUM_SCALAR >::installCPT(), and gum::BayesNetFragment< GUM_SCALAR >::installMarginal().

192  {
193  // topology
194  const auto& parents = this->parents(id);
195  for (auto node_it = parents.beginSafe(); node_it != parents.endSafe();
196  ++node_it) // safe iterator needed here
197  _uninstallArc(*node_it, id);
198 
199  for (Idx i = 1; i < pot->nbrDim(); i++) {
200  NodeId parent = __bn.idFromName(pot->variable(i).name());
201 
202  if (isInstalledNode(parent)) _installArc(parent, id);
203  }
204 
205  // local cpt
206  if (__localCPTs.exists(id)) _uninstallCPT(id);
207 
208  __localCPTs.insert(id, pot);
209  }
NodeProperty< const Potential< GUM_SCALAR > *> __localCPTs
Mapping between the variable&#39;s id and their CPT specific to this Fragment.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:103
void _installArc(NodeId from, NodeId to) noexcept
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Definition: set_tpl.h:499
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
Definition: set_tpl.h:485
void _uninstallArc(NodeId from, NodeId to) noexcept
void _uninstallCPT(NodeId id) noexcept
uninstall a local CPT.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _uninstallArc()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::_uninstallArc ( NodeId  from,
NodeId  to 
)
protectednoexcept

Definition at line 179 of file BayesNetFragment_tpl.h.

References gum::DAGmodel::_dag, and gum::ArcGraphPart::eraseArc().

Referenced by gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), and gum::BayesNetFragment< GUM_SCALAR >::whenArcDeleted().

180  {
181  this->_dag.eraseArc(Arc(from, to));
182  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _uninstallCPT()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::_uninstallCPT ( NodeId  id)
protectednoexcept

uninstall a local CPT.

Does nothing if no local CPT for this nodeId No check. No change in the topology. Checks are made in public methods.

Definition at line 236 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__localCPTs.

Referenced by gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), gum::BayesNetFragment< GUM_SCALAR >::uninstallCPT(), and gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment().

236  {
237  delete __localCPTs[id];
238  __localCPTs.erase(id);
239  }
NodeProperty< const Potential< GUM_SCALAR > *> __localCPTs
Mapping between the variable&#39;s id and their CPT specific to this Fragment.
+ Here is the caller graph for this function:

◆ arcs()

INLINE const ArcSet & gum::DAGmodel::arcs ( ) const
inherited

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 101 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag, and gum::ArcGraphPart::arcs().

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::DAGmodel::__moralGraph(), gum::MarkovBlanket::hasSameStructure(), and gum::DAGmodel::hasSameStructure().

101 { return _dag.arcs(); }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attachSignal__()

INLINE void gum::Listener::attachSignal__ ( __sig__::ISignaler *  sender)
inherited

Definition at line 33 of file listener_inl.h.

References gum::Listener::__senders.

33  {
34  __senders.push_back(sender);
35  }
Senders_list __senders
Definition: listener.h:92

◆ checkConsistency() [1/2]

template<typename GUM_SCALAR >
bool gum::BayesNetFragment< GUM_SCALAR >::checkConsistency ( NodeId  id) const

returns true if the nodeId's (local or not) cpt is consistent with its parents in the fragment

Exceptions
NotFoundif the id is not in the fragment

Definition at line 278 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, gum::BayesNetFragment< GUM_SCALAR >::cpt(), GUM_ERROR, gum::Set< Key, Alloc >::insert(), gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode(), and gum::DAGmodel::parents().

278  {
279  if (!isInstalledNode(id))
280  GUM_ERROR(NotFound, "The node " << id << " is not part of this fragment");
281 
282  const auto& cpt = this->cpt(id);
283  NodeSet cpt_parents;
284 
285  for (Idx i = 1; i < cpt.nbrDim(); i++) {
286  cpt_parents.insert(__bn.idFromName(cpt.variable(i).name()));
287  }
288 
289  return (this->parents(id) == cpt_parents);
290  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:103
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const override
Returns the CPT of a variable.
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ checkConsistency() [2/2]

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetFragment< GUM_SCALAR >::checkConsistency ( ) const
noexcept

returns true if all nodes in the fragment are consistent

Definition at line 293 of file BayesNetFragment_tpl.h.

References gum::DAGmodel::nodes().

Referenced by gum::BayesNetFragment< GUM_SCALAR >::toDot().

293  {
294  for (auto node : nodes())
295  if (!checkConsistency(node)) return false;
296 
297  return true;
298  }
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
bool checkConsistency() const noexcept
returns true if all nodes in the fragment are consistent
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ children() [1/2]

INLINE const NodeSet & gum::DAGmodel::children ( const NodeId  id) const
inherited

returns the set of nodes with arc outgoing from a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is outgoing from the given node.

Parameters
idthe node which is the tail of the arcs returned

Definition at line 108 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag, and gum::ArcGraphPart::children().

Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::DAGmodel::parents(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().

108  {
109  return _dag.children(id);
110  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ children() [2/2]

const NodeSet& gum::DAGmodel::children ( const std::string &  name) const
inlineinherited

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 162 of file DAGmodel.h.

References gum::DAGmodel::hasSameStructure(), gum::DAGmodel::idFromName(), gum::DAGmodel::log10DomainSize(), gum::DAGmodel::moralGraph(), gum::DAGmodel::operator=(), gum::DAGmodel::parents(), and gum::DAGmodel::topologicalOrder().

162  {
163  return parents(idFromName(name));
164  };
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:103
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ completeInstantiation()

INLINE Instantiation gum::DAGmodel::completeInstantiation ( ) const
finalvirtualinherited

Get an instantiation over all the variables of the model.

Definition at line 83 of file DAGmodel_inl.h.

References gum::DAGmodel::dag(), and gum::DAGmodel::variable().

83  {
84  Instantiation I;
85 
86  for (const auto node : dag())
87  I << variable(node);
88 
89  return I;
90  }
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
+ Here is the call graph for this function:

◆ cpt()

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::BayesNetFragment< GUM_SCALAR >::cpt ( NodeId  varId) const
overridevirtual

Returns the CPT of a variable.

Exceptions
NotFoundIf no variable's id matches varId.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 77 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, gum::BayesNetFragment< GUM_SCALAR >::__localCPTs, GUM_ERROR, and gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode().

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_unsharpenBN(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), and gum::BayesNetFragment< GUM_SCALAR >::uninstallCPT().

77  {
78  if (!isInstalledNode(id)) GUM_ERROR(NotFound, id << " is not installed");
79 
80  if (__localCPTs.exists(id))
81  return *__localCPTs[id];
82  else
83  return __bn.cpt(id);
84  }
NodeProperty< const Potential< GUM_SCALAR > *> __localCPTs
Mapping between the variable&#39;s id and their CPT specific to this Fragment.
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dag()

◆ detachSignal__()

INLINE void gum::Listener::detachSignal__ ( __sig__::ISignaler *  sender)
inherited

Definition at line 37 of file listener_inl.h.

References gum::Listener::__senders.

37  {
38  auto del = std::remove(__senders.begin(), __senders.end(), sender);
39 
40  if (del != __senders.end()) __senders.erase(del, __senders.end());
41  }
Senders_list __senders
Definition: listener.h:92

◆ dim()

template<typename GUM_SCALAR >
Size gum::IBayesNet< GUM_SCALAR >::dim ( ) const
inherited

Returns the dimension (the number of free parameters) in this bayes net.

\( dim(G)=\sum_{i \in nodes} ((r_i-1)\cdot q_i) \) where \( r_i \) is the number of instantiations of node \( i \) and \( q_i \) is the number of instantiations of its parents.

Definition at line 76 of file IBayesNet_tpl.h.

76  {
77  Size dim = 0;
78 
79  for (auto node : nodes()) {
80  Size q = 1;
81 
82  for (auto parent : parents(node))
83  q *= variable(parent).domainSize();
84 
85  dim += (variable(node).domainSize() - 1) * q;
86  }
87 
88  return dim;
89  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:103
virtual Size domainSize() const =0
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable 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:112
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
Definition: IBayesNet_tpl.h:76
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45

◆ empty()

INLINE bool gum::DAGmodel::empty ( ) const
inherited

Retursn true if this Directed Graphical Model is empty.

Definition at line 96 of file DAGmodel_inl.h.

References gum::DAGmodel::size().

96 { return size() == 0; }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:93
+ Here is the call graph for this function:

◆ hasSameStructure()

bool gum::DAGmodel::hasSameStructure ( const DAGmodel other)
inherited
Returns
true if all the named node are the same and all the named arcs are the same

Definition at line 119 of file DAGmodel.cpp.

References gum::DAGmodel::arcs(), gum::Set< Key, Alloc >::exists(), gum::DAGmodel::idFromName(), gum::DAGmodel::nodes(), gum::DAGmodel::size(), gum::DAGmodel::sizeArcs(), and gum::DAGmodel::variable().

Referenced by gum::DAGmodel::children().

119  {
120  if (this == &other) return true;
121 
122  if (size() != other.size()) return false;
123 
124  if (sizeArcs() != other.sizeArcs()) return false;
125 
126  for (const auto& nid : nodes()) {
127  try {
128  other.idFromName(variable(nid).name());
129  } catch (NotFound) { return false; }
130  }
131 
132  for (const auto& arc : arcs()) {
133  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
134  other.idFromName(variable(arc.head()).name()))))
135  return false;
136  }
137 
138  return true;
139  }
const ArcSet & arcs() const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:101
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:99
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:93
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ idFromName()

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNetFragment< GUM_SCALAR >::idFromName ( const std::string &  name) const
overridevirtual

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 114 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, GUM_ERROR, and gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode().

114  {
115  NodeId id = __bn.idFromName(name);
116 
117  if (!isInstalledNode(id))
118  GUM_ERROR(NotFound, "variable " << name << " is not installed");
119 
120  return id;
121  }
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ installAscendants()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::installAscendants ( NodeId  id)

install a node and all its ascendants

Exceptions
NotFoundif the node does not exist in the referred BN
Warning
nothing happens if the node is already installed

Definition at line 162 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, and gum::BayesNetFragment< GUM_SCALAR >::installNode().

162  {
163  installNode(id);
164 
165  // bn is a dag => this will have an end ...
166  for (auto pa : this->__bn.parents(id))
167  installAscendants(pa);
168  }
void installAscendants(NodeId id)
install a node and all its ascendants
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
void installNode(NodeId id)
install a node referenced by its nodeId
+ Here is the call graph for this function:

◆ installCPT()

template<typename GUM_SCALAR >
void gum::BayesNetFragment< GUM_SCALAR >::installCPT ( NodeId  id,
const Potential< GUM_SCALAR > *  pot 
)

install a local cpt for a node into the fragment.

This function will change the arcs from the parents to the node in order to be consistent with the new local potential.

Parameters
idthe nodeId
potthe potential<
Exceptions
NotFoundif the id is not in the fragment
OperationNotAllowedif the potential is not compliant with the variable or if a variable in the CPT is not a parent in the referred bn.

Definition at line 212 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), gum::Set< Key, Alloc >::contains(), gum::DAGmodel::dag(), GUM_ERROR, gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), gum::DAGmodel::parents(), gum::MultiDimDecorator< GUM_SCALAR >::variable(), and gum::BayesNetFragment< GUM_SCALAR >::variable().

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize(), and gum::ImportanceSampling< GUM_SCALAR >::_unsharpenBN().

213  {
214  if (!dag().existsNode(id))
215  GUM_ERROR(NotFound, "Node " << id << " is not installed in the fragment");
216 
217  if (&(pot->variable(0)) != &(variable(id))) {
218  GUM_ERROR(OperationNotAllowed,
219  "The potential is not a marginal for __bn.variable <"
220  << variable(id).name() << ">");
221  }
222 
223  const NodeSet& parents = __bn.parents(id);
224 
225  for (Idx i = 1; i < pot->nbrDim(); i++) {
226  if (!parents.contains(__bn.idFromName(pot->variable(i).name())))
227  GUM_ERROR(OperationNotAllowed,
228  "Variable <" << pot->variable(i).name()
229  << "> is not in the parents of node " << id);
230  }
231 
232  _installCPT(id, pot);
233  }
void _installCPT(NodeId id, const Potential< GUM_SCALAR > *pot) noexcept
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:103
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
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 DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ installMarginal()

template<typename GUM_SCALAR >
void gum::BayesNetFragment< GUM_SCALAR >::installMarginal ( NodeId  id,
const Potential< GUM_SCALAR > *  pot 
)

install a local marginal for a node into the fragment.

This function will remove all the arcs from the parents to the node.

Parameters
idthe nodeId
potthe potential
Exceptions
NotFoundif the id is not in the fragment
OperationNotAllowedif the potential is not compliant with the variable (or is not a marginal)

Definition at line 258 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), GUM_ERROR, gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

259  {
260  if (!isInstalledNode(id)) {
261  GUM_ERROR(NotFound, "The node " << id << " is not part of this fragment");
262  }
263 
264  if (pot->nbrDim() > 1) {
265  GUM_ERROR(OperationNotAllowed, "The potential is not a marginal :" << pot);
266  }
267 
268  if (&(pot->variable(0)) != &(__bn.variable(id))) {
269  GUM_ERROR(OperationNotAllowed,
270  "The potential is not a marginal for __bn.variable <"
271  << __bn.variable(id).name() << ">");
272  }
273 
274  _installCPT(id, pot);
275  }
void _installCPT(NodeId id, const Potential< GUM_SCALAR > *pot) noexcept
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ installNode()

template<typename GUM_SCALAR >
void gum::BayesNetFragment< GUM_SCALAR >::installNode ( NodeId  id)

install a node referenced by its nodeId

Exceptions
NotFoundif the node does not exist in the referred BN
Warning
nothing happens if the node is already installed

Definition at line 143 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, gum::DAGmodel::_dag, gum::DAG::addArc(), gum::NodeGraphPart::addNodeWithId(), GUM_ERROR, and gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode().

Referenced by gum::BayesNetFragment< GUM_SCALAR >::installAscendants().

143  {
144  if (!__bn.dag().existsNode(id))
145  GUM_ERROR(NotFound, "Node " << id << " does not exist in referred BayesNet");
146 
147  if (!isInstalledNode(id)) {
148  this->_dag.addNodeWithId(id);
149 
150  // adding arcs with id as a tail
151  for (auto pa : this->__bn.parents(id)) {
152  if (isInstalledNode(pa)) this->_dag.addArc(pa, id);
153  }
154 
155  // addin arcs with id as a head
156  for (auto son : this->__bn.children(id))
157  if (isInstalledNode(son)) this->_dag.addArc(id, son);
158  }
159  }
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: DAG_inl.h:40
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isInstalledNode()

template<typename GUM_SCALAR >
INLINE bool gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode ( NodeId  id) const
noexcept

check if a certain NodeId exists in the fragment

Definition at line 137 of file BayesNetFragment_tpl.h.

References gum::DAGmodel::dag(), and gum::NodeGraphPart::existsNode().

Referenced by gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::BayesNetFragment< GUM_SCALAR >::cpt(), gum::BayesNetFragment< GUM_SCALAR >::idFromName(), gum::BayesNetFragment< GUM_SCALAR >::installMarginal(), gum::BayesNetFragment< GUM_SCALAR >::installNode(), gum::BayesNetFragment< GUM_SCALAR >::nodeId(), gum::BayesNetFragment< GUM_SCALAR >::toDot(), gum::BayesNetFragment< GUM_SCALAR >::uninstallCPT(), gum::BayesNetFragment< GUM_SCALAR >::uninstallNode(), gum::BayesNetFragment< GUM_SCALAR >::variable(), and gum::BayesNetFragment< GUM_SCALAR >::variableFromName().

138  {
139  return dag().existsNode(id);
140  }
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jointProbability()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::jointProbability ( const Instantiation i) const
inherited

Compute a parameter of the joint probability for the BN (given an instantiation of the vars)

Warning
a variable not present in the instantiation is assumed to be instantiated to 0.

Definition at line 217 of file IBayesNet_tpl.h.

217  {
218  auto value = (GUM_SCALAR)1.0;
219 
220  GUM_SCALAR tmp;
221 
222  for (auto node : nodes()) {
223  if ((tmp = cpt(node)[i]) == (GUM_SCALAR)0) { return (GUM_SCALAR)0; }
224 
225  value *= tmp;
226  }
227 
228  return value;
229  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112

◆ log10DomainSize()

INLINE double gum::DAGmodel::log10DomainSize ( ) const
inherited
Returns
Returns the log10 domain size of the joint probabilty for the Directed Graphical Model

Definition at line 72 of file DAGmodel_inl.h.

References gum::DAGmodel::nodes(), and gum::DAGmodel::variable().

Referenced by gum::DAGmodel::children(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().

72  {
73  double dSize = 0.0;
74 
75  for (const auto node : nodes()) {
76  dSize += std::log10(variable(node).domainSize());
77  }
78 
79  return dSize;
80  }
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variabe given it&#39;s node id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ log2JointProbability()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::log2JointProbability ( const Instantiation i) const
inherited

Compute a parameter of the log joint probability for the BN (given an instantiation of the vars)

Compute a parameter of the joint probability for the BN (given an instantiation of the vars)

Warning
a variable not present in the instantiation is assumed to be instantiated to 0.

Definition at line 236 of file IBayesNet_tpl.h.

236  {
237  auto value = (GUM_SCALAR)0.0;
238 
239  GUM_SCALAR tmp;
240 
241  for (auto node : nodes()) {
242  if ((tmp = cpt(node)[i]) == (GUM_SCALAR)0) {
243  return (GUM_SCALAR)(-std::numeric_limits< double >::infinity());
244  }
245 
246  value += log2(cpt(node)[i]);
247  }
248 
249  return value;
250  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112

◆ maxNonOneParam()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::maxNonOneParam ( ) const
inherited
Returns
the biggest value (not equal to 1) in the CPTs of *this

Definition at line 132 of file IBayesNet_tpl.h.

132  {
133  GUM_SCALAR res = 0.0;
134  for (auto node : nodes()) {
135  auto v = cpt(node).maxNonOne();
136  if (v > res) { res = v; }
137  }
138  return res;
139  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112

◆ maxParam()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::maxParam ( ) const
inherited
Returns
the biggest value in the CPTs of *this

Definition at line 112 of file IBayesNet_tpl.h.

112  {
113  GUM_SCALAR res = 1.0;
114  for (auto node : nodes()) {
115  auto v = cpt(node).max();
116  if (v > res) { res = v; }
117  }
118  return res;
119  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112

◆ maxVarDomainSize()

template<typename GUM_SCALAR >
Size gum::IBayesNet< GUM_SCALAR >::maxVarDomainSize ( ) const
inherited
Returns
the biggest domainSize among the variables of *this

Definition at line 92 of file IBayesNet_tpl.h.

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize().

92  {
93  Size res = 0;
94  for (auto node : nodes()) {
95  auto v = variable(node).domainSize();
96  if (v > res) { res = v; }
97  }
98  return res;
99  }
virtual Size domainSize() const =0
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable 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:112
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
+ Here is the caller graph for this function:

◆ minimalCondSet() [1/2]

template<typename GUM_SCALAR >
NodeSet gum::IBayesNet< GUM_SCALAR >::minimalCondSet ( NodeId  target,
const NodeSet soids 
) const
inherited

Definition at line 352 of file IBayesNet_tpl.h.

353  {
354  if (soids.contains(target)) return NodeSet({target});
355 
356  NodeSet res;
357  NodeSet alreadyVisitedUp;
358  NodeSet alreadyVisitedDn;
359  alreadyVisitedDn << target;
360  alreadyVisitedUp << target;
361 
362  for (auto fath : _dag.parents(target))
364  fath, soids, res, alreadyVisitedUp, alreadyVisitedDn);
365  for (auto chil : _dag.children(target))
367  chil, soids, res, alreadyVisitedUp, alreadyVisitedDn);
368  return res;
369  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
void __minimalCondSetVisitUp(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
void __minimalCondSetVisitDn(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const

◆ minimalCondSet() [2/2]

template<typename GUM_SCALAR >
NodeSet gum::IBayesNet< GUM_SCALAR >::minimalCondSet ( const NodeSet targets,
const NodeSet soids 
) const
inherited

Definition at line 372 of file IBayesNet_tpl.h.

373  {
374  NodeSet res;
375  for (auto node : targets) {
376  res += minimalCondSet(node, soids);
377  }
378  return res;
379  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const

◆ minNonZeroParam()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::minNonZeroParam ( ) const
inherited
Returns
the smallest value (not equal to 0) in the CPTs of *this

Definition at line 122 of file IBayesNet_tpl.h.

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize().

122  {
123  GUM_SCALAR res = 1.0;
124  for (auto node : nodes()) {
125  auto v = cpt(node).minNonZero();
126  if (v < res) { res = v; }
127  }
128  return res;
129  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
+ Here is the caller graph for this function:

◆ minParam()

template<typename GUM_SCALAR >
GUM_SCALAR gum::IBayesNet< GUM_SCALAR >::minParam ( ) const
inherited
Returns
the smallest value in the CPTs of *this

Definition at line 102 of file IBayesNet_tpl.h.

102  {
103  GUM_SCALAR res = 1.0;
104  for (auto node : nodes()) {
105  auto v = cpt(node).min();
106  if (v < res) { res = v; }
107  }
108  return res;
109  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112

◆ moralGraph()

const UndiGraph & gum::DAGmodel::moralGraph ( bool  clear = true) const
inherited

The node's id are coherent with the variables and nodes of the topology.

Parameters
clearIf false returns the previously created moral graph.

Definition at line 99 of file DAGmodel.cpp.

References gum::DAGmodel::__moralGraph(), gum::DAGmodel::__mutableMoralGraph, and gum::UndiGraph::clear().

Referenced by gum::prm::SVED< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodes(), gum::prm::SVED< GUM_SCALAR >::__eliminateNodesWithEvidence(), gum::prm::SVE< GUM_SCALAR >::__eliminateNodesWithEvidence(), gum::prm::SVED< GUM_SCALAR >::__initLiftedNodes(), gum::prm::SVE< GUM_SCALAR >::__initLiftedNodes(), and gum::DAGmodel::children().

99  {
100  if (clear
101  || (__mutableMoralGraph == nullptr)) { // we have to call _moralGraph
102  if (__mutableMoralGraph == nullptr) {
103  __mutableMoralGraph = new UndiGraph();
104  } else {
105  // clear is True ,__mutableMoralGraph exists
107  }
108 
109  __moralGraph();
110  }
111 
112  return *__mutableMoralGraph;
113  }
virtual void clear()
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:40
UndiGraph * __mutableMoralGraph
The moral graph of this Directed Graphical Model.
Definition: DAGmodel.h:208
void __moralGraph() const
Returns the moral graph of this DAGModel.
Definition: DAGmodel.cpp:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nodeId()

template<typename GUM_SCALAR >
INLINE NodeId gum::BayesNetFragment< GUM_SCALAR >::nodeId ( const DiscreteVariable var) const
overridevirtual

Return id node from discrete var pointer.

Exceptions
NotFoundIf no variable matches var.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 103 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, GUM_ERROR, gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode(), and gum::Variable::name().

103  {
104  NodeId id = __bn.nodeId(var);
105 
106  if (!isInstalledNode(id))
107  GUM_ERROR(NotFound, "variable " << var.name() << " is not installed");
108 
109  return id;
110  }
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ nodes()

INLINE const NodeGraphPart & gum::DAGmodel::nodes ( ) const
inherited

Returns a constant reference to the dag of this Bayes Net.

Definition at line 112 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag.

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__bnCopy(), gum::EssentialGraph::__buildEssentialGraph(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::DAGmodel::__moralGraph(), gum::credal::CredalNet< GUM_SCALAR >::__sort_varType(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__verticesSampling(), gum::ImportanceSampling< GUM_SCALAR >::_unsharpenBN(), gum::BayesNetFactory< GUM_SCALAR >::BayesNetFactory(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN(), gum::Estimator< GUM_SCALAR >::Estimator(), gum::getMaxModality(), gum::DAGmodel::hasSameStructure(), gum::DAGmodel::log10DomainSize(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::credal::CredalNet< GUM_SCALAR >::toString(), and gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment().

112  {
113  return (NodeGraphPart&)_dag;
114  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
+ Here is the caller graph for this function:

◆ operator!=()

template<typename GUM_SCALAR>
bool gum::IBayesNet< GUM_SCALAR >::operator!= ( const IBayesNet< GUM_SCALAR > &  from) const
inherited
Returns
Returns false if the src and this are equal.

Definition at line 300 of file IBayesNet_tpl.h.

300  {
301  return !this->operator==(from);
302  }
bool operator==(const IBayesNet< GUM_SCALAR > &from) const
This operator compares 2 BNs !

◆ operator==()

template<typename GUM_SCALAR>
bool gum::IBayesNet< GUM_SCALAR >::operator== ( const IBayesNet< GUM_SCALAR > &  from) const
inherited

This operator compares 2 BNs !

Warning
To identify nodes between BNs, it is assumed that they share the same name.
Returns
true if the src and this are equal.

Definition at line 253 of file IBayesNet_tpl.h.

253  {
254  if (size() != from.size()) { return false; }
255 
256  if (sizeArcs() != from.sizeArcs()) { return false; }
257 
258  // alignment of variables between the 2 BNs
259  Bijection< const DiscreteVariable*, const DiscreteVariable* > alignment;
260 
261  for (auto node : nodes()) {
262  try {
263  alignment.insert(&variable(node),
264  &from.variableFromName(variable(node).name()));
265  } catch (NotFound&) {
266  // a name is not found in from
267  return false;
268  }
269  }
270 
271  for (auto node : nodes()) {
272  NodeId fromnode = from.idFromName(variable(node).name());
273 
274  if (cpt(node).nbrDim() != from.cpt(fromnode).nbrDim()) { return false; }
275 
276  if (cpt(node).domainSize() != from.cpt(fromnode).domainSize()) {
277  return false;
278  }
279 
280  Instantiation i(cpt(node));
281  Instantiation j(from.cpt(fromnode));
282 
283  for (i.setFirst(); !i.end(); i.inc()) {
284  for (Idx indice = 0; indice < cpt(node).nbrDim(); ++indice) {
285  const DiscreteVariable* p = &(i.variable(indice));
286  j.chgVal(*(alignment.second(p)), i.val(*p));
287  }
288 
289  if (std::pow(cpt(node).get(i) - from.cpt(fromnode).get(j), (GUM_SCALAR)2)
290  > (GUM_SCALAR)1e-6) {
291  return false;
292  }
293  }
294  }
295 
296  return true;
297  }
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:99
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:93
virtual const DiscreteVariable & variable(NodeId id) const =0
Returns a constant reference over a variable 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:112
Size NodeId
Type for node ids.
Definition: graphElements.h:97

◆ parents() [1/2]

INLINE const NodeSet & gum::DAGmodel::parents ( const NodeId  id) const
inherited

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 103 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag, and gum::ArcGraphPart::parents().

Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::DAGmodel::__moralGraph(), gum::BayesNetFragment< GUM_SCALAR >::_installCPT(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::DAGmodel::children(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::DAGmodel::parents(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().

103  {
104  return _dag.parents(id);
105  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parents() [2/2]

const NodeSet& gum::DAGmodel::parents ( const std::string &  name) const
inlineinherited

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 153 of file DAGmodel.h.

References gum::DAGmodel::children(), gum::DAGmodel::idFromName(), and gum::DAGmodel::parents().

153  {
154  return parents(idFromName(name));
155  };
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:103
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
+ Here is the call graph for this function:

◆ property()

INLINE const std::string & gum::DAGmodel::property ( const std::string &  name) const
inherited

Return the value of the property name of this DAGModel.

Exceptions
NotFoundRaised if no name property is found.

Definition at line 34 of file DAGmodel_inl.h.

References gum::DAGmodel::__properties(), and GUM_ERROR.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::toDot().

34  {
35  try {
36  return __properties()[name];
37  } catch (NotFound&) {
38  std::string msg = "The following property does not exists: ";
39  GUM_ERROR(NotFound, msg + name);
40  }
41  }
HashTable< std::string, std::string > & __properties() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
Definition: DAGmodel_inl.h:63
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ propertyWithDefault()

INLINE const std::string & gum::DAGmodel::propertyWithDefault ( const std::string &  name,
const std::string &  byDefault 
) const
inherited

Return the value of the property name of this DAGModel.

return byDefault if the property name is not found

Definition at line 45 of file DAGmodel_inl.h.

References gum::DAGmodel::__properties().

46  {
47  try {
48  return __properties()[name];
49  } catch (NotFound&) { return byDefault; }
50  }
HashTable< std::string, std::string > & __properties() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
Definition: DAGmodel_inl.h:63
+ Here is the call graph for this function:

◆ setProperty()

INLINE void gum::DAGmodel::setProperty ( const std::string &  name,
const std::string &  value 
)
inherited

Add or change a property of this DAGModel.

Definition at line 53 of file DAGmodel_inl.h.

References gum::DAGmodel::__properties(), and gum::HashTable< Key, Val, Alloc >::insert().

Referenced by gum::BayesNet< double >::fastPrototype().

53  {
54  try {
55  __properties()[name] = value;
56  } catch (NotFound&) { __properties().insert(name, value); }
57  }
HashTable< std::string, std::string > & __properties() const
Return the properties of this Directed Graphical Model and initialize the hash table is necessary...
Definition: DAGmodel_inl.h:63
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

INLINE Size gum::DAGmodel::size ( ) const
inherited

Returns the number of variables in this Directed Graphical Model.

Definition at line 93 of file DAGmodel_inl.h.

References gum::DAGmodel::dag(), and gum::NodeGraphPart::size().

Referenced by gum::credal::CredalNet< GUM_SCALAR >::__initCNNets(), gum::InfluenceDiagram< GUM_SCALAR >::decisionNodeSize(), gum::DAGmodel::empty(), gum::MarkovBlanket::hasSameStructure(), gum::DAGmodel::hasSameStructure(), gum::IBayesNet< double >::operator==(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().

93 { return dag().size(); }
Size size() const
alias for sizeNodes
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sizeArcs()

INLINE Size gum::DAGmodel::sizeArcs ( ) const
inherited

Returns the number of arcs in this Directed Graphical Model.

Definition at line 99 of file DAGmodel_inl.h.

References gum::DAGmodel::_dag, and gum::ArcGraphPart::sizeArcs().

Referenced by gum::MarkovBlanket::hasSameStructure(), gum::DAGmodel::hasSameStructure(), and gum::IBayesNet< double >::operator==().

99 { return _dag.sizeArcs(); }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toDot()

template<typename GUM_SCALAR >
std::string gum::BayesNetFragment< GUM_SCALAR >::toDot ( ) const
overridevirtual

creates a dot representing the whole referred BN hilighting the fragment.

Returns
Returns a dot representation of this fragment

Reimplemented from gum::IBayesNet< GUM_SCALAR >.

Definition at line 301 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, gum::BayesNetFragment< GUM_SCALAR >::__localCPTs, gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::DAGmodel::dag(), and gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode().

301  {
302  std::stringstream output;
303  output << "digraph \"";
304 
305  std::string bn_name;
306 
307  static std::string inFragmentStyle = "fillcolor=\"#ffffaa\","
308  "color=\"#000000\","
309  "fontcolor=\"#000000\"";
310  static std::string styleWithLocalCPT = "fillcolor=\"#ffddaa\","
311  "color=\"#000000\","
312  "fontcolor=\"#000000\"";
313  static std::string notConsistantStyle = "fillcolor=\"#ff0000\","
314  "color=\"#000000\","
315  "fontcolor=\"#ffff00\"";
316  static std::string outFragmentStyle = "fillcolor=\"#f0f0f0\","
317  "color=\"#f0f0f0\","
318  "fontcolor=\"#000000\"";
319 
320  try {
321  bn_name = __bn.property("name");
322  } catch (NotFound&) { bn_name = "no_name"; }
323 
324  bn_name = "Fragment of " + bn_name;
325 
326  output << bn_name << "\" {" << std::endl;
327  output << " graph [bgcolor=transparent,label=\"" << bn_name << "\"];"
328  << std::endl;
329  output << " node [style=filled];" << std::endl << std::endl;
330 
331  for (auto node : __bn.nodes()) {
332  output << "\"" << __bn.variable(node).name() << "\" [comment=\"" << node
333  << ":" << __bn.variable(node) << ", \"";
334 
335  if (isInstalledNode(node)) {
336  if (!checkConsistency(node)) {
337  output << notConsistantStyle;
338  } else if (__localCPTs.exists(node))
339  output << styleWithLocalCPT;
340  else
341  output << inFragmentStyle;
342  } else
343  output << outFragmentStyle;
344 
345  output << "];" << std::endl;
346  }
347 
348  output << std::endl;
349 
350  std::string tab = " ";
351 
352  for (auto node : __bn.nodes()) {
353  if (__bn.children(node).size() > 0) {
354  for (auto child : __bn.children(node)) {
355  output << tab << "\"" << __bn.variable(node).name() << "\" -> "
356  << "\"" << __bn.variable(child).name() << "\" [";
357 
358  if (dag().existsArc(Arc(node, child)))
359  output << inFragmentStyle;
360  else
361  output << outFragmentStyle;
362 
363  output << "];" << std::endl;
364  }
365  }
366  }
367 
368  output << "}" << std::endl;
369 
370  return output.str();
371  }
NodeProperty< const Potential< GUM_SCALAR > *> __localCPTs
Mapping between the variable&#39;s id and their CPT specific to this Fragment.
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
bool checkConsistency() const noexcept
returns true if all nodes in the fragment are consistent
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
+ Here is the call graph for this function:

◆ topologicalOrder()

const Sequence< NodeId > & gum::DAGmodel::topologicalOrder ( bool  clear = true) const
inherited

The topological order stays the same as long as no variable or arcs are added or erased src the topology.

Parameters
clearIf false returns the previously created topology.

Definition at line 115 of file DAGmodel.cpp.

References gum::DAGmodel::dag(), and gum::DiGraph::topologicalOrder().

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::InfluenceDiagramGenerator< GUM_SCALAR >::__checkTemporalOrder(), gum::DAGmodel::children(), gum::InfluenceDiagram< GUM_SCALAR >::decisionOrderExists(), and gum::InfluenceDiagram< GUM_SCALAR >::getDecisionOrder().

115  {
116  return this->dag().topologicalOrder(clear);
117  }
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
Definition: diGraph.cpp:88
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

template<typename GUM_SCALAR >
INLINE std::string gum::IBayesNet< GUM_SCALAR >::toString ( ) const
inherited
Returns
Returns a string representation of this IBayesNet.

Definition at line 142 of file IBayesNet_tpl.h.

Referenced by gum::operator<<().

142  {
143  Size param = 0;
144  double dSize = log10DomainSize();
145 
146  for (auto node : nodes())
147  param += cpt(node).content()->realSize();
148 
149  double compressionRatio = log10(1.0 * param) - dSize;
150 
151  std::stringstream s;
152  s << "BN{nodes: " << size() << ", arcs: " << dag().sizeArcs() << ", ";
153 
154  if (dSize > 6)
155  s << "domainSize: 10^" << dSize;
156  else
157  s << "domainSize: " << std::round(std::pow(10.0, dSize));
158 
159  s << ", parameters: " << param << ", compression ratio: ";
160 
161  if (compressionRatio > -3)
162  s << trunc(100.0 - std::pow(10.0, compressionRatio + 2.0));
163  else
164  s << "100-10^" << compressionRatio + 2.0;
165 
166  s << "% }";
167 
168  return s.str();
169  }
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:93
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:112
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
double log10DomainSize() const
Definition: DAGmodel_inl.h:72
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
+ Here is the caller graph for this function:

◆ uninstallCPT()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::uninstallCPT ( NodeId  id)
noexcept

uninstall a local CPT.

Warning
Nothing happens if no local CPT for this nodeId or if the node is not installed.

Definition at line 242 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, gum::BayesNetFragment< GUM_SCALAR >::__localCPTs, gum::BayesNetFragment< GUM_SCALAR >::_installArc(), gum::BayesNetFragment< GUM_SCALAR >::_uninstallCPT(), gum::BayesNetFragment< GUM_SCALAR >::cpt(), gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_onContextualize(), and gum::BayesNetFragment< GUM_SCALAR >::uninstallNode().

242  {
243  if (__localCPTs.exists(id)) {
244  _uninstallCPT(id);
245 
246  // re-create arcs from referred potential
247  const Potential< GUM_SCALAR >& pot = cpt(id);
248 
249  for (Idx i = 1; i < pot.nbrDim(); i++) {
250  NodeId parent = __bn.idFromName(pot.variable(i).name());
251 
252  if (isInstalledNode(parent)) _installArc(parent, id);
253  }
254  }
255  }
NodeProperty< const Potential< GUM_SCALAR > *> __localCPTs
Mapping between the variable&#39;s id and their CPT specific to this Fragment.
void _installArc(NodeId from, NodeId to) noexcept
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const override
Returns the CPT of a variable.
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
void _uninstallCPT(NodeId id) noexcept
uninstall a local CPT.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uninstallNode()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::uninstallNode ( NodeId  id)
noexcept

uninstall a node referenced by its nodeId

Warning
nothing happens if the node is not installed

Definition at line 171 of file BayesNetFragment_tpl.h.

References gum::DAGmodel::_dag, gum::DiGraph::eraseNode(), gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode(), and gum::BayesNetFragment< GUM_SCALAR >::uninstallCPT().

Referenced by gum::BayesNetFragment< GUM_SCALAR >::whenNodeDeleted().

171  {
172  if (isInstalledNode(id)) {
173  this->_dag.eraseNode(id);
174  uninstallCPT(id);
175  }
176  }
void uninstallCPT(NodeId id) noexcept
uninstall a local CPT.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Definition: diGraph_inl.h:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ variable()

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::BayesNetFragment< GUM_SCALAR >::variable ( NodeId  id) const
overridevirtual

Returns a constant reference over a variabe given it's node id.

Exceptions
NotFoundIf no variable's id matches varId.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 95 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, GUM_ERROR, and gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode().

Referenced by gum::BayesNetFragment< GUM_SCALAR >::installCPT().

95  {
96  if (!isInstalledNode(id)) GUM_ERROR(NotFound, id << " is not installed");
97 
98  return __bn.variable(id);
99  }
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ variableFromName()

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::BayesNetFragment< GUM_SCALAR >::variableFromName ( const std::string &  name) const
overridevirtual

Getter by name.

Exceptions
NotFoundif no such name exists in the graph.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 124 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::__bn, GUM_ERROR, and gum::BayesNetFragment< GUM_SCALAR >::isInstalledNode().

125  {
126  NodeId id = __bn.idFromName(name);
127 
128  if (!isInstalledNode(id))
129  GUM_ERROR(NotFound, "variable " << name << " is not installed");
130 
131  return __bn.variable(id);
132  }
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ variableNodeMap()

template<typename GUM_SCALAR >
INLINE const VariableNodeMap & gum::BayesNetFragment< GUM_SCALAR >::variableNodeMap ( ) const
overridevirtual

Returns a constant reference to the VariableNodeMap of this BN.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 88 of file BayesNetFragment_tpl.h.

References GUM_ERROR.

88  {
89  GUM_ERROR(FatalError,
90  "Not implemented yet. please use referent bayesnet method");
91  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52

◆ whenArcAdded()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::whenArcAdded ( const void *  src,
NodeId  from,
NodeId  to 
)
overridevirtualnoexcept

the action to take when a new arc is inserted into the graph

Parameters
srcthe object that sent the signal
fromthe id of tail of the new arc inserted into the graph
tothe id of head of the new arc inserted into the graph

Implements gum::DiGraphListener.

Definition at line 60 of file BayesNetFragment_tpl.h.

62  {
63  // nothing to do
64  }

◆ whenArcDeleted()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::whenArcDeleted ( const void *  src,
NodeId  from,
NodeId  to 
)
overridevirtualnoexcept

the action to take when an arc has just been removed from the graph

Parameters
srcthe object that sent the signal
fromthe id of tail of the arc removed from the graph
tothe id of head of the arc removed from the graph

Implements gum::DiGraphListener.

Definition at line 66 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::_uninstallArc(), and gum::DAGmodel::dag().

68  {
69  if (dag().existsArc(from, to)) _uninstallArc(from, to);
70  }
void _uninstallArc(NodeId from, NodeId to) noexcept
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:60
+ Here is the call graph for this function:

◆ whenNodeAdded()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::whenNodeAdded ( const void *  src,
NodeId  id 
)
overridevirtualnoexcept

the action to take when a new node is inserted into the graph

Parameters
srcthe object that sent the signal
idthe id of the new node inserted into the graph

Implements gum::DiGraphListener.

Definition at line 50 of file BayesNetFragment_tpl.h.

51  {
52  // nothing to do
53  }

◆ whenNodeDeleted()

template<typename GUM_SCALAR >
INLINE void gum::BayesNetFragment< GUM_SCALAR >::whenNodeDeleted ( const void *  src,
NodeId  id 
)
overridevirtualnoexcept

the action to take when a node has just been removed from the graph

Parameters
srcthe object that sent the signal
idthe id of the node has just been removed from the graph

Implements gum::DiGraphListener.

Definition at line 55 of file BayesNetFragment_tpl.h.

References gum::BayesNetFragment< GUM_SCALAR >::uninstallNode().

56  {
57  uninstallNode(id);
58  }
void uninstallNode(NodeId id) noexcept
uninstall a node referenced by its nodeId
+ Here is the call graph for this function:

Member Data Documentation

◆ __bn

◆ __localCPTs

◆ _dag

◆ _graph

DiGraph* gum::DiGraphListener::_graph
protectedinherited

the graph to listen to

Definition at line 96 of file diGraphListener.h.

Referenced by gum::DiGraphListener::DiGraphListener().


The documentation for this class was generated from the following files: