aGrUM  0.13.2
gum::prm::ClassBayesNet< GUM_SCALAR > Class Template Reference

This class decorates a gum::prm::Class<GUM_SCALAR> has an IBaseBayesNet. More...

#include <agrum/PRM/classBayesNet.h>

+ Inheritance diagram for gum::prm::ClassBayesNet< GUM_SCALAR >:
+ Collaboration diagram for gum::prm::ClassBayesNet< 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)
 
Constructors & destructor.
 ClassBayesNet (const PRMClass< GUM_SCALAR > &c)
 Default constructor. More...
 
 ClassBayesNet (const ClassBayesNet< GUM_SCALAR > &from)
 Copy constructor. More...
 
ClassBayesNet< GUM_SCALAR > & operator= (const ClassBayesNet< GUM_SCALAR > &from)
 Copy operator. More...
 
virtual ~ClassBayesNet ()
 Destructor. More...
 
Variable manipulation methods.
virtual const Potential< GUM_SCALAR > & cpt (NodeId varId) const
 Returns the CPT of a node in this ClassBayesNet<GUM_SCALAR>. More...
 
virtual const VariableNodeMapvariableNodeMap () const
 See gum::IBaseBayesNet::variableNodeMap(). More...
 
virtual const DiscreteVariablevariable (NodeId id) const
 See gum::IBaseBayesNet::variable(). More...
 
virtual NodeId nodeId (const DiscreteVariable &var) const
 See gum::IBaseBayesNet::nodeId(). More...
 
virtual NodeId idFromName (const std::string &name) const
 See gum::IBaseBayesNet::idFromName(). More...
 
virtual const DiscreteVariablevariableFromName (const std::string &name) const
 See gum::IBaseBayesNet::variableFromName(). More...
 
const NodeProperty< Size > & modalities () const
 See gum::IBaseBayesNet::modalities(). More...
 
Graphical methods
virtual std::string toDot () const
 
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...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::ClassBayesNet< GUM_SCALAR >

This class decorates a gum::prm::Class<GUM_SCALAR> has an IBaseBayesNet.

Template Parameters
GUM_SCALARThe type of scalar to use.

This class filters PRMAttribute and PRMAggregate in a way it can be interpreted as a IBayesNet.

SlotChains and PRMReferenceSlot are not represented.

Remember that a ClassBayesNet<GUM_SCALAR> does not contain input nodes parents and output nodes children. Thus you should be careful when using one of the BayesNetInference over a ClassBayesNet<GUM_SCALAR> since some variables are missing in the DAG but not in the nodes CPT.

Definition at line 57 of file classBayesNet.h.

Constructor & Destructor Documentation

template<typename GUM_SCALAR >
INLINE gum::prm::ClassBayesNet< GUM_SCALAR >::ClassBayesNet ( const PRMClass< GUM_SCALAR > &  c)

Default constructor.

Parameters
cThe Class<GUM_SCALAR> decorated by this ClassBayesNet<GUM_SCALAR>.

Definition at line 59 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__init().

59  :
60  IBayesNet< GUM_SCALAR >(),
61  __class(&c) {
62  GUM_CONSTRUCTOR(ClassBayesNet);
63  __init(c);
64  }
void __init(const PRMClass< GUM_SCALAR > &c)
const PRMClass< GUM_SCALAR > * __class
The PRMClassElementContainer decorated by this.
ClassBayesNet(const PRMClass< GUM_SCALAR > &c)
Default constructor.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE gum::prm::ClassBayesNet< GUM_SCALAR >::ClassBayesNet ( const ClassBayesNet< GUM_SCALAR > &  from)

Copy constructor.

Definition at line 67 of file classBayesNet_tpl.h.

