aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::DefaultEliminationSequenceStrategy Class Reference

An efficient unconstrained elimination sequence algorithm. More...

#include <defaultEliminationSequenceStrategy.h>

Inheritance diagram for gum::DefaultEliminationSequenceStrategy:
Collaboration diagram for gum::DefaultEliminationSequenceStrategy:

Public Member Functions

Constructors / Destructors
 DefaultEliminationSequenceStrategy (double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
 default constructor (uses an empty graph)
 DefaultEliminationSequenceStrategy (UndiGraph *graph, const NodeProperty< Size > *dom_sizes, double ratio=GUM_QUASI_RATIO, double threshold=GUM_WEIGHT_THRESHOLD)
 constructor for a (tensorly) non empty graph
 DefaultEliminationSequenceStrategy (const DefaultEliminationSequenceStrategy &from)
 copy constructor
 DefaultEliminationSequenceStrategy (DefaultEliminationSequenceStrategy &&)
 move constructor
virtual ~DefaultEliminationSequenceStrategy ()
 destructor
virtual DefaultEliminationSequenceStrategynewFactory () const final
 creates a new elimination sequence of the same type as the current object, but this sequence contains only an empty graph
virtual DefaultEliminationSequenceStrategycopyFactory () const final
 virtual copy constructor
Accessors / Modifiers
virtual bool setGraph (UndiGraph *graph, const NodeProperty< Size > *dom_sizes) final
 sets a new graph to be triangulated
virtual void clear () final
 clears the sequence (to prepare, for instance, a new elimination sequence)
virtual NodeId nextNodeToEliminate () final
 returns the new node to be eliminated within the triangulation algorithm
virtual void askFillIns (bool do_it) final
 if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to be activated
virtual bool providesFillIns () const final
 indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the elimination sequence, or need be computed by the triangulation itself.
virtual bool providesGraphUpdate () const final
 indicates whether the elimination sequence updates by itself the graph after a node has been eliminated
virtual void eliminationUpdate (const NodeId node) final
 performs all the graph/fill-ins updates provided (if any)
virtual const EdgeSetfillIns () final
 in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so far
Accessors / Modifiers
UndiGraphgraph () const noexcept
 returns the current graph
const NodeProperty< Size > * domainSizes () const noexcept
 returns the current domain sizes

Protected Attributes

UndiGraphgraph_ {nullptr}
 the graph to be triangulated
const NodeProperty< Size > * domain_sizes_ {nullptr}
 the domain sizes of the variables/nodes
NodeProperty< doublelog_domain_sizes_
 the log of the domain sizes of the variables/nodes

Private Member Functions

void _createSimplicialSet_ ()
 create a new simplicial set suited for the current graph

Static Private Member Functions

static const EdgeSet_empty_fill_ins_ ()
 an empty fill-ins set used by default

Private Attributes

NodeProperty< double_log_weights_
 for each node, the weight of the clique created by the node's elimination
SimplicialSet_simplicial_set_ {nullptr}
 the simplicial set used for determining the best nodes to eliminate
double _simplicial_ratio_
 the ratio used by simplicial_set for its quasi-simplicial nodes
double _simplicial_threshold_
 the threshold used by simplicial_set to determine small cliques
bool _provide_fill_ins_ {false}
 indicates whether we compute new fill-ins

Detailed Description

An efficient unconstrained elimination sequence algorithm.

Class DefaultEliminationSequenceStrategy implements an unconstrained elimination sequence algorithm (that is, there is no external constraint on the possible elimination ordering). The ordering is determined as follows:

the nodes that are simplicial (i.e., those that already form a clique

with their neighbors) are eliminated first

then the nodes that are almost simplicial (i.e., if we remove one of

their neighbors, they become simplicial) and that create small cliques,

are eliminated

the quasi simplicial nodes (i.e., the nodes that do not require many

fill-ins to create cliques) that would create small cliques, are eliminated

finally, the heuristic proposed by Kjaerulff(90) is used to compute the

last nodes to be eliminated.

Definition at line 94 of file defaultEliminationSequenceStrategy.h.

Constructor & Destructor Documentation

◆ DefaultEliminationSequenceStrategy() [1/4]

gum::DefaultEliminationSequenceStrategy::DefaultEliminationSequenceStrategy ( double theRatio = GUM_QUASI_RATIO,
double theThreshold = GUM_WEIGHT_THRESHOLD )

default constructor (uses an empty graph)

Parameters
theRatiothe ratio used by the SimplicialSet included in the DefaultEliminationSequenceStrategy
theThresholdthe weight threshhold of the SimplicialSet included in the DefaultEliminationSequenceStrategy

Definition at line 57 of file defaultEliminationSequenceStrategy.cpp.

58 :
59 _simplicial_ratio_(theRatio), _simplicial_threshold_(theThreshold) {
61 }
double _simplicial_threshold_
the threshold used by simplicial_set to determine small cliques
double _simplicial_ratio_
the ratio used by simplicial_set for its quasi-simplicial nodes
DefaultEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)

