aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::learning::StructuralConstraintIndegree Class Reference

the class for structural constraints limiting the number of parents of nodes in a directed graph More...

#include <structuralConstraintIndegree.h>

Inheritance diagram for gum::learning::StructuralConstraintIndegree:
Collaboration diagram for gum::learning::StructuralConstraintIndegree:

Public Member Functions

Constructors / Destructors
 StructuralConstraintIndegree ()
 default constructor
 StructuralConstraintIndegree (Size nb_nodes, Size max_indegree)
 constructor starting with an empty graph with a given number of nodes
 StructuralConstraintIndegree (const DiGraph &graph, Size max_indegree)
 constructor starting with a given graph
 StructuralConstraintIndegree (const StructuralConstraintIndegree &from)
 copy constructor
 StructuralConstraintIndegree (StructuralConstraintIndegree &&from)
 move constructor
 ~StructuralConstraintIndegree () override
 destructor
Operators
StructuralConstraintIndegreeoperator= (const StructuralConstraintIndegree &from)
 copy operator
StructuralConstraintIndegreeoperator= (StructuralConstraintIndegree &&from)
 move operator
Specific Accessors / Modifiers
void setIndegree (const NodeProperty< Size > &max_indegree)
 sets the default max indegree for all the nodes in the property
void setMaxIndegree (Size max_indegree, bool update_all_node=false)
 resets the default max indegree and possibly updates the indegree of all nodes
void setGraphAlone (const DiGraph &graph)
 sets a new graph from which we will perform checkings
void modifyGraphAlone (const ArcAddition &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const ArcDeletion &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const ArcReversal &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const ArcTriangleDeletion1 &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const ArcTriangleDeletion2 &change)
 notify the constraint of a modification of the graph
void modifyGraphAlone (const GraphChange &change)
 notify the constraint of a modification of the graph
bool isAlwaysInvalidAlone (const GraphChange &change) const
 indicates whether a change will always violate the constraint
bool checkArcAdditionAlone (NodeId x, NodeId y) const
 checks whether the constraints enable to add arc (x,y)
bool checkArcDeletionAlone (NodeId x, NodeId y) const
 checks whether the constraints enable to remove arc (x,y)
bool checkArcReversalAlone (NodeId x, NodeId y) const
 checks whether the constraints enable to reverse arc (x,y)
bool checkArcTriangleDeletion1Alone (NodeId node1, NodeId node2, NodeId node3) const
 checks whether the constraints enable to apply an ArcTriangleDeletion1
bool checkArcTriangleDeletion2Alone (NodeId node1, NodeId node2, NodeId node3) const
 checks whether the constraints enable to apply an ArcTriangleDeletion2
bool checkModificationAlone (const ArcAddition &change) const
 checks whether the constraints enable to add an arc
bool checkModificationAlone (const ArcDeletion &change) const
 checks whether the constraints enable to remove an arc
bool checkModificationAlone (const ArcReversal &change) const
 checks whether the constraints enable to reverse an arc
bool checkModificationAlone (const ArcTriangleDeletion1 &change) const
 checks whether the constraints enable to apply an ArcTriangleDeletion1
bool checkModificationAlone (const ArcTriangleDeletion2 &change) const
 checks whether the constraints enable to apply an ArcTriangleDeletion2
bool checkModificationAlone (const GraphChange &change) const
 checks whether the constraints enable to perform a graph change
Size maxIndegree () const
 sets the default max indegree for all the nodes in the property

Protected Types

using constraints

Protected Member Functions

Accessors / Modifiers
void setGraph (const DiGraph &graph)
 sets a new graph from which we will perform checkings
void modifyGraph (const ArcAddition &change)
 notify the constraint of a modification of the graph
bool isAlwaysInvalid (const GraphChange &change) const
 indicates whether a change will always violate the constraint
bool checkArcAddition (NodeId x, NodeId y) const
 checks whether the constraints enable to add arc (x,y)
bool checkArcDeletion (NodeId x, NodeId y) const
 checks whether the constraints enable to remove arc (x,y)
bool checkArcReversal (NodeId x, NodeId y) const
 checks whether the constraints enable to reverse arc (x,y)
bool checkArcTriangleDeletion1 (NodeId node1, NodeId node2, NodeId node3) const
 checks whether the constraints enable to apply an ArcTriangleDeletion1
bool checkArcTriangleDeletion2 (NodeId node1, NodeId node2, NodeId node3) const
 checks whether the constraints enable to apply an ArcTriangleDeletion2