68  :
69  IBayesNet< GUM_SCALAR >(from),
70  __class(from.__class) {
71  GUM_CONS_CPY(ClassBayesNet);
72  }
const PRMClass< GUM_SCALAR > * __class
The PRMClassElementContainer decorated by this.
ClassBayesNet(const PRMClass< GUM_SCALAR > &c)
Default constructor.
template<typename GUM_SCALAR >
INLINE gum::prm::ClassBayesNet< GUM_SCALAR >::~ClassBayesNet ( )
virtual

Destructor.

Definition at line 75 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::operator=().

75  {
76  GUM_DESTRUCTOR(ClassBayesNet);
77  }
ClassBayesNet(const PRMClass< GUM_SCALAR > &c)
Default constructor.

+ Here is the call graph for this function:

Member Function Documentation

template<typename GUM_SCALAR >
INLINE const PRMClassElement< GUM_SCALAR > & gum::prm::ClassBayesNet< GUM_SCALAR >::__get ( NodeId  id) const
private

Private getter with type checking in case the id is not a formal PRMAttribute.

Exceptions
NotFoundRaised if id is not a formal attribute.

Definition at line 129 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__class, gum::DAGmodel::_dag, gum::NodeGraphPart::exists(), and GUM_ERROR.

Referenced by gum::prm::ClassBayesNet< GUM_SCALAR >::cpt(), gum::prm::ClassBayesNet< GUM_SCALAR >::idFromName(), gum::prm::ClassBayesNet< GUM_SCALAR >::variable(), and gum::prm::ClassBayesNet< GUM_SCALAR >::variableFromName().

129  {
130  if (this->_dag.exists(id)) {
131  return __class->get(id);
132  } else {
133  GUM_ERROR(NotFound, "no element found with that id.");
134  }
135  }
const PRMClass< GUM_SCALAR > * __class
The PRMClassElementContainer decorated by this.
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
bool exists(const NodeId id) const
alias for existsNode
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const PRMClassElement< GUM_SCALAR > & gum::prm::ClassBayesNet< GUM_SCALAR >::__get ( const std::string &  name) const
private

Private getter with type checking in case the id is not a formal PRMAttribute.

Exceptions
NotFoundRaised if id is not a formal attribute.

Definition at line 139 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__class, and GUM_ERROR.

139  {
140  try {
141  return __class->get(name);
142  } catch (NotFound&) {
143  GUM_ERROR(NotFound, "no element found with that id.");
144  }
145  }
const PRMClass< GUM_SCALAR > * __class
The PRMClassElementContainer decorated by this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
template<typename GUM_SCALAR >
void gum::prm::ClassBayesNet< GUM_SCALAR >::__init ( const PRMClass< GUM_SCALAR > &  c)
private

Definition at line 33 of file classBayesNet_tpl.h.

References gum::prm::PRMClassElementContainer< GUM_SCALAR >::containerDag(), gum::prm::PRMClass< GUM_SCALAR >::get(), gum::prm::PRMClassElement< GUM_SCALAR >::id(), and gum::prm::PRMClassElement< GUM_SCALAR >::type().

Referenced by gum::prm::ClassBayesNet< GUM_SCALAR >::ClassBayesNet().

33  {
34  for (const auto node : c.containerDag().nodes()) {
35  try {
36  // Adding the attribute
39  const PRMClassElement< GUM_SCALAR >& elt = c.get(node);
40  this->_dag.addNodeWithId(elt.id());
41  this->__varNodeMap.insert(&(elt.type().variable()), &elt);
42  }
43  } catch (NotFound&) {
44  // Not an attribute
45  }
46  }
47 
48  for (const auto& arc : c.containerDag().arcs()) {
49  try {
50  this->_dag.addArc(arc.tail(), arc.head());
51  } catch (InvalidNode&) {
52  // Not added means not an attribute
53  }
54  }
55  }
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
static INLINE bool isAttribute(const PRMClassElement &elt)
Returns true if obj_ptr is of type PRMAttribute.
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
static INLINE bool isAggregate(const PRMClassElement &elt)
Return true if obj is of type PRMAggregate.
HashTable< const DiscreteVariable *, const PRMClassElement< GUM_SCALAR > * > __varNodeMap
Mapping between DiscreteVariable and their NodeId.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 102 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().