References DefaultEliminationSequenceStrategy(), _simplicial_ratio_, and _simplicial_threshold_.

Referenced by DefaultEliminationSequenceStrategy(), DefaultEliminationSequenceStrategy(), DefaultEliminationSequenceStrategy(), DefaultEliminationSequenceStrategy(), ~DefaultEliminationSequenceStrategy(), copyFactory(), and newFactory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DefaultEliminationSequenceStrategy() [2/4]

gum::DefaultEliminationSequenceStrategy::DefaultEliminationSequenceStrategy ( UndiGraph * graph,
const NodeProperty< Size > * dom_sizes,
double ratio = GUM_QUASI_RATIO,
double threshold = GUM_WEIGHT_THRESHOLD )

constructor for a (tensorly) non empty graph

Parameters
graphthe graph to be triangulated, i.e., the nodes of which will be eliminated
dom_sizesthe domain sizes of the nodes to be eliminated
ratiothe ratio used by the SimplicialSet included in the DefaultEliminationSequenceStrategy
thresholdthe weight threshhold of the SimplicialSet included in the DefaultEliminationSequenceStrategy
Warning
Note that we allow dom_sizes to be defined over nodes/variables that do not belong to graph. These sizes will simply be ignored. However, it is compulsory that all the nodes of graph belong to dom_sizes
the graph is altered during the triangulation.
note that, by aGrUM's rule, the graph and the domain sizes are not copied but only referenced by the elimination sequence algorithm.

Definition at line 64 of file defaultEliminationSequenceStrategy.cpp.

68 : _simplicial_ratio_(ratio), _simplicial_threshold_(threshold) {
69 setGraph(graph, domain_sizes);
70
72 }
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes) final
sets a new graph to be triangulated
UndiGraph * graph() const noexcept
returns the current graph

References DefaultEliminationSequenceStrategy(), _simplicial_ratio_, _simplicial_threshold_, gum::EliminationSequenceStrategy::graph(), and setGraph().

Here is the call graph for this function:

◆ DefaultEliminationSequenceStrategy() [3/4]

gum::DefaultEliminationSequenceStrategy::DefaultEliminationSequenceStrategy ( const DefaultEliminationSequenceStrategy & from)

copy constructor

Warning
The newly created elimination sequence strategy points toward the same undirected graph as the one contained in from but each strategy possesses its own simplicial set. As a result, if both elimination strategies are used at the same time, they will probably result in a mess because their simplicial sets won't be synchronized correctly with the changing undirected graph. So, whenever using this copy constructor, be sure that either from or the newly created strategy is used for a triangulation but not both. This will necessarily be OK in DefaultTriangulations.

Definition at line 75 of file defaultEliminationSequenceStrategy.cpp.

76 :
78 // no need to set _log_weights_ because the copy of the simplicial set
79 // will set it properly
80 _simplicial_set_(new SimplicialSet(*from._simplicial_set_,
81 graph_,
84 false)),
85 _simplicial_ratio_(from._simplicial_ratio_),
86 _simplicial_threshold_(from._simplicial_threshold_),
87 _provide_fill_ins_(from._provide_fill_ins_) {
89 }
NodeProperty< double > _log_weights_
for each node, the weight of the clique created by the node's elimination
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
bool _provide_fill_ins_
indicates whether we compute new fill-ins
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
UndiGraph * graph_
the graph to be triangulated

References DefaultEliminationSequenceStrategy(), gum::UnconstrainedEliminationSequenceStrategy::UnconstrainedEliminationSequenceStrategy(), _log_weights_, _provide_fill_ins_, _simplicial_ratio_, _simplicial_set_, _simplicial_threshold_, gum::EliminationSequenceStrategy::graph_, and gum::EliminationSequenceStrategy::log_domain_sizes_.

Here is the call graph for this function:

◆ DefaultEliminationSequenceStrategy() [4/4]

gum::DefaultEliminationSequenceStrategy::DefaultEliminationSequenceStrategy ( DefaultEliminationSequenceStrategy && from)

move constructor

Definition at line 92 of file defaultEliminationSequenceStrategy.cpp.