bool checkModification (const ArcAddition &change) const
 checks whether the constraints enable to add an arc

Protected Attributes

NodeProperty< Size_Indegree_max_parents_
 the max number of parents per node
Size _Indegree_max_indegree_ {std::numeric_limits< Size >::max()}
 a default max indegree to assign for nodes without specified indegree

Detailed Description

the class for structural constraints limiting the number of parents of nodes in a directed graph

Definition at line 66 of file structuralConstraintIndegree.h.

Member Typedef Documentation

◆ constraints

using gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::constraints
inherited

Definition at line 497 of file structuralConstraintSetStatic.h.

Constructor & Destructor Documentation

◆ StructuralConstraintIndegree() [1/5]

gum::learning::StructuralConstraintIndegree::StructuralConstraintIndegree ( )

default constructor

Definition at line 61 of file structuralConstraintIndegree.cpp.

61 {
62 GUM_CONSTRUCTOR(StructuralConstraintIndegree);
63 }

References StructuralConstraintIndegree().

Referenced by StructuralConstraintIndegree(), StructuralConstraintIndegree(), StructuralConstraintIndegree(), StructuralConstraintIndegree(), StructuralConstraintIndegree(), ~StructuralConstraintIndegree(), operator=(), and operator=().

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

◆ StructuralConstraintIndegree() [2/5]

gum::learning::StructuralConstraintIndegree::StructuralConstraintIndegree ( Size nb_nodes,
Size max_indegree )

constructor starting with an empty graph with a given number of nodes

Definition at line 66 of file structuralConstraintIndegree.cpp.

66 :
67 StructuralConstraintDiGraph(nb_nodes), _Indegree_max_indegree_(max_indegree) {
68 for (NodeId i = 0; i < nb_nodes; ++i) {
69 _Indegree_max_parents_.insert(i, max_indegree);
70 }
71 GUM_CONSTRUCTOR(StructuralConstraintIndegree);
72 }
Size _Indegree_max_indegree_
a default max indegree to assign for nodes without specified indegree
NodeProperty< Size > _Indegree_max_parents_
the max number of parents per node
Size NodeId
Type for node ids.

References StructuralConstraintIndegree(), _Indegree_max_indegree_, and _Indegree_max_parents_.

Here is the call graph for this function:

◆ StructuralConstraintIndegree() [3/5]

gum::learning::StructuralConstraintIndegree::StructuralConstraintIndegree ( const DiGraph & graph,
Size max_indegree )

constructor starting with a given graph

Definition at line 75 of file structuralConstraintIndegree.cpp.

76 :
77 StructuralConstraintDiGraph(graph), _Indegree_max_indegree_(max_indegree) {
78 for (const auto id: graph) {
79 _Indegree_max_parents_.insert(id, max_indegree);
80 }
81 GUM_CONSTRUCTOR(StructuralConstraintIndegree);
82 }

References StructuralConstraintIndegree(), _Indegree_max_indegree_, and _Indegree_max_parents_.

Here is the call graph for this function:

◆ StructuralConstraintIndegree() [4/5]

gum::learning::StructuralConstraintIndegree::StructuralConstraintIndegree ( const StructuralConstraintIndegree & from)

copy constructor

Definition at line 85 of file structuralConstraintIndegree.cpp.

86 :
87 StructuralConstraintDiGraph(from), _Indegree_max_parents_(from._Indegree_max_parents_),
88 _Indegree_max_indegree_(from._Indegree_max_indegree_) {
89 GUM_CONS_CPY(StructuralConstraintIndegree);
90 }

References StructuralConstraintIndegree(), _Indegree_max_indegree_, and _Indegree_max_parents_.

Here is the call graph for this function:

◆ StructuralConstraintIndegree() [5/5]

gum::learning::StructuralConstraintIndegree::StructuralConstraintIndegree ( StructuralConstraintIndegree && from)

move constructor

Definition at line 93 of file structuralConstraintIndegree.cpp.

94 :
95 StructuralConstraintDiGraph(std::move(from)),
96 _Indegree_max_parents_(std::move(from._Indegree_max_parents_)),
97 _Indegree_max_indegree_(std::move(from._Indegree_max_indegree_)) {
98 GUM_CONS_MOV(StructuralConstraintIndegree);
99 }

References StructuralConstraintIndegree(), _Indegree_max_indegree_, and _Indegree_max_parents_.

Here is the call graph for this function:

◆ ~StructuralConstraintIndegree()