102 { return _dag.arcs(); }
const ArcSet & arcs() const
returns the set of arcs stored within 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:

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 109 of file DAGmodel_inl.h.

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

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

109  {
110  return _dag.children(id);
111  }
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:

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  };
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104

+ Here is the call graph for this function:

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

Get an instantiation over all the variables of the model.

Definition at line 84 of file DAGmodel_inl.h.

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

84  {
85  Instantiation I;
86 
87  for (const auto node : dag())
88  I << variable(node);
89 
90  return I;
91  }
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
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:

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::prm::ClassBayesNet< GUM_SCALAR >::cpt ( NodeId  varId) const
virtual

Returns the CPT of a node in this ClassBayesNet<GUM_SCALAR>.

If the node is an PRMAggregate, this will raise an OperationNotAllowed since PRMAggregate's CPT are define at instantiation only.

Parameters
varIda variable id.
Returns
the Potential of varId.
Exceptions
NotFoundraised if varId does not match any variable in this IBayesNet.
OperationNotAllowedraised if varId is an PRMAggregate.

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 93 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__get().

93  {
94  return __get(varId).cpf();
95  }
const PRMClassElement< GUM_SCALAR > & __get(NodeId id) const
Private getter with type checking in case the id is not a formal PRMAttribute.

+ Here is the call graph for this function:

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.

References gum::DiscreteVariable::domainSize(), gum::DAGmodel::nodes(), gum::DAGmodel::parents(), and gum::IBayesNet< GUM_SCALAR >::variable().

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  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
Definition: IBayesNet_tpl.h:76
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 NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

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

Retursn true if this Directed Graphical Model is empty.

Definition at line 97 of file DAGmodel_inl.h.

References gum::DAGmodel::size().

97 { return size() == 0; }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94

+ Here is the call graph for this function:

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 118 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().

118  {
119  if (this == &other) return true;
120 
121  if (size() != other.size()) return false;
122 
123  if (sizeArcs() != other.sizeArcs()) return false;
124 
125  for (const auto& nid : nodes()) {
126  try {
127  other.idFromName(variable(nid).name());
128  } catch (NotFound) { return false; }
129  }
130 
131  for (const auto& arc : arcs()) {
132  if (!other.arcs().exists(Arc(other.idFromName(variable(arc.tail()).name()),
133  other.idFromName(variable(arc.head()).name()))))
134  return false;
135  }
136 
137  return true;
138  }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94
const ArcSet & arcs() const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:102
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:100
virtual const DiscreteVariable & variable(NodeId id) const =0
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:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE NodeId gum::prm::ClassBayesNet< GUM_SCALAR >::idFromName ( const std::string &  name) const
virtual

See gum::IBaseBayesNet::idFromName().

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 117 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__get().

117  {
118  return __get(name).id();
119  }
const PRMClassElement< GUM_SCALAR > & __get(NodeId id) const
Private getter with type checking in case the id is not a formal PRMAttribute.

+ Here is the call graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

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:113

+ Here is the call graph for this function:

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 73 of file DAGmodel_inl.h.

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

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

73  {
74  double dSize = 0.0;
75 
76  for (const auto node : nodes()) {
77  dSize += std::log10(variable(node).domainSize());
78  }
79 
80  return dSize;
81  }
virtual const DiscreteVariable & variable(NodeId id) const =0
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:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

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:113

+ Here is the call graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

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:113

+ Here is the call graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

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:113

+ Here is the call graph for this function:

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.

References gum::DiscreteVariable::domainSize(), gum::DAGmodel::nodes(), and gum::IBayesNet< GUM_SCALAR >::variable().

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  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
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:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::__minimalCondSetVisitDn(), gum::IBayesNet< GUM_SCALAR >::__minimalCondSetVisitUp(), gum::DAGmodel::_dag, gum::ArcGraphPart::children(), gum::Set< Key, Alloc >::contains(), and gum::ArcGraphPart::parents().

