56 template < GUM_Numeric GUM_SCALAR >
64 this->
dag_.addNodeWithId(elt.
id());
72 this->
dag_.addArc(arc.tail(), arc.head());
79 template < GUM_Numeric GUM_SCALAR >
86 template < GUM_Numeric GUM_SCALAR >
92 template < GUM_Numeric GUM_SCALAR >
97 template < GUM_Numeric GUM_SCALAR >
109 template < GUM_Numeric GUM_SCALAR >
111 return _get_(varId).cpf();
114 template < GUM_Numeric GUM_SCALAR >
119 template < GUM_Numeric GUM_SCALAR >
121 return _get_(
id).type().variable();
124 template < GUM_Numeric GUM_SCALAR >
129 template < GUM_Numeric GUM_SCALAR >
131 return _get_(name).id();
134 template < GUM_Numeric GUM_SCALAR >
137 return _get_(name).type().variable();
140 template < GUM_Numeric GUM_SCALAR >
142 if (this->
dag_.exists(
id)) {
149 template < GUM_Numeric GUM_SCALAR >
156 template < GUM_Numeric GUM_SCALAR >
159 for (
const auto node: this->
nodes()) {
167 template < GUM_Numeric GUM_SCALAR >
169 std::string tab =
" ";
170 std::stringstream output;
171 output << std::format(
"digraph \"{}\" {{\n",
_class_->name());
173 for (
const auto node: this->
nodes()) {
175 for (
const auto chi: this->
children(node)) {
176 output << std::format(
"{}\"{}\" -> \"{}\";\n",
182 output << std::format(
"{}\"{}\";\n", tab,
variable(node).name());
Headers of ClassBayesNet<GUM_SCALAR>.
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
DAG dag_
The DAG of this Directed Graphical Model.
Size size() const final
Returns the number of variables in this Directed Graphical Model.
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
const NodeGraphPart & nodes() const final
Returns a named copy of the internal DAG: each node id is assigned the name of the corresponding vari...
Base class for discrete random variable.
Exception : fatal (unknown ?) error.
IBayesNet()
Default constructor.
IBayesNet< GUM_SCALAR > & operator=(const IBayesNet< GUM_SCALAR > &source)
Copy operator.
Exception : node does not exist.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Exception : the element we looked for cannot be found.
Container used to map discrete variables with nodes.
This class decorates a gum::prm::Class<GUM_SCALAR> has an IBaseBayesNet.
~ClassBayesNet() override
Destructor.
ClassBayesNet(const PRMClass< GUM_SCALAR > &c)
Default constructor.
const DiscreteVariable & variableFromName(std::string_view name) const override
See gum::IBaseBayesNet::variableFromName().
std::string toDot() const override
NodeId nodeId(const DiscreteVariable &var) const override
See gum::IBaseBayesNet::nodeId().
NodeProperty< Size > _modalities_
NodeId idFromName(std::string_view name) const override
See gum::IBaseBayesNet::idFromName().
const VariableNodeMap & variableNodeMap() const override
See gum::IBaseBayesNet::variableNodeMap().
HashTable< const DiscreteVariable *, const PRMClassElement< GUM_SCALAR > * > _varNodeMap_
Mapping between DiscreteVariable and their NodeId.
const NodeProperty< Size > & modalities() const
See gum::IBaseBayesNet::modalities().
const Tensor< GUM_SCALAR > & cpt(NodeId varId) const override
Returns the CPT of a node in this ClassBayesNet<GUM_SCALAR>.
const PRMClassElement< GUM_SCALAR > & _get_(NodeId id) const
Private getter with type checking in case the id is not a formal PRMAttribute.
void _init_(const PRMClass< GUM_SCALAR > &c)
const PRMClass< GUM_SCALAR > * _class_
The PRMClassElementContainer decorated by this.
const DiscreteVariable & variable(NodeId id) const override
See gum::IBaseBayesNet::variable().
ClassBayesNet< GUM_SCALAR > & operator=(const ClassBayesNet< GUM_SCALAR > &from)
Copy operator.
virtual const DAG & containerDag() const
Returns the gum::DAG of this PRMClassElementContainer.
virtual bool exists(std::string_view name) const
Returns true if a member with the given name exists in this PRMClassElementContainer or in the PRMCla...
Abstract class representing an element of PRM class.
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
PRMClassElement< GUM_SCALAR > & get(NodeId id) override
See gum::prm::PRMClassElementContainer<GUM_SCALAR>::get(NodeId).
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
aGrUM's inline/outline selection
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities