63 template < GUM_Numeric GUM_SCALAR >
68 template < GUM_Numeric GUM_SCALAR >
74 template < GUM_Numeric GUM_SCALAR >
80 template < GUM_Numeric GUM_SCALAR >
88 template < GUM_Numeric GUM_SCALAR >
93 template < GUM_Numeric GUM_SCALAR >
97 res += f.second->domainSize();
102 template < GUM_Numeric GUM_SCALAR >
105 for (
auto node:
nodes()) {
106 auto v =
variable(node).domainSize();
107 if (v > res) { res = v; }
112 template < GUM_Numeric GUM_SCALAR >
114 GUM_SCALAR res = 1.0;
116 auto v = elt.second->min();
117 if (v < res) { res = v; }
122 template < GUM_Numeric GUM_SCALAR >
124 GUM_SCALAR res = 1.0;
126 auto v = elt.second->max();
127 if (v > res) { res = v; }
132 template < GUM_Numeric GUM_SCALAR >
134 GUM_SCALAR res = 1.0;
136 auto v = elt.second->minNonZero();
137 if (v < res) { res = v; }
142 template < GUM_Numeric GUM_SCALAR >
144 GUM_SCALAR res = 0.0;
146 auto v = elt.second->maxNonOne();
147 if (v > res) { res = v; }
152 template < GUM_Numeric GUM_SCALAR >
158 param +=
factor.second->content()->realSize();
163 if (dSize > 6) s << std::format(
"domainSize: 10^{}", dSize);
164 else s << std::format(
"domainSize: {}", std::round(std::pow(10.0, dSize)));
166 s << std::format(
", dim: {}}}", param);
171 template < GUM_Numeric GUM_SCALAR >
176 template < GUM_Numeric GUM_SCALAR >
182 for (
const auto node:
nodes()) {
183 const auto& name =
variable(node).name();
188 "(" + std::to_string(node) +
") " + name));
191 for (
const auto& edge:
edges()) {
195 std::to_string(edge.first()) +
" — "
196 + std::to_string(edge.second()));
204 template < GUM_Numeric GUM_SCALAR >
209 template < GUM_Numeric GUM_SCALAR >
218 for (
const auto node:
nodes()) {
219 const auto& name =
variable(node).name();
223 "(" + std::to_string(node) +
") " + name);
228 writer.
node(name, attributes);
232 std::vector< std::vector< NodeId > > scopes;
233 for (
const auto& kv:
factors()) {
234 std::vector< NodeId > scope(kv.first.begin(), kv.first.end());
235 std::sort(scope.begin(), scope.end());
236 scopes.push_back(std::move(scope));
238 std::sort(scopes.begin(), scopes.end());
240 auto factorName = [
this](
const std::vector< NodeId >& scope) {
241 std::string name =
"f";
242 for (
const auto node: scope)
243 name +=
"#" +
variable(node).name();
250 for (
const auto& scope: scopes) {
257 writer.
node(factorName(scope), attributes);
261 for (
const auto& scope: scopes)
262 for (
const auto node: scope)
268 template < GUM_Numeric GUM_SCALAR >
270 if (
size() != from.
size()) {
return false; }
277 for (
auto node:
nodes()) {
279 if (!from.
exists(v1.name()))
return false;
281 if (v1 != v2)
return false;
286 for (
const auto& elt:
factors()) {
287 const auto& key = elt.first;
288 const auto&
factor = *elt.second;
291 for (
const auto n: key)
294 if (!from.
factors().exists(fromkey)) {
return false; }
296 const auto& fromfactor = from.
factor(fromkey);
304 for (
Idx indice = 0; indice <
factor.nbrDim(); ++indice) {
309 if (std::pow(
factor.get(i) - fromfactor.get(j), (GUM_SCALAR)2) > tolerance) {
317 template < GUM_Numeric GUM_SCALAR >
323 template < GUM_Numeric GUM_SCALAR >
326 if (!this->
exists(name)) {
333 template < GUM_Numeric GUM_SCALAR >
337 NodeSet& alreadyVisited)
const {
338 if (alreadyVisited.
contains(node))
return;
339 alreadyVisited << node;
344 for (
auto neig:
graph_.neighbours(node))
349 template < GUM_Numeric GUM_SCALAR >
356 alreadyVisited << target;
358 for (
auto neig:
graph_.neighbours(target))
363 template < GUM_Numeric GUM_SCALAR >
367 for (
auto node: targets) {
Class representing Markov random fields.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Set of pairs of elements with fast search for both elements.
double epsilonStandard() const noexcept
NodeId idFromName(std::string_view name) const override
Returns the NodeId of a variable given its name.
const DiscreteVariable & variableFromName(std::string_view name) const override
Returns a constant reference over a variable given its name.
const DiscreteVariable & variable(NodeId id) const override
Returns a constant reference over a variable given its node id.
Base class for discrete random variable.
void setProperty(std::string_view name, std::string_view value)
Add or change a property of this GraphicalModel.
double log10DomainSize() const
const std::string & propertyWithDefault(std::string_view name, const std::string &byDefault) const
Return the value of the property name of this GraphicalModel.
Class representing the minimal interface for Markov random field.
virtual std::string toDot() const
IMarkovRandomField()
Default constructor.
GUM_SCALAR minParam() const
GUM_SCALAR maxParam() const
virtual const Tensor< GUM_SCALAR > & factor(const NodeSet &varIds) const =0
Returns the factor of a set of variable.
GUM_SCALAR minNonZeroParam() const
~IMarkovRandomField() override
Destructor.
Size maxVarDomainSize() const
virtual const FactorTable< GUM_SCALAR > & factors() const =0
Returns the set of factors as a IMarkovRandomField::FactorTable.
virtual std::string toDotAsFactorGraph() const
void _minimalCondSetVisit_(NodeId node, const NodeSet &soids, NodeSet &minimal, NodeSet &alreadyVisited) const
Size dim() const
Returns the dimension (the number of free parameters) in this bayes net.
bool operator==(const IMarkovRandomField< GUM_SCALAR > &from) const
This operator compares 2 BNs !
NodeSet minimalCondSet(NodeId target, const NodeSet &soids) const
IMarkovRandomField< GUM_SCALAR > & operator=(const IMarkovRandomField< GUM_SCALAR > &source)
Copy operator.
GUM_SCALAR maxNonOneParam() const
std::string toString() const
virtual const NodeSet & smallestFactorFromNode(NodeId node) const =0
Returns the smallest factor that contains this variable.
Class for assigning/browsing values to tuples of discrete variables.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
bool end() const
Returns true if the Instantiation reached the end.
void inc()
Operator increment.
Idx val(Idx i) const
Returns the current value of the variable at position i.
void setFirst()
Assign the first values to the tuple of the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
Exception : the element we looked for cannot be found.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
UGmodel()
Default constructor.
const NodeGraphPart & nodes() const final
Returns a named copy of the internal undirected graph: each node id is assigned the name of the corre...
UGmodel & operator=(const UGmodel &source)
Private copy operator.
bool exists(NodeId node) const final
Return true if this node exists in this graphical model.
UndiGraph graph_
The DAG of this Directed Graphical Model.
const EdgeSet & edges() const
return true if the edge node1-node2 exists in the UGModel
UndiGraph graph() const
Returns a named copy of the internal undirected graph: each node id is assigned the name of the corre...
Size sizeEdges() const
Returns the number of arcs in this Directed Graphical Model.
Size size() const final
Returns the number of variables in this Directed Graphical Model.
The options given to a toDot(const DotOptions&).
const DotArcOptions * edge(Size a, Size b) const
the options of the undirected edge between a and b, given for (a, b) or for (b, a),...
const DotNodeOptions * factor(const std::vector< Size > &variables) const
the options of the factor on these variables (in any order), or nullptr if none was given
const DotNodeOptions * node(Size node) const
the options of a node, or nullptr if none was given for it
Writes a graph in the dot language, statement after statement, in the order of the calls.
void edgeDefaults(const DotAttributes &attributes)
edge [attributes];, the default attributes of the edges that follow (none : does nothing).
void edge(std::string_view from, std::string_view to, const DotAttributes &attributes={})
an edge from from to to (-> in a directed graph, -- in an undirected one).
static std::string number(double value)
The shortest text that reads back as value (0.5, 1, 1e-05).
std::string str() const
The graph written so far, closed. It can be called at any moment, and the writer can be used after.
void node(std::string_view id, const DotAttributes &attributes={})
a node, whose identifier is id (quoted).
Typed, documented, sectioned configuration singleton read from an .ini content.
The statements common to the graphs drawn with graphviz : preamble, attributes of nodes and arcs.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
DotAttributes nodeAttributes(const DotStyle &style, const DotNodeOptions *options, std::string_view defaultLabel, std::string_view defaultTooltip)
The attributes of a node : its label and tooltip, and its colors if the options give some.
void writePreamble(DotWriter &writer, const DotStyle &style, const DotOptions &options, std::string_view defaultLabel)
Writes the beginning of a graph, as pyAgrum displays it.
void addDefaultAttribute(DotAttributes &attributes, std::string_view key, std::string_view value)
Adds an attribute at the beginning of the list, unless the list already gives a value for this key : ...
DotAttributes arcAttributes(const DotArcOptions *options)
The attributes of an arc or an edge given by the options : color, penwidth, label,...
gum is the global namespace for all aGrUM entities
Configuration & config()
A short name for Configuration::instance() : gum::config().epsilonStandard(). It is not inline so tha...
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
The look shared by all the graphs: size, direction, layout, colors of the arcs and of the nodes.
static DotStyle read()
the style of the graphs of the section notebook
std::string nodeBgColor
background color of the nodes
static FactorGraphDotStyle read()
Header of the Tensor class.