Referenced by gum::IBayesNet< GUM_SCALAR >::minimalCondSet().

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  }
void __minimalCondSetVisitDn(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const
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
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
void __minimalCondSetVisitUp(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisitedUp, NodeSet &alreadyVisitedDn) const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::minimalCondSet().

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

+ Here is the call graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

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:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::cpt(), and gum::DAGmodel::nodes().

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:113

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE const NodeProperty< Size > & gum::prm::ClassBayesNet< GUM_SCALAR >::modalities ( ) const

See gum::IBaseBayesNet::modalities().

Definition at line 149 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__modalities, gum::DAGmodel::nodes(), and gum::prm::ClassBayesNet< GUM_SCALAR >::variable().

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

149  {
150  if (__modalities.empty()) {
151  for (const auto node : this->nodes()) {
152  __modalities.insert(node, (Size)variable(node).domainSize());
153  }
154  }
155 
156  return __modalities;
157  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
virtual const DiscreteVariable & variable(NodeId id) const
See gum::IBaseBayesNet::variable().
NodeProperty< Size > __modalities
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 98 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().

98  {
99  if (clear
100  || (__mutableMoralGraph == nullptr)) { // we have to call _moralGraph
101  if (__mutableMoralGraph == nullptr) {
102  __mutableMoralGraph = new UndiGraph();
103  } else {
104  // clear is True ,__mutableMoralGraph exists
106  }
107 
108  __moralGraph();
109  }
110 
111  return *__mutableMoralGraph;
112  }
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:

template<typename GUM_SCALAR >
INLINE NodeId gum::prm::ClassBayesNet< GUM_SCALAR >::nodeId ( const DiscreteVariable var) const
virtual

See gum::IBaseBayesNet::nodeId().

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 111 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__varNodeMap.

111  {
112  return __varNodeMap[&var]->id();
113  }
HashTable< const DiscreteVariable *, const PRMClassElement< GUM_SCALAR > * > __varNodeMap
Mapping between DiscreteVariable and their NodeId.
INLINE const NodeGraphPart & gum::DAGmodel::nodes ( ) const
inherited

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

Definition at line 113 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::BayesNet< GUM_SCALAR >::beginTopologyTransformation(), gum::BayesNetFragment< GUM_SCALAR >::checkConsistency(), gum::IBayesNet< GUM_SCALAR >::dim(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN(), gum::BayesNet< GUM_SCALAR >::endTopologyTransformation(), gum::Estimator< GUM_SCALAR >::Estimator(), gum::BayesNet< GUM_SCALAR >::generateCPTs(), gum::getMaxModality(), gum::DAGmodel::hasSameStructure(), gum::IBayesNet< GUM_SCALAR >::jointProbability(), gum::DAGmodel::log10DomainSize(), gum::IBayesNet< GUM_SCALAR >::log2JointProbability(), gum::IBayesNet< GUM_SCALAR >::maxNonOneParam(), gum::IBayesNet< GUM_SCALAR >::maxParam(), gum::IBayesNet< GUM_SCALAR >::maxVarDomainSize(), gum::IBayesNet< GUM_SCALAR >::minNonZeroParam(), gum::IBayesNet< GUM_SCALAR >::minParam(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::IBayesNet< GUM_SCALAR >::toDot(), gum::IBayesNet< GUM_SCALAR >::toString(), gum::credal::CredalNet< GUM_SCALAR >::toString(), and gum::BayesNetFragment< GUM_SCALAR >::~BayesNetFragment().

113  {
114  return (NodeGraphPart&)_dag;
115  }
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:200
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.

References gum::IBayesNet< GUM_SCALAR >::operator==().

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

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE ClassBayesNet< GUM_SCALAR > & gum::prm::ClassBayesNet< GUM_SCALAR >::operator= ( const ClassBayesNet< GUM_SCALAR > &  from)

Copy operator.

Definition at line 81 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__class, and gum::IBayesNet< GUM_SCALAR >::operator=().

Referenced by gum::prm::ClassBayesNet< GUM_SCALAR >::~ClassBayesNet().

81  {
82  if (this != &from) {
84 
85  __class = from.__class;
86  }
87 
88  return *this;
89  }
const PRMClass< GUM_SCALAR > * __class
The PRMClassElementContainer decorated by this.
IBayesNet< GUM_SCALAR > & operator=(const IBayesNet< GUM_SCALAR > &source)
Copy operator.
Definition: IBayesNet_tpl.h:64

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::cpt(), gum::Instantiation::end(), gum::IBayesNet< GUM_SCALAR >::idFromName(), gum::Instantiation::inc(), gum::BijectionImplementation< T1, T2, Alloc, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::insert(), gum::DAGmodel::nodes(), gum::BijectionImplementation< T1, T2, Alloc, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::second(), gum::Instantiation::setFirst(), gum::DAGmodel::size(), gum::DAGmodel::sizeArcs(), gum::Instantiation::val(), gum::IBayesNet< GUM_SCALAR >::variable(), gum::Instantiation::variable(), and gum::IBayesNet< GUM_SCALAR >::variableFromName().

Referenced by gum::IBayesNet< GUM_SCALAR >::operator!=().

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 size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Size sizeArcs() const
Returns the number of arcs in this Directed Graphical Model.
Definition: DAGmodel_inl.h:100
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:113
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 104 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::IBayesNet< GUM_SCALAR >::dim(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::DAGmodel::parents(), gum::BayesNet< GUM_SCALAR >::reverseArc(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), and gum::IBayesNet< GUM_SCALAR >::toDot().

104  {
105  return _dag.parents(id);
106  }
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:

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  };
virtual NodeId idFromName(const std::string &name) const =0
Getter by name.
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104

+ Here is the call graph for this function:

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 35 of file DAGmodel_inl.h.

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

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

35  {
36  try {
37  return __properties()[name];
38  } catch (NotFound&) {
39  std::string msg = "The following property does not exists: ";
40  GUM_ERROR(NotFound, msg + name);
41  }
42  }
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:64
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 46 of file DAGmodel_inl.h.

References gum::DAGmodel::__properties().

47  {
48  try {
49  return __properties()[name];
50  } catch (NotFound&) { return byDefault; }
51  }
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:64

+ Here is the call graph for this function:

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 54 of file DAGmodel_inl.h.

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

Referenced by gum::IBayesNet< GUM_SCALAR >::IBayesNet().

54  {
55  try {
56  __properties()[name] = value;
57  } catch (NotFound&) { __properties().insert(name, value); }
58  }
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:64
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:

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

Returns the number of variables in this Directed Graphical Model.

Definition at line 94 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< GUM_SCALAR >::operator==(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::IBayesNet< GUM_SCALAR >::toDot(), and gum::IBayesNet< GUM_SCALAR >::toString().

94 { return dag().size(); }
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
Size size() const
alias for sizeNodes

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Returns the number of arcs in this Directed Graphical Model.

Definition at line 100 of file DAGmodel_inl.h.

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

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

100 { 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:

template<typename GUM_SCALAR >
INLINE std::string gum::prm::ClassBayesNet< GUM_SCALAR >::toDot ( ) const
virtual
Returns
Returns a dot representation of this IBayesNet.

Reimplemented from gum::IBayesNet< GUM_SCALAR >.

Definition at line 160 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__class, gum::DAGmodel::children(), gum::Variable::name(), gum::DAGmodel::nodes(), gum::DAGmodel::parents(), gum::DAGmodel::size(), and gum::prm::ClassBayesNet< GUM_SCALAR >::variable().

160  {
161  std::string tab = " ";
162  std::stringstream output;
163  output << "digraph \"";
164  output << __class->name() << "\" {" << std::endl;
165 
166  for (const auto node : this->nodes()) {
167  if (this->children(node).size() > 0)
168  for (const auto chi : this->children(node)) {
169  output << tab << "\"" << variable(node).name() << "\" -> ";
170  output << "\"" << variable(chi).name() << "\";" << std::endl;
171  }
172  else if (this->parents(node).size() == 0) {
173  output << tab << "\"" << variable(node).name() << "\";" << std::endl;
174  }
175  }
176 
177  output << "}" << std::endl;
178  return output.str();
179  }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94
virtual const DiscreteVariable & variable(NodeId id) const
See gum::IBaseBayesNet::variable().
const PRMClass< GUM_SCALAR > * __class
The PRMClassElementContainer decorated by this.
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Definition: DAGmodel_inl.h:109
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Definition: DAGmodel_inl.h:104
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113
const std::string & name() const
returns the name of the variable

+ Here is the call graph for this function:

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 114 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().

114  {
115  return this->dag().topologicalOrder(clear);
116  }
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

References gum::IBayesNet< GUM_SCALAR >::cpt(), gum::DAGmodel::dag(), gum::DAGmodel::log10DomainSize(), gum::DAGmodel::nodes(), gum::DAGmodel::size(), and gum::ArcGraphPart::sizeArcs().

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  }
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:94
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:61
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const =0
Returns the CPT of a variable.
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
double log10DomainSize() const
Definition: DAGmodel_inl.h:73
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::prm::ClassBayesNet< GUM_SCALAR >::variable ( NodeId  id) const
virtual

See gum::IBaseBayesNet::variable().

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 105 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__get().

Referenced by gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), and gum::prm::ClassBayesNet< GUM_SCALAR >::toDot().

105  {
106  return __get(id).type().variable();
107  }
const PRMClassElement< GUM_SCALAR > & __get(NodeId id) const
Private getter with type checking in case the id is not a formal PRMAttribute.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::prm::ClassBayesNet< GUM_SCALAR >::variableFromName ( const std::string &  name) const
virtual

See gum::IBaseBayesNet::variableFromName().

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 122 of file classBayesNet_tpl.h.

References gum::prm::ClassBayesNet< GUM_SCALAR >::__get().

123  {
124  return __get(name).type().variable();
125  }
const PRMClassElement< GUM_SCALAR > & __get(NodeId id) const
Private getter with type checking in case the id is not a formal PRMAttribute.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE const VariableNodeMap & gum::prm::ClassBayesNet< GUM_SCALAR >::variableNodeMap ( ) const
virtual

See gum::IBaseBayesNet::variableNodeMap().

Implements gum::IBayesNet< GUM_SCALAR >.

Definition at line 99 of file classBayesNet_tpl.h.

References GUM_ERROR.

99  {
100  GUM_ERROR(FatalError, "Sorry no VarMap in a ClassBayesNet.");
101  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

Member Data Documentation

template<typename GUM_SCALAR>
const PRMClass< GUM_SCALAR >* gum::prm::ClassBayesNet< GUM_SCALAR >::__class
private
template<typename GUM_SCALAR>
NodeProperty< Size > gum::prm::ClassBayesNet< GUM_SCALAR >::__modalities
mutableprivate

Definition at line 146 of file classBayesNet.h.

Referenced by gum::prm::ClassBayesNet< GUM_SCALAR >::modalities().

template<typename GUM_SCALAR>
HashTable< const DiscreteVariable*, const PRMClassElement< GUM_SCALAR >* > gum::prm::ClassBayesNet< GUM_SCALAR >::__varNodeMap
private

Mapping between DiscreteVariable and their NodeId.

Definition at line 131 of file classBayesNet.h.

Referenced by gum::prm::ClassBayesNet< GUM_SCALAR >::nodeId().

DAG gum::DAGmodel::_dag
protectedinherited

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