![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
Class enabling fast retrieval of simplicial, quasi and almost simplicial nodes. More...
#include <simplicialSet.h>
Public Member Functions | |
Constructors / Destructors | |
SimplicialSet (UndiGraph *graph, const NodeProperty< double > *log_domain_sizes, NodeProperty< double > *log_weights, double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD) | |
constructor. initializes the simplicial set w.r.t. a given graph More... | |
SimplicialSet (const SimplicialSet &simplicial_from, UndiGraph *graph, const NodeProperty< double > *log_domain_sizes, NodeProperty< double > *log_weights, bool avoid_check=false) | |
copy constructor More... | |
SimplicialSet (SimplicialSet &&from) | |
move constructor More... | |
~SimplicialSet () | |
destructor More... | |
Accessors / Modifiers | |
void | makeClique (const NodeId id) |
adds the necessary edges so that node 'id' and its neighbors form a clique More... | |
void | eraseClique (const NodeId id) |
removes a node and its adjacent edges from the underlying graph More... | |
void | eraseNode (const NodeId id) |
removes a node and its adjacent edges from the underlying graph More... | |
void | eraseEdge (const Edge &edge) |
removes an edge from the graph and recomputes the simplicial set More... | |
void | addEdge (NodeId first, NodeId second) |
adds a new edge to the graph and recomputes the simplicial set More... | |
bool | isSimplicial (const NodeId id) |
indicates whether a given node is a simplicial node More... | |
bool | hasSimplicialNode () |
indicates whether there exists a simplicial node More... | |
bool | hasAlmostSimplicialNode () |
indicates whether there exists an almost simplicial node More... | |
bool | hasQuasiSimplicialNode () |
indicates whether there exists a quasi simplicial node More... | |
NodeId | bestSimplicialNode () |
returns the simplicial node with the lowest clique weight More... | |
const PriorityQueue< NodeId, double > & | allSimplicialNodes () |
returns all the simplicial nodes More... | |
NodeId | bestAlmostSimplicialNode () |
gets the almost simplicial node with the lowest clique weight More... | |
const PriorityQueue< NodeId, double > & | allAlmostSimplicialNodes () |
returns all the almost simplicial nodes More... | |
NodeId | bestQuasiSimplicialNode () |
gets a quasi simplicial node with the lowest clique weight More... | |
const PriorityQueue< NodeId, double > & | allQuasiSimplicialNodes () |
returns all the quasi simplicial nodes More... | |
void | setFillIns (bool on_off) |
sets/unset the fill-ins storage in the standard triangulation procedure More... | |
const EdgeSet & | fillIns () const |
returns the set of all the fill-ins added to the graph so far More... | |
void | setGraph (UndiGraph *graph, const NodeProperty< double > *log_domain_sizes, NodeProperty< double > *log_weights, double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD) |
initialize the simplicial set w.r.t. a new graph More... | |
void | replaceLogWeights (NodeProperty< double > *old_weigths, NodeProperty< double > *new_weights) |
reassigns a new set of cliques' log weights (with the same content) More... | |
Class enabling fast retrieval of simplicial, quasi and almost simplicial nodes.
Definition at line 59 of file simplicialSet.h.
|
strongprivate |
indicates for each node to which list (simplicial, almost simplicial, quasi simplicial) it belongs
Enumerator | |
---|---|
SIMPLICIAL | |
ALMOST_SIMPLICIAL | |
QUASI_SIMPLICIAL | |
NO_LIST |
Definition at line 320 of file simplicialSet.h.
|
explicit |
constructor. initializes the simplicial set w.r.t. a given graph
creates a class for managing the simplicial sets of a given undirected graph. When we add or remove nodes or edges within this undirected graph, the simplicial set updates its list of simplicial, almost simplicial and quasi simplicial sets. Recall that a node is simplicial if, along with its neighbors, it forms a clique. A node X is almost simplicial if it has a neighbor, say Y, such that, after removing Y, X and its neighbors form a clique.
graph | The undirected graph the simplicial sets of which we are interested in. |
log_domain_sizes | The logarithm of the domain sizes of the nodes/variables. This is used for two different reasons: i) it enables to retrieve the simplicial nodes that have the smallest domain size (useful for triangulations); and ii) it enables to compute and update the log-weight of the cliques containing the nodes (the log-weight of a clique is the sum of the log_domain_sizes of its nodes). |
log_weights | The logarithm of the weights of cliques. |
theRatio | Let L be the number of edges between neighbors of a given node and let L' be the number of all the possible edges between these neighbors (n * (n+1) / 2). If L/L' >= theRatio, then we consider that the node and its neighbors quasi form a clique and, hence is a quasi-simplicial node. |
theThreshold | for a safe triangulation (see Bodlaender), almost and quasi-simplicial nodes should not be eliminated, unless their weight is lower than the highest weight of the cliques created so far. Here, we consider it safe if the weight of a new clique is lower than (1+theThreshold) * this highest weight. This enables flexibility. |
OperationNotAllowed | exception is thrown if the graph, the log_modalities or the log_weights are null pointers. |
gum::SimplicialSet::SimplicialSet | ( | const SimplicialSet & | simplicial_from, |
UndiGraph * | graph, | ||
const NodeProperty< double > * | log_domain_sizes, | ||
NodeProperty< double > * | log_weights, | ||
bool | avoid_check = false |
||
) |
copy constructor
The constructor tries to make a copy of simplicial_from. In addition, it requires a graph that is a perfect copy of that of simplicial_from, as well as perfect copies of the log domain sizes and weights of simplicial_from. This requirement is necessary to avoid a mess: as the graph, the log domain sizes and the log weights are the only data that are not copied into the SimplicialSet, creating a copy of simplicial_from without using, say, a new graph would result in the new SimplicialSet asserting that some nodes are simplicial while they are not because the graph has been changed by simplicial_from. With these new copies, this kind of case cannot occur.
simplicial_from | the simplicial set we wish to copy |
graph | The undirected graph the simplicial sets of which we are interested in. It should be identical to that used by simplicial_from. |
log_domain_sizes | The logarithm of the domain sizes of the nodes/variabless. This is used for two different reasons: i) it enables to retrieve the simplicial nodes that have the smallest domain sizes (useful for triangulations); and ii) it enables to compute and update the log-weight of the cliques containing the nodes (the log-weight of a clique is the sum of the log_domain_sizes of its nodes). log_domain_sizes should be identical to that used by simplicial_from. |
log_weights | The logarithm of the weights of the cliques. |
avoid_check | if this Boolean is set to true, the SimplicialSet will not check whether the graph, the log_domain_sizes and the log_weights are OK. It will simply assume that everything is OK. Never use this unless you know what you do: setting avoid_check to true results in a faster constructor but can also lead to a mess that is quite complicated to fix. |
OperationNotAllowed | exception is thrown if the graph, the log_domain_sizes or the log_weights are null pointers, or if these data are different from those stored into simplicial_from |
gum::SimplicialSet::SimplicialSet | ( | SimplicialSet && | from | ) |
move constructor
gum::SimplicialSet::~SimplicialSet | ( | ) |
destructor
|
private |
prevent the default copy constructor
If we did not prevent this operator to be used, we would be in a mess since the graph, the domain sizes and the weights would be shared and updated by several Simplicial sets whereas the number of triangles and the number of joined neighbors would not be shared.
|
private |
initialize: compute nb_triangles, nb_adjacent_neighbors, etc when a new graph is set
This method initializes the log_weights, the number of triangles and the number of adjacent neighbors given the current graph. This is to be used in constructors and method setGraph
|
private |
put all the nodes in their appropriate list
|
private |
put node id in the correct simplicial/almost simplicial/quasi simplicial list
adds a new edge to the graph and recomputes the simplicial set
first | the id of one extremal node of the new inserted edge |
second | the id of the other extremal node of the new inserted edge |
InvalidNode | if first and/or second do not belong to the graph nodes |
const PriorityQueue< NodeId, double >& gum::SimplicialSet::allAlmostSimplicialNodes | ( | ) |
returns all the almost simplicial nodes
In the priority queue returned, the doubles correspond to the log-weight of the cliques formed by the nodes and their neighbors.
const PriorityQueue< NodeId, double >& gum::SimplicialSet::allQuasiSimplicialNodes | ( | ) |
returns all the quasi simplicial nodes
In the priority queue returned, the doubles correspond to the weight of cliques formed by the nodes and their neighbors.
const PriorityQueue< NodeId, double >& gum::SimplicialSet::allSimplicialNodes | ( | ) |
returns all the simplicial nodes
In the priority queue returned, the doubles correspond to the log-weight of the cliques the nodes belong to.
NodeId gum::SimplicialSet::bestAlmostSimplicialNode | ( | ) |
gets the almost simplicial node with the lowest clique weight
NodeId gum::SimplicialSet::bestQuasiSimplicialNode | ( | ) |
gets a quasi simplicial node with the lowest clique weight
NodeId gum::SimplicialSet::bestSimplicialNode | ( | ) |
returns the simplicial node with the lowest clique weight
A simplicial node is a node such that the latter and its neighbors form a clique.
void gum::SimplicialSet::eraseClique | ( | const NodeId | id | ) |
removes a node and its adjacent edges from the underlying graph
The node should form a clique with its neighbors.
id | the id of the node which, along with its neighbors, forms the clique that will be removed |
NotFound | exception is thrown if the node cannot be found in the graph or if it is not a clique. |
void gum::SimplicialSet::eraseEdge | ( | const Edge & | edge | ) |
removes an edge from the graph and recomputes the simplicial set
edge | the edge to be removed |
void gum::SimplicialSet::eraseNode | ( | const NodeId | id | ) |
removes a node and its adjacent edges from the underlying graph
id | the id of the node which, along with its adjacent edges, will be removed |
NotFound | exception is thrown if the node cannot be found in the graph. |
const EdgeSet& gum::SimplicialSet::fillIns | ( | ) | const |
returns the set of all the fill-ins added to the graph so far
bool gum::SimplicialSet::hasAlmostSimplicialNode | ( | ) |
indicates whether there exists an almost simplicial node
bool gum::SimplicialSet::hasQuasiSimplicialNode | ( | ) |
indicates whether there exists a quasi simplicial node
bool gum::SimplicialSet::hasSimplicialNode | ( | ) |
indicates whether there exists a simplicial node
A simplicial node is a node such that the latter and its neighbors form a clique.
indicates whether a given node is a simplicial node
A simplicial node is a node such that the latter and its neighbors form a clique.
id | the ID of the node the simpliciality of which we test |
void gum::SimplicialSet::makeClique | ( | const NodeId | id | ) |
adds the necessary edges so that node 'id' and its neighbors form a clique
id | the node which will form, with its neighbors, a clique |
|
private |
prevent a copy operator to be used
If we did not prevent this operator to be used, we would be in a mess since the graph, the modalities and the weights would be shared and updated by several Simplicial sets whereas the number of triangles and the number of joined neighbors would not be shared.
void gum::SimplicialSet::replaceLogWeights | ( | NodeProperty< double > * | old_weigths, |
NodeProperty< double > * | new_weights | ||
) |
reassigns a new set of cliques' log weights (with the same content)
This method is useful for move constructors in elimination sequences.
InvalidArgument | is raised if the old_weights argument is different from the current log_weights pointer. |
void gum::SimplicialSet::setFillIns | ( | bool | on_off | ) |
sets/unset the fill-ins storage in the standard triangulation procedure
on_off | when true means that the SimplicialSet will compute the fill-ins added to the graph. When on_off is false, the fill-ins are not computed. Note that, to produce a correct result, you should call setFillIns before any modification to the graph. |
void gum::SimplicialSet::setGraph | ( | UndiGraph * | graph, |
const NodeProperty< double > * | log_domain_sizes, | ||
NodeProperty< double > * | log_weights, | ||
double | theRatio = GUM_QUASI_RATIO , |
||
double | theThreshold = GUM_WEIGHT_THRESHOLD |
||
) |
initialize the simplicial set w.r.t. a new graph
graph | The undirected graph the simplicial sets of which we are interested in. |
log_domain_sizes | The logarithm of the domain sizes of the nodes/variables. This is used for two different reasons: i) it enables to retrieve the simplicial nodes that have the smallest domain sizes (useful for triangulations); and ii) it enables to compute and update the log-weight of the cliques containing the nodes (the log-weight of a clique is the sum of the log_domain_sizes of its nodes). |
log_weights | The logarithm of the weights of the cliques. |
theRatio | Let L be the number of edges between neighbors of a given node and let L' be the number of all the possible edges between these neighbors (n * (n+1) / 2). If L/L' >= theRatio, then we consider that the node and its neighbors quasi form a clique and, hence is a quasi-simplicial node. |
theThreshold | for a safe triangulation (see Bodlaender), almost and quasi-simplicial nodes should not be eliminated, unless their weight is lower than the highest weight of the cliques created so far. Here, we consider it safe if the weight of a new clique is lower than (1+theThreshold) * this highest weight. This enables flexibility. |
|
private |
a queue of the almost simplicial nodes ordered by increasing node weight
Definition at line 313 of file simplicialSet.h.
|
private |
the set of nodes that have potentially changed of status
Definition at line 356 of file simplicialSet.h.
|
private |
Definition at line 327 of file simplicialSet.h.
|
private |
fill-ins list
Definition at line 363 of file simplicialSet.h.
|
private |
the graph on which we perform the simplicial computations
Definition at line 301 of file simplicialSet.h.
|
private |
the log of the modalities of the nodes
Definition at line 307 of file simplicialSet.h.
|
private |
quasi and almost simplicial nodes may not be eliminated unless their weight is lower than (1 + threshold) * tree_width
Definition at line 353 of file simplicialSet.h.
|
private |
the current (induced) tree width
Definition at line 344 of file simplicialSet.h.
|
private |
the weights of the nodes (i.e., weight of their clique)
Definition at line 304 of file simplicialSet.h.
|
private |
for each node, the number of pairs of adjacent neighbours
Definition at line 334 of file simplicialSet.h.
|
private |
for each edge, keep track of the number of triangles passing through this egde
Definition at line 331 of file simplicialSet.h.
|
private |
for a given node, if the number of pairs of neighbors that are adjacent / the number of adjacent neighbors in a clique is greater than the quasi ratio, then the node should belong the quasi simplicial list
Definition at line 349 of file simplicialSet.h.
|
private |
a queue of the quasi simplicial nodes ordered by increasing node weight
Definition at line 316 of file simplicialSet.h.
|
private |
a queue of the simplicial nodes ordered by increasing node weight
Definition at line 310 of file simplicialSet.h.
|
private |
a boolean indicating if we want fill-ins list with the standard triangulation method
Definition at line 360 of file simplicialSet.h.