93 :
95 _log_weights_(std::move(from._log_weights_)), _simplicial_set_(from._simplicial_set_),
96 _simplicial_ratio_(from._simplicial_ratio_),
97 _simplicial_threshold_(from._simplicial_threshold_),
98 _provide_fill_ins_(from._provide_fill_ins_) {
99 _simplicial_set_->replaceLogWeights(&from._log_weights_, &_log_weights_);
100 from._simplicial_set_ = nullptr;
101
103 }

References DefaultEliminationSequenceStrategy(), gum::UnconstrainedEliminationSequenceStrategy::UnconstrainedEliminationSequenceStrategy(), _log_weights_, _provide_fill_ins_, _simplicial_ratio_, _simplicial_set_, and _simplicial_threshold_.

Here is the call graph for this function:

◆ ~DefaultEliminationSequenceStrategy()

gum::DefaultEliminationSequenceStrategy::~DefaultEliminationSequenceStrategy ( )
virtual

destructor

Definition at line 106 of file defaultEliminationSequenceStrategy.cpp.

106 {
108
109 if (_simplicial_set_ != nullptr) delete _simplicial_set_;
110 }

References DefaultEliminationSequenceStrategy(), and _simplicial_set_.

Here is the call graph for this function:

Member Function Documentation

◆ _createSimplicialSet_()

void gum::DefaultEliminationSequenceStrategy::_createSimplicialSet_ ( )
private

create a new simplicial set suited for the current graph

Definition at line 124 of file defaultEliminationSequenceStrategy.cpp.

124 {
125 // remove the old simplicial set, if any
126 if (_simplicial_set_ != nullptr) {
127 delete _simplicial_set_;
128 _simplicial_set_ = nullptr;
129 }
130
131 if (graph_ != nullptr) {
132 // create a simplicial set suited for the graph
133 _simplicial_set_ = new SimplicialSet(graph_,
138
140 }
141 }

References _log_weights_, _provide_fill_ins_, _simplicial_ratio_, _simplicial_set_, _simplicial_threshold_, gum::EliminationSequenceStrategy::graph_, and gum::EliminationSequenceStrategy::log_domain_sizes_.

Referenced by setGraph().

Here is the caller graph for this function:

◆ _empty_fill_ins_()

const EdgeSet & gum::EliminationSequenceStrategy::_empty_fill_ins_ ( )
staticprivateinherited

an empty fill-ins set used by default

Definition at line 60 of file eliminationSequenceStrategy.cpp.

60 {
61#ifdef GUM_DEBUG_MODE
62 static bool first_use = true;
63 if (first_use) {
64 first_use = false;
65 __debug__::_dec_creation_("Set", " __empty_edge_set", 0, "static variable correction", 0);
66 __debug__::_dec_creation_("HashTable",
67 " __empty_edge_set",
68 0,
69 "static variable correction",
70 0);
71 }
72#endif
73 static EdgeSet empty_fill_ins;
74 return empty_fill_ins;
75 }
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...

Referenced by fillIns().

Here is the caller graph for this function:

◆ askFillIns()

void gum::DefaultEliminationSequenceStrategy::askFillIns ( bool do_it)
finalvirtual

if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to be activated

Parameters
do_itwhen true and the elimination sequence has the ability to compute fill-ins, the elimination sequence will actually compute them (for the triangulation to use them), else they will not be available.

Implements gum::EliminationSequenceStrategy.

Definition at line 201 of file defaultEliminationSequenceStrategy.cpp.

201 {
202 _provide_fill_ins_ = do_it;
203
204 if (_simplicial_set_ != nullptr) _simplicial_set_->setFillIns(_provide_fill_ins_);
205 }

References _provide_fill_ins_, and _simplicial_set_.

◆ clear()

void gum::DefaultEliminationSequenceStrategy::clear ( )
finalvirtual

clears the sequence (to prepare, for instance, a new elimination sequence)

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 155 of file defaultEliminationSequenceStrategy.cpp.

155 {
157
158 _log_weights_.clear();
159 if (_simplicial_set_ != nullptr) {
160 delete _simplicial_set_;
161 _simplicial_set_ = nullptr;
162 }
163 }
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)

References _log_weights_, _simplicial_set_, and gum::EliminationSequenceStrategy::clear().

Here is the call graph for this function:

◆ copyFactory()

DefaultEliminationSequenceStrategy * gum::DefaultEliminationSequenceStrategy::copyFactory ( ) const
finalvirtual

virtual copy constructor

