aGrUM  0.16.0
gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy > Class Template Reference

Class used to perform Function Graph projections. More...

#include <agrum/multidim/patterns/multiDimFunctionGraphProjector.h>

+ Collaboration diagram for gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >:

Public Member Functions

Constructors / Destructors
 MultiDimFunctionGraphProjector (const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *src, const Set< const DiscreteVariable * > &delVars, const GUM_SCALAR neutral)
 Default constructor. More...
 
 ~MultiDimFunctionGraphProjector ()
 Default destructor. More...
 
Main Method
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * project ()
 Computes and builds the Function Graph that is the result of the Projection. More...
 

Detailed Description

template<typename GUM_SCALAR, template< typename > class FUNCTOR, template< typename > class TerminalNodePolicy = ExactTerminalNodePolicy>
class gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >

Class used to perform Function Graph projections.

Definition at line 55 of file multiDimFunctionGraphProjector.h.

Constructor & Destructor Documentation

◆ MultiDimFunctionGraphProjector()

template<typename GUM_SCALAR , template< typename > class FUNCTOR, template< typename > class TerminalNodePolicy>
gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::MultiDimFunctionGraphProjector ( const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *  src,
const Set< const DiscreteVariable * > &  delVars,
const GUM_SCALAR  neutral 
)

Default constructor.

Definition at line 44 of file multiDimFunctionGraphProjector_tpl.h.

References gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__rd, gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::getReducedAndOrderedInstance(), and gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::~MultiDimFunctionGraphProjector().