gum::learning::StructuralConstraintIndegree::~StructuralConstraintIndegree ( )
override

destructor

Definition at line 102 of file structuralConstraintIndegree.cpp.

102 {
103 GUM_DESTRUCTOR(StructuralConstraintIndegree);
104 }

References StructuralConstraintIndegree().

Here is the call graph for this function:

Member Function Documentation

◆ checkArcAddition()

bool gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::checkArcAddition ( NodeId x,
NodeId y ) const
inherited

checks whether the constraints enable to add arc (x,y)

◆ checkArcAdditionAlone()

bool gum::learning::StructuralConstraintIndegree::checkArcAdditionAlone ( NodeId x,
NodeId y ) const

checks whether the constraints enable to add arc (x,y)

an arc can be added if and only if its extremal nodes belong to the graph and the arc does not already exist and its addition would not violate the indegree constraint of y.

Referenced by checkModificationAlone().

Here is the caller graph for this function:

◆ checkArcDeletion()

bool gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::checkArcDeletion ( NodeId x,
NodeId y ) const
inherited

checks whether the constraints enable to remove arc (x,y)

◆ checkArcDeletionAlone()

bool gum::learning::StructuralConstraintIndegree::checkArcDeletionAlone ( NodeId x,
NodeId y ) const

checks whether the constraints enable to remove arc (x,y)

an arc can be removed if and only if the arc exists.

Referenced by checkModificationAlone().

Here is the caller graph for this function:

◆ checkArcReversal()

bool gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::checkArcReversal ( NodeId x,
NodeId y ) const
inherited

checks whether the constraints enable to reverse arc (x,y)

◆ checkArcReversalAlone()

bool gum::learning::StructuralConstraintIndegree::checkArcReversalAlone ( NodeId x,
NodeId y ) const

checks whether the constraints enable to reverse arc (x,y)

an arc can be reversed if and only if it exists and arc (y,x) does not and its addition would not violate the indegree constraint of x.

Referenced by checkModificationAlone().

Here is the caller graph for this function:

◆ checkArcTriangleDeletion1()

bool gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::checkArcTriangleDeletion1 ( NodeId node1,
NodeId node2,
NodeId node3 ) const
inherited

checks whether the constraints enable to apply an ArcTriangleDeletion1

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node2 -> node1 <- node3

◆ checkArcTriangleDeletion1Alone()

bool gum::learning::StructuralConstraintIndegree::checkArcTriangleDeletion1Alone ( NodeId node1,
NodeId node2,
NodeId node3 ) const

checks whether the constraints enable to apply an ArcTriangleDeletion1

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node2 -> node1 <- node3

Referenced by checkModificationAlone().

Here is the caller graph for this function:

◆ checkArcTriangleDeletion2()

bool gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::checkArcTriangleDeletion2 ( NodeId node1,
NodeId node2,
NodeId node3 ) const
inherited

checks whether the constraints enable to apply an ArcTriangleDeletion2

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node1 -> node2 <- node3

◆ checkArcTriangleDeletion2Alone()

bool gum::learning::StructuralConstraintIndegree::checkArcTriangleDeletion2Alone ( NodeId node1,
NodeId node2,
NodeId node3 ) const

checks whether the constraints enable to apply an ArcTriangleDeletion2

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node1 -> node2 <- node3

Referenced by checkModificationAlone().

Here is the caller graph for this function:

◆ checkModification()

bool gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::checkModification ( const ArcAddition & change) const
inherited

checks whether the constraints enable to add an arc

◆ checkModificationAlone() [1/6]

bool gum::learning::StructuralConstraintIndegree::checkModificationAlone ( const ArcAddition & change) const

checks whether the constraints enable to add an arc

an arc can be added if and only if its extremal nodes belong to the graph and the arc does not already exist and its addition would not violate the indegree constraint of y.

◆ checkModificationAlone() [2/6]

bool gum::learning::StructuralConstraintIndegree::checkModificationAlone ( const ArcDeletion & change) const

checks whether the constraints enable to remove an arc

an arc can be removed if and only if the arc exists.

◆ checkModificationAlone() [3/6]

bool gum::learning::StructuralConstraintIndegree::checkModificationAlone ( const ArcReversal & change) const

checks whether the constraints enable to reverse an arc

an arc can be reversed if and only if it exists and arc (y,x) does not and its addition would not violate the indegree constraint of x.

◆ checkModificationAlone() [4/6]

bool gum::learning::StructuralConstraintIndegree::checkModificationAlone ( const ArcTriangleDeletion1 & change) const