Warning
The newly created elimination sequence strategy points toward the same undirected graph as the one contained in the current strategy but each strategy possesses its own simplicial set. As a result, if both elimination strategies are used at the same time, they will probably result in a mess because their simplicial sets won't be synchronized correctly with the changing undirected graph. So, whenever using this virtual copy constructor, be sure that either the current or the newly created strategy is used for a triangulation but not both. This will necessarily be OK in DefaultTriangulations.

Implements gum::UnconstrainedEliminationSequenceStrategy.

Definition at line 119 of file defaultEliminationSequenceStrategy.cpp.

119 {
120 return new DefaultEliminationSequenceStrategy(*this);
121 }

References DefaultEliminationSequenceStrategy().

Here is the call graph for this function:

◆ domainSizes()

INLINE const NodeProperty< Size > * gum::EliminationSequenceStrategy::domainSizes ( ) const
noexceptinherited

returns the current domain sizes

Definition at line 59 of file eliminationSequenceStrategy_inl.h.

59 {
60 return domain_sizes_;
61 }
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes

References domain_sizes_.

Referenced by providesGraphUpdate().

Here is the caller graph for this function:

◆ eliminationUpdate()

void gum::DefaultEliminationSequenceStrategy::eliminationUpdate ( const NodeId node)
finalvirtual

performs all the graph/fill-ins updates provided (if any)

performs all the graph/fill-ins updates provided

Parameters
nodethe node the elimination of which requires the graph update

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 217 of file defaultEliminationSequenceStrategy.cpp.

217 {
218 if (_simplicial_set_ != nullptr) {
219 _simplicial_set_->makeClique(id);
220 _simplicial_set_->eraseClique(id);
221 }
222 }

References _simplicial_set_.

◆ fillIns()

const EdgeSet & gum::DefaultEliminationSequenceStrategy::fillIns ( )
finalvirtual

in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so far

in case fill-ins are provided, this function returns the fill-ins generated after the last node elimination

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 226 of file defaultEliminationSequenceStrategy.cpp.

226 {
227 if (!_provide_fill_ins_ || (_simplicial_set_ == nullptr))
229 else return _simplicial_set_->fillIns();
230 }
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...

References _provide_fill_ins_, _simplicial_set_, and gum::EliminationSequenceStrategy::fillIns().

Here is the call graph for this function:

◆ graph()

◆ newFactory()

DefaultEliminationSequenceStrategy * gum::DefaultEliminationSequenceStrategy::newFactory ( ) const
finalvirtual

creates a new elimination sequence of the same type as the current object, but this sequence contains only an empty graph

Warning
you must deallocate by yourself the object returned
Returns
an empty clone of the current object with the same type

Implements gum::UnconstrainedEliminationSequenceStrategy.

Definition at line 114 of file defaultEliminationSequenceStrategy.cpp.

References DefaultEliminationSequenceStrategy(), _simplicial_ratio_, and _simplicial_threshold_.

Here is the call graph for this function:

◆ nextNodeToEliminate()

NodeId gum::DefaultEliminationSequenceStrategy::nextNodeToEliminate ( )
finalvirtual

returns the new node to be eliminated within the triangulation algorithm

Exceptions
NotFoundexception is thrown if there is no more node to eliminate in the graph

Implements gum::EliminationSequenceStrategy.

Definition at line 166 of file defaultEliminationSequenceStrategy.cpp.

