34 template <
typename GUM_SCALAR >
42 template <
typename GUM_SCALAR >
46 for (
auto node :
nodes())
52 template <
typename GUM_SCALAR >
57 template <
typename GUM_SCALAR >
62 template <
typename GUM_SCALAR >
68 template <
typename GUM_SCALAR >
78 template <
typename GUM_SCALAR >
89 template <
typename GUM_SCALAR >
93 "Not implemented yet. please use referent bayesnet method");
96 template <
typename GUM_SCALAR >
101 return __bn.variable(
id);
104 template <
typename GUM_SCALAR >
115 template <
typename GUM_SCALAR >
126 template <
typename GUM_SCALAR >
128 const std::string& name)
const {
134 return __bn.variable(
id);
139 template <
typename GUM_SCALAR >
145 template <
typename GUM_SCALAR >
147 if (!
__bn.dag().existsNode(
id))
154 for (
auto pa : this->
__bn.parents(
id)) {
159 for (
auto son : this->
__bn.children(
id))
164 template <
typename GUM_SCALAR >
169 for (
auto pa : this->
__bn.parents(
id))
173 template <
typename GUM_SCALAR >
181 template <
typename GUM_SCALAR >
187 template <
typename GUM_SCALAR >
193 template <
typename GUM_SCALAR >
202 for (
Idx i = 1; i < pot->nbrDim(); i++) {
203 NodeId parent =
__bn.idFromName(pot->variable(i).name());
214 template <
typename GUM_SCALAR >
217 if (!
dag().existsNode(
id))
222 "The potential is not a marginal for __bn.variable <" 228 for (
Idx i = 1; i < pot->
nbrDim(); i++) {
231 "Variable <" << pot->
variable(i).name()
232 <<
"> is not in the parents of node " << id);
238 template <
typename GUM_SCALAR >
244 template <
typename GUM_SCALAR >
260 template <
typename GUM_SCALAR >
273 "The potential is not a marginal for __bn.variable <" 274 <<
__bn.variable(
id).name() <<
">");
280 template <
typename GUM_SCALAR >
285 const auto&
cpt = this->
cpt(
id);
288 for (
Idx i = 1; i <
cpt.nbrDim(); i++) {
292 return (this->
parents(
id) == cpt_parents);
295 template <
typename GUM_SCALAR >
297 for (
auto node :
nodes())
303 template <
typename GUM_SCALAR >
305 std::stringstream output;
306 output <<
"digraph \"";
310 static std::string inFragmentStyle =
"fillcolor=\"#ffffaa\"," 312 "fontcolor=\"#000000\"";
313 static std::string styleWithLocalCPT =
"fillcolor=\"#ffddaa\"," 315 "fontcolor=\"#000000\"";
316 static std::string notConsistantStyle =
"fillcolor=\"#ff0000\"," 318 "fontcolor=\"#ffff00\"";
319 static std::string outFragmentStyle =
"fillcolor=\"#f0f0f0\"," 321 "fontcolor=\"#000000\"";
324 bn_name =
__bn.property(
"name");
325 }
catch (
NotFound&) { bn_name =
"no_name"; }
327 bn_name =
"Fragment of " + bn_name;
329 output << bn_name <<
"\" {" << std::endl;
330 output <<
" graph [bgcolor=transparent,label=\"" << bn_name <<
"\"];" 332 output <<
" node [style=filled];" << std::endl << std::endl;
334 for (
auto node :
__bn.nodes()) {
335 output <<
"\"" <<
__bn.variable(node).name() <<
"\" [comment=\"" << node
336 <<
":" <<
__bn.variable(node) <<
", \"";
340 output << notConsistantStyle;
342 output << styleWithLocalCPT;
344 output << inFragmentStyle;
346 output << outFragmentStyle;
348 output <<
"];" << std::endl;
353 std::string tab =
" ";
355 for (
auto node :
__bn.nodes()) {
356 if (
__bn.children(node).size() > 0) {
357 for (
auto child :
__bn.children(node)) {
358 output << tab <<
"\"" <<
__bn.variable(node).name() <<
"\" -> " 359 <<
"\"" <<
__bn.variable(child).name() <<
"\" [";
361 if (
dag().existsArc(
Arc(node, child)))
362 output << inFragmentStyle;
364 output << outFragmentStyle;
366 output <<
"];" << std::endl;
371 output <<
"}" << std::endl;
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
aGrUM's Potential is a multi-dimensional array with tensor operators.
virtual NodeId nodeId(const DiscreteVariable &var) const override
Return id node from discrete var pointer.
Abstract Base class for all diGraph Listener.
virtual void whenNodeDeleted(const void *src, NodeId id) noexcept override
the action to take when a node has just been removed from the graph
void uninstallCPT(NodeId id) noexcept
uninstall a local CPT.
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
NodeProperty< const Potential< GUM_SCALAR > *> __localCPTs
Mapping between the variable's id and their CPT specific to this Fragment.
virtual const DiscreteVariable & variableFromName(const std::string &name) const override
Getter by name.
void _installCPT(NodeId id, const Potential< GUM_SCALAR > *pot) noexcept
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
BayesNetFragment()=delete
void installCPT(NodeId id, const Potential< GUM_SCALAR > *pot)
install a local cpt for a node into the fragment.
virtual void whenArcAdded(const void *src, NodeId from, NodeId to) noexcept override
the action to take when a new arc is inserted into the graph
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
virtual const VariableNodeMap & variableNodeMap() const override
Returns a constant reference to the VariableNodeMap of this BN.
Container used to map discrete variables with nodes.
void _installArc(NodeId from, NodeId to) noexcept
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Base class for discrete random variable.
void installAscendants(NodeId id)
install a node and all its ascendants
Class representing the minimal interface for Bayesian Network.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual ~BayesNetFragment()
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const override
Returns the CPT of a variable.
const IBayesNet< GUM_SCALAR > & __bn
The referred BayesNet.
DAG _dag
The DAG of this Directed Graphical Model.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual const DiscreteVariable & variable(NodeId id) const override
Returns a constant reference over a variabe given it's node id.
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
const NodeGraphPart & nodes() const
Returns a constant reference to the dag of this Bayes Net.
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
virtual void whenArcDeleted(const void *src, NodeId from, NodeId to) noexcept override
the action to take when an arc has just been removed from the graph
Portion of a BN identified by the list of nodes and a BayesNet.
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
void installNode(NodeId id)
install a node referenced by its nodeId
virtual std::string toDot() const override
creates a dot representing the whole referred BN hilighting the fragment.
void uninstallNode(NodeId id) noexcept
uninstall a node referenced by its nodeId
bool isInstalledNode(NodeId id) const noexcept
check if a certain NodeId exists in the fragment
void installMarginal(NodeId id, const Potential< GUM_SCALAR > *pot)
install a local marginal for a node into the fragment.
bool checkConsistency() const noexcept
returns true if all nodes in the fragment are consistent
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
virtual NodeId idFromName(const std::string &name) const override
Getter by name.
Size Idx
Type for indexes.
virtual void whenNodeAdded(const void *src, NodeId id) noexcept override
the action to take when a new node is inserted into the graph
void _uninstallArc(NodeId from, NodeId to) noexcept
void _uninstallCPT(NodeId id) noexcept
uninstall a local CPT.
const std::string & name() const
returns the name of the variable
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
#define GUM_ERROR(type, msg)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.