checks whether the constraints enable to apply an ArcTriangleDeletion1

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node2 -> node1 <- node3

◆ checkModificationAlone() [5/6]

bool gum::learning::StructuralConstraintIndegree::checkModificationAlone ( const ArcTriangleDeletion2 & change) const

checks whether the constraints enable to apply an ArcTriangleDeletion2

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node1 -> node2 <- node3

◆ checkModificationAlone() [6/6]

bool gum::learning::StructuralConstraintIndegree::checkModificationAlone ( const GraphChange & change) const

checks whether the constraints enable to perform a graph change

An arc can be added if and only if its extremal nodes belong to the graph and the arc does not already exist and its addition would not violate the indegree constraint of y. An arc can be removed if and only if the arc exists. An arc can be reversed if and only if it exists and arc (y,x) does not and its addition would not violate the indegree constraint of x.

Definition at line 130 of file structuralConstraintIndegree.cpp.

130 {
131 switch (change.type()) {
133 return checkArcAdditionAlone(change.node1(), change.node2());
134
136 return checkArcDeletionAlone(change.node1(), change.node2());
137
139 return checkArcReversalAlone(change.node1(), change.node2());
140
142 return checkArcTriangleDeletion1Alone(change.node1(), change.node2(), change.node3());
143
145 return checkArcTriangleDeletion2Alone(change.node1(), change.node2(), change.node3());
146
147 default :
148 GUM_ERROR(OperationNotAllowed,
149 "Graph change operation "
150 << change.typeAsString()
151 << " is not supported by the Indegree structural constraint");
152 }
153 }
bool checkArcTriangleDeletion1Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion1
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
bool checkArcTriangleDeletion2Alone(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion2
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References gum::learning::ARC_ADDITION, gum::learning::ARC_DELETION, gum::learning::ARC_REVERSAL, gum::learning::ARC_TRIANGLE_DELETION1, gum::learning::ARC_TRIANGLE_DELETION2, checkArcAdditionAlone(), checkArcDeletionAlone(), checkArcReversalAlone(), checkArcTriangleDeletion1Alone(), checkArcTriangleDeletion2Alone(), GUM_ERROR, gum::learning::GraphChange::node1(), gum::learning::GraphChange::node2(), gum::learning::GraphChange::node3(), gum::learning::GraphChange::type(), and gum::learning::GraphChange::typeAsString().

Here is the call graph for this function:

◆ isAlwaysInvalid()

bool gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::isAlwaysInvalid ( const GraphChange & change) const
inherited

indicates whether a change will always violate the constraint

◆ isAlwaysInvalidAlone()

bool gum::learning::StructuralConstraintIndegree::isAlwaysInvalidAlone ( const GraphChange & change) const

indicates whether a change will always violate the constraint

Some learning algorithms need examine several times whether a given graph change can be applied. For instance, the first time arc (X,Y) addition is considered, the learning algorithm may discard this change because it violates the structural constraint (e.g., if the latter enforces a DAG structure, this arc addition might induce a directed cycle), but, later on, other arc removal may induce that the arc addition is now possible. Such change is thus not always invalid. Conversely, there are changes that can be discarded once and for all. For instance, in a 2TBN structure, it is always impossible to add a backward-time arc. Such graph changes are always invalid and are therefore tagged as such by the isAlwaysInvalid method.

◆ maxIndegree()

Size gum::learning::StructuralConstraintIndegree::maxIndegree ( ) const

sets the default max indegree for all the nodes in the property

◆ modifyGraph()

void gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::modifyGraph ( const ArcAddition & change)
inherited

notify the constraint of a modification of the graph

◆ modifyGraphAlone() [1/6]

void gum::learning::StructuralConstraintIndegree::modifyGraphAlone ( const ArcAddition & change)

notify the constraint of a modification of the graph

Warning
If an already existing arc is added, nothing is done. In particular, no exception is raised.
Exceptions
InvalidNodeexception is thrown if an arc (x,y) is added and x or y does not belong to the graph nodes
OutOfBoundsexception is thrown if the indegree constraint is violated by the arc addition.

◆ modifyGraphAlone() [2/6]

void gum::learning::StructuralConstraintIndegree::modifyGraphAlone ( const ArcDeletion & change)

notify the constraint of a modification of the graph

Warning
If a nonexisting arc is removed, nothing is done. In particular, no exception is raised.

◆ modifyGraphAlone() [3/6]

void gum::learning::StructuralConstraintIndegree::modifyGraphAlone ( const ArcReversal & change)

notify the constraint of a modification of the graph

Warning
If an already existing arc is added, or if a nonexisting arc is removed, nothing is done. In particular, no exception is raised.
Exceptions
InvalidNodeexception is thrown if an arc (x,y) is added and x or y does not belong to the graph nodes
OutOfBoundsexception is thrown if the indegree constraint is violated by the arc reversal.

◆ modifyGraphAlone() [4/6]

void gum::learning::StructuralConstraintIndegree::modifyGraphAlone ( const ArcTriangleDeletion1 & change)

notify the constraint of a modification of the graph

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node2 -> node1 <- node3

◆ modifyGraphAlone() [5/6]

void gum::learning::StructuralConstraintIndegree::modifyGraphAlone ( const ArcTriangleDeletion2 & change)

notify the constraint of a modification of the graph

An arc triangle deletion1 substitutes triangle node1 -> node2 -> node3 + node1 -> node3 into v-structure node1 -> node2 <- node3

◆ modifyGraphAlone() [6/6]

void gum::learning::StructuralConstraintIndegree::modifyGraphAlone ( const GraphChange & change)

notify the constraint of a modification of the graph

Warning
If an already existing arc is added, or if a nonexisting arc is removed, nothing is done. In particular, no exception is raised.
Exceptions
InvalidNodeexception is thrown if an arc (x,y) is added and x or y does not belong to the graph nodes
OutOfBoundsexception is thrown if the indegree constraint is violated by an arc addition or reversal.

◆ operator=() [1/2]

StructuralConstraintIndegree & gum::learning::StructuralConstraintIndegree::operator= ( const StructuralConstraintIndegree & from)

copy operator

Definition at line 108 of file structuralConstraintIndegree.cpp.

108 {
109 if (this != &from) {
111 _Indegree_max_parents_ = from._Indegree_max_parents_;
112 _Indegree_max_indegree_ = from._Indegree_max_indegree_;
113 }
114
115 return *this;
116 }
StructuralConstraintDiGraph & operator=(const StructuralConstraintDiGraph &from)
copy operator

References StructuralConstraintIndegree(), _Indegree_max_indegree_, _Indegree_max_parents_, and gum::learning::StructuralConstraintDiGraph::operator=().

Here is the call graph for this function:

◆ operator=() [2/2]

StructuralConstraintIndegree & gum::learning::StructuralConstraintIndegree::operator= ( StructuralConstraintIndegree && from)

move operator

Definition at line 120 of file structuralConstraintIndegree.cpp.

120 {
121 if (this != &from) {
123 _Indegree_max_parents_ = std::move(from._Indegree_max_parents_);
124 _Indegree_max_indegree_ = std::move(from._Indegree_max_indegree_);
125 }
126
127 return *this;
128 }

References StructuralConstraintIndegree(), _Indegree_max_indegree_, _Indegree_max_parents_, and gum::learning::StructuralConstraintDiGraph::operator=().

Here is the call graph for this function:

◆ setGraph()

void gum::learning::StructuralConstraintSetStatic< StructuralConstraintDiGraph, OTHER_CONSTRAINTS >::setGraph ( const DiGraph & graph)
inherited

sets a new graph from which we will perform checkings

◆ setGraphAlone()

void gum::learning::StructuralConstraintIndegree::setGraphAlone ( const DiGraph & graph)

sets a new graph from which we will perform checkings

◆ setIndegree()

void gum::learning::StructuralConstraintIndegree::setIndegree ( const NodeProperty< Size > & max_indegree)

sets the default max indegree for all the nodes in the property

◆ setMaxIndegree()

void gum::learning::StructuralConstraintIndegree::setMaxIndegree ( Size max_indegree,
bool update_all_node = false )

resets the default max indegree and possibly updates the indegree of all nodes

Member Data Documentation

◆ _Indegree_max_indegree_

Size gum::learning::StructuralConstraintIndegree::_Indegree_max_indegree_ {std::numeric_limits< Size >::max()}
protected

a default max indegree to assign for nodes without specified indegree

Definition at line 266 of file structuralConstraintIndegree.h.

266{std::numeric_limits< Size >::max()};

Referenced by StructuralConstraintIndegree(), StructuralConstraintIndegree(), StructuralConstraintIndegree(), StructuralConstraintIndegree(), operator=(), and operator=().

◆ _Indegree_max_parents_

NodeProperty< Size > gum::learning::StructuralConstraintIndegree::_Indegree_max_parents_
protected

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