47  :
48  __src(src),
49  __delVars(delVars), __function(), __neutral(neutral) {
50  GUM_CONSTRUCTOR(MultiDimFunctionGraphProjector);
52  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __rd
The resulting function graph.
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __src
One of the two function graphs used for the Projection.
const FUNCTOR< GUM_SCALAR > __function
The function to be performed on the leaves.
const GUM_SCALAR __neutral
The function to be performed on the leaves.
const Set< const DiscreteVariable *> & __delVars
The list of variables on which the projection is performed.
MultiDimFunctionGraphProjector(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *src, const Set< const DiscreteVariable * > &delVars, const GUM_SCALAR neutral)
Default constructor.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
+ Here is the call graph for this function:

◆ ~MultiDimFunctionGraphProjector()

template<typename GUM_SCALAR , template< typename > class FUNCTOR, template< typename > class TerminalNodePolicy>
gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::~MultiDimFunctionGraphProjector ( )

Default destructor.

Definition at line 62 of file multiDimFunctionGraphProjector_tpl.h.

References gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::project().

Referenced by gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::MultiDimFunctionGraphProjector().

62  {
63  GUM_DESTRUCTOR(MultiDimFunctionGraphProjector);
64  }
MultiDimFunctionGraphProjector(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *src, const Set< const DiscreteVariable * > &delVars, const GUM_SCALAR neutral)
Default constructor.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Function Documentation

◆ project()

template<typename GUM_SCALAR , template< typename > class FUNCTOR, template< typename > class TerminalNodePolicy>
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::project ( )

Computes and builds the Function Graph that is the result of the Projection.

Definition at line 76 of file multiDimFunctionGraphProjector_tpl.h.

References gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__delVars, gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__function, gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__neutral, gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__rd, gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__src, gum::DiscreteVariable::domainSize(), gum::HashTable< Key, Val, Alloc >::empty(), gum::InternalNode::nodeVar(), and gum::InternalNode::son().

Referenced by gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::~MultiDimFunctionGraphProjector().

76  {
77  __rd->copy(*__src);
78 
79  for (SetIteratorSafe< const DiscreteVariable* > varIter =
80  __delVars.beginSafe();
81  varIter != __delVars.endSafe();
82  ++varIter) {
83  const DiscreteVariable* curVar = *varIter;
84 
85  // Tout d'abord, on déplace la variable à projeter en fin de séquence afin
86  // de simplifier la projection
87  if (__rd->variablesSequence().exists(curVar))
88  __rd->manager()->moveTo(curVar, __rd->variablesSequence().size() - 1);
89 
90  // 1er cas spécial : le diagramme est un un simple noeud terminal
91  if (__rd->isTerminalNode(__rd->root())) {
92  GUM_SCALAR newVal = __neutral, oldVal = __rd->nodeValue(__rd->root());
93  for (Idx curVarModality = 0; curVarModality < curVar->domainSize();
94  ++curVarModality)
95  newVal = __function(newVal, oldVal);
96 
97  NodeId newSonId = __rd->manager()->addTerminalNode(newVal);
98  __rd->manager()->setRootNode(newSonId);
99 
100  if (__rd->variablesSequence().exists(curVar)) __rd->erase(*curVar);
101  continue;
102  }
103 
104  // 2ème cas spécial : la racine du diagramme est associée à la variable
105  // projetée
106  if (__rd->node(__rd->root())->nodeVar() == curVar) {
107  const InternalNode* curVarNode = __rd->node(__rd->root());
108  GUM_SCALAR newVal = __neutral;
109  for (Idx curVarModality = 0; curVarModality < curVar->domainSize();
110  ++curVarModality)
111  newVal =
112  __function(newVal, __rd->nodeValue(curVarNode->son(curVarModality)));
113 
114  NodeId newSonId = __rd->manager()->addTerminalNode(newVal);
115 
116  __rd->manager()->eraseNode(__rd->root(), newSonId, false);
117 
118  if (__rd->variablesSequence().exists(curVar)) __rd->erase(*curVar);
119  continue;
120  }
121 
122  // Cas général
123  HashTable< NodeId, NodeId > visitedNode(2 * __rd->realSize(), true, false);
124  std::vector< NodeId > filo;
125  filo.push_back(__rd->root());
126 
127  while (!filo.empty()) {
128  NodeId curNodeId = filo.back();
129  filo.pop_back();
130 
131  const InternalNode* curNode = __rd->node(curNodeId);
132 
133  for (Idx modality = 0; modality < curNode->nodeVar()->domainSize();
134  ++modality) {
135  NodeId oldSonId = curNode->son(modality);
136 
137  if (!visitedNode.exists(oldSonId)) {
138  NodeId newSonId = oldSonId;
139 
140  if (!__rd->isTerminalNode(oldSonId)) {
141  if (__rd->node(oldSonId)->nodeVar() != curVar) {
142  filo.push_back(oldSonId);
143  } else {
144  const InternalNode* curVarNode = __rd->node(oldSonId);
145  GUM_SCALAR newVal = __neutral;
146  for (Idx curVarModality = 0; curVarModality < curVar->domainSize();
147  ++curVarModality)
148  newVal = __function(
149  newVal, __rd->nodeValue(curVarNode->son(curVarModality)));
150 
151  newSonId = __rd->manager()->addTerminalNode(newVal);
152 
153  __rd->manager()->eraseNode(oldSonId, newSonId, false);
154  __rd->manager()->setSon(curNodeId, modality, newSonId);
155  }
156 
157  } else {
158  GUM_SCALAR newVal = __neutral, oldVal = __rd->nodeValue(oldSonId);
159  for (Idx curVarModality = 0; curVarModality < curVar->domainSize();
160  ++curVarModality)
161  newVal = __function(newVal, oldVal);
162 
163  newSonId = __rd->manager()->addTerminalNode(newVal);
164  __rd->manager()->setSon(curNodeId, modality, newSonId);
165  }
166 
167  visitedNode.insert(oldSonId, newSonId);
168 
169  } else {
170  if (__rd->node(curNodeId)->son(modality) != visitedNode[oldSonId])
171  __rd->manager()->setSon(curNodeId, modality, visitedNode[oldSonId]);
172  }
173  }
174  }
175 
176  if (__rd->variablesSequence().exists(curVar)) __rd->erase(*curVar);
177  }
178 
179  return __rd;
180  }
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __rd
The resulting function graph.
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __src
One of the two function graphs used for the Projection.
const FUNCTOR< GUM_SCALAR > __function
The function to be performed on the leaves.
const GUM_SCALAR __neutral
The function to be performed on the leaves.
const Set< const DiscreteVariable *> & __delVars
The list of variables on which the projection is performed.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ __delVars

template<typename GUM_SCALAR , template< typename > class FUNCTOR, template< typename > class TerminalNodePolicy = ExactTerminalNodePolicy>
const Set< const DiscreteVariable* >& gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__delVars
private

The list of variables on which the projection is performed.

Definition at line 94 of file multiDimFunctionGraphProjector.h.

Referenced by gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::project().

◆ __function

template<typename GUM_SCALAR , template< typename > class FUNCTOR, template< typename > class TerminalNodePolicy = ExactTerminalNodePolicy>
const FUNCTOR< GUM_SCALAR > gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__function
private

The function to be performed on the leaves.

Definition at line 100 of file multiDimFunctionGraphProjector.h.

Referenced by gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::project().

◆ __neutral

template<typename GUM_SCALAR , template< typename > class FUNCTOR, template< typename > class TerminalNodePolicy = ExactTerminalNodePolicy>
const GUM_SCALAR gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__neutral
private

The function to be performed on the leaves.

Definition at line 103 of file multiDimFunctionGraphProjector.h.

Referenced by gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::project().

◆ __rd

template<typename GUM_SCALAR , template< typename > class FUNCTOR, template< typename > class TerminalNodePolicy = ExactTerminalNodePolicy>
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__rd
private

◆ __src

template<typename GUM_SCALAR , template< typename > class FUNCTOR, template< typename > class TerminalNodePolicy = ExactTerminalNodePolicy>
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::__src
private

One of the two function graphs used for the Projection.

Definition at line 91 of file multiDimFunctionGraphProjector.h.

Referenced by gum::MultiDimFunctionGraphProjector< GUM_SCALAR, FUNCTOR, TerminalNodePolicy >::project().


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