166 {
167 // if there is no simplicial set, send an exception
168 if (graph_ == nullptr) { GUM_ERROR(NotFound, "the graph is empty") }
169
170 // select a node to be eliminated: try simplicial nodes, then almost
171 // simplicial nodes, then quasi-simplicial nodes
172 // note that if _graph_ != 0, _simplicial_set_ has been allocated
173 if (_simplicial_set_->hasSimplicialNode()) return _simplicial_set_->bestSimplicialNode();
174 else if (_simplicial_set_->hasAlmostSimplicialNode())
175 return _simplicial_set_->bestAlmostSimplicialNode();
176 else if (_simplicial_set_->hasQuasiSimplicialNode())
177 return _simplicial_set_->bestQuasiSimplicialNode();
178 else {
179 // here: select the node through Kjaerulff's heuristic
180 auto iter_heuristic = _log_weights_.cbegin();
181
182 if (iter_heuristic == _log_weights_.cend())
183 GUM_ERROR(NotFound, "there exists no more node to eliminate")
184
185 double min_weight = iter_heuristic.val();
186 NodeId removable_node = iter_heuristic.key();
187 for (++iter_heuristic; iter_heuristic != _log_weights_.cend(); ++iter_heuristic) {
188 if (iter_heuristic.val() < min_weight) {
189 removable_node = iter_heuristic.key();
190 min_weight = iter_heuristic.val();
191 }
192 }
193
194 return removable_node;
195 }
196 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
Size NodeId
Type for node ids.

References _log_weights_, _simplicial_set_, gum::EliminationSequenceStrategy::graph_, and GUM_ERROR.

◆ providesFillIns()

bool gum::DefaultEliminationSequenceStrategy::providesFillIns ( ) const
finalvirtual

indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the elimination sequence, or need be computed by the triangulation itself.

indicates whether the new fill-ins generated by a new eliminated node, if needed, will be computed by the elimination sequence, or need be computed by the triangulation itself.

An elimination sequence provides fill-ins to its triangulation if and only if it has the ability to compute them and it has been asked to do so (by method askFillIns)

Implements gum::EliminationSequenceStrategy.

Definition at line 210 of file defaultEliminationSequenceStrategy.cpp.

210{ return _provide_fill_ins_; }

References _provide_fill_ins_.

◆ providesGraphUpdate()

bool gum::DefaultEliminationSequenceStrategy::providesGraphUpdate ( ) const
finalvirtual

indicates whether the elimination sequence updates by itself the graph after a node has been eliminated

Some algorithms have more informations than the triangulation algorithm to update the graph after a node has been eliminated. They can thus exploit these informations to update the graph faster than the triangulation. Hence the latter should delegate this operation to the elimination sequence. This is the case, for instance, for the defaultEliminationSequence, which uses a SimplicialSet that knows that some eliminated nodes do not require any fill-in.

Implements gum::EliminationSequenceStrategy.

Definition at line 214 of file defaultEliminationSequenceStrategy.cpp.

214{ return true; }

◆ setGraph()

bool gum::DefaultEliminationSequenceStrategy::setGraph ( UndiGraph * graph,
const NodeProperty< Size > * dom_sizes )
finalvirtual

sets a new graph to be triangulated

The elimination sequence algorithm reinitializes its data to start a new triangulation with Graph "graph"

Parameters
graphthe new graph to be triangulated
dom_sizesthe domain sizes of the variables/nodes
Returns
true if the data structures were modified (if the graph or the
Warning
Note that we allow dom_sizes to be defined over nodes/variables that do not belong to graph. These sizes will simply be ignored. However, it is compulsory that all the nodes of graph belong to dom_sizes
the graph is altered during the triangulation.
note that, by aGrUM's rule, the graph and the domain sizes are not copied but only referenced by the elimination sequence algorithm.

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 144 of file defaultEliminationSequenceStrategy.cpp.

145 {
148 return true;
149 }
150
151 return false;
152 }
void _createSimplicialSet_()
create a new simplicial set suited for the current graph
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated

References _createSimplicialSet_(), gum::EliminationSequenceStrategy::graph(), and gum::EliminationSequenceStrategy::setGraph().

Referenced by DefaultEliminationSequenceStrategy().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _log_weights_

NodeProperty< double > gum::DefaultEliminationSequenceStrategy::_log_weights_
private

for each node, the weight of the clique created by the node's elimination

Definition at line 238 of file defaultEliminationSequenceStrategy.h.

Referenced by DefaultEliminationSequenceStrategy(), DefaultEliminationSequenceStrategy(), _createSimplicialSet_(), clear(), and nextNodeToEliminate().

◆ _provide_fill_ins_

bool gum::DefaultEliminationSequenceStrategy::_provide_fill_ins_ {false}
private

indicates whether we compute new fill-ins

Definition at line 250 of file defaultEliminationSequenceStrategy.h.

250{false};

Referenced by DefaultEliminationSequenceStrategy(), DefaultEliminationSequenceStrategy(), _createSimplicialSet_(), askFillIns(), fillIns(), and providesFillIns().

◆ _simplicial_ratio_

double gum::DefaultEliminationSequenceStrategy::_simplicial_ratio_
private

◆ _simplicial_set_

SimplicialSet* gum::DefaultEliminationSequenceStrategy::_simplicial_set_ {nullptr}
private

◆ _simplicial_threshold_

double gum::DefaultEliminationSequenceStrategy::_simplicial_threshold_
private

◆ domain_sizes_

const NodeProperty< Size >* gum::EliminationSequenceStrategy::domain_sizes_ {nullptr}
protectedinherited

the domain sizes of the variables/nodes

Definition at line 177 of file eliminationSequenceStrategy.h.

177{nullptr};

Referenced by EliminationSequenceStrategy(), EliminationSequenceStrategy(), clear(), domainSizes(), and setGraph().

◆ graph_

◆ log_domain_sizes_


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