aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::StatesCounter Class Reference

<agrum/FMDP/simulation/statesCounter.h> More...

#include <statesCounter.h>

+ Inheritance diagram for gum::StatesCounter:
+ Collaboration diagram for gum::StatesCounter:

Public Member Functions

Constructor & destructor.
 StatesCounter ()
 Default constructor. More...
 
 ~StatesCounter ()
 Default destructor. More...
 
Miscelleanous methods
void incState (const Instantiation &)
 
void reset (const Instantiation &)
 
const MultiDimFunctionGraph< int > * counter ()
 
Visit Methods
NodeId root () const
 
bool isTerminal (NodeId ni) const
 
const DiscreteVariablenodeVar (NodeId ni) const
 
NodeId nodeSon (NodeId ni, Idx modality) const
 
Idx nodeNbObservation (NodeId ni) const
 
void insertSetOfVars (MultiDimFunctionGraph< double > *ret) const
 

Detailed Description

<agrum/FMDP/simulation/statesCounter.h>

Provides the necessary to check whether or not states have been already visited.

Definition at line 51 of file statesCounter.h.

Constructor & Destructor Documentation

◆ StatesCounter()

gum::StatesCounter::StatesCounter ( )

Default constructor.

Definition at line 31 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

31  :
33  GUM_CONSTRUCTOR(StatesCounter);
34  }
MultiDimFunctionGraph< Size > * counter__
static MultiDimFunctionGraph< Size, ExactTerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
StatesCounter()
Default constructor.
+ Here is the call graph for this function:

◆ ~StatesCounter()

gum::StatesCounter::~StatesCounter ( )

Default destructor.

Definition at line 40 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

40  {
41  delete counter__;
42  GUM_DESTRUCTOR(StatesCounter);
43  }
MultiDimFunctionGraph< Size > * counter__
StatesCounter()
Default constructor.
+ Here is the call graph for this function:

Member Function Documentation

◆ counter()

const MultiDimFunctionGraph< int >* gum::StatesCounter::counter ( )

◆ incState()

void gum::StatesCounter::incState ( const Instantiation state)

Definition at line 66 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

66  {
67  Idx nbVisits = counter__->get(state);
68 
69  NodeId parId = counter__->root();
70  Idx parModa = state.valFromPtr(counter__->node(parId)->nodeVar());
71  while (!counter__->isTerminalNode(counter__->node(parId)->son(parModa))) {
72  parId = counter__->node(parId)->son(parModa);
73  parModa = state.valFromPtr(counter__->node(parId)->nodeVar());
74  }
75  incState__(state, parId, parModa, nbVisits);
76  }
bool isTerminalNode(const NodeId &node) const
Indicates if given node is terminal or not.
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
const DiscreteVariable * nodeVar() const
Returns the node variable.
NodeId son(Idx modality) const
Returns the son at a given index.
MultiDimFunctionGraph< Size > * counter__
const NodeId & root() const
Returns the id of the root node from the diagram.
void incState__(const Instantiation &, NodeId, Idx, Size)
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ incState__()

void gum::StatesCounter::incState__ ( const Instantiation state,
NodeId  parentId,
Idx  parentModa,
Size  nbVisits 
)
private

Definition at line 82 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

85  {
86  Idx varIter = 0;
87  if (parentId)
88  varIter
89  = state.variablesSequence().pos(counter__->node(parentId)->nodeVar()) + 1;
90 
91 
92  for (; varIter < state.variablesSequence().size(); ++varIter) {
93  const DiscreteVariable* curVar = state.variablesSequence().atPos(varIter);
94  NodeId varId = counter__->manager()->addInternalNode(curVar);
95  if (parentId)
96  counter__->manager()->setSon(parentId, parentModa, varId);
97  else
98  counter__->manager()->setRootNode(varId);
99  for (Idx moda = 0; moda < curVar->domainSize(); ++moda) {
100  if (moda == state.valFromPtr(curVar))
101  parentModa = moda;
102  else
103  counter__->manager()->setSon(varId,
104  moda,
105  counter__->terminalNodeId(nbVisits));
106  }
107  parentId = varId;
108  }
110  parentId,
111  parentModa,
112  counter__->manager()->addTerminalNode(nbVisits + 1));
113  }
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
const DiscreteVariable * nodeVar() const
Returns the node variable.
const NodeId & terminalNodeId(const GUM_SCALAR &v) const
Returns the id of the terminal node that has the given value.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
MultiDimFunctionGraph< Size > * counter__
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ insertSetOfVars()

void gum::StatesCounter::insertSetOfVars ( MultiDimFunctionGraph< double > *  ret) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 118 of file statesCounter.h.

118  {
119  for (SequenceIteratorSafe< const DiscreteVariable* > varIter
120  = counter__->variablesSequence().beginSafe();
121  varIter != counter__->variablesSequence().endSafe();
122  ++varIter)
123  ret->add(**varIter);
124  }
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
MultiDimFunctionGraph< Size > * counter__
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.

◆ isTerminal()

bool gum::StatesCounter::isTerminal ( NodeId  ni) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 97 of file statesCounter.h.

97 { return counter__->isTerminalNode(ni); }
bool isTerminalNode(const NodeId &node) const
Indicates if given node is terminal or not.
MultiDimFunctionGraph< Size > * counter__

◆ nodeNbObservation()

Idx gum::StatesCounter::nodeNbObservation ( NodeId  ni) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 116 of file statesCounter.h.

116 { return counter__->nodeValue(ni); }
const GUM_SCALAR & nodeValue(NodeId n) const
Returns value associated to given node.
MultiDimFunctionGraph< Size > * counter__

◆ nodeSon()

NodeId gum::StatesCounter::nodeSon ( NodeId  ni,
Idx  modality 
) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 109 of file statesCounter.h.

109  {
110  return counter__->node(ni)->son(modality);
111  }
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
NodeId son(Idx modality) const
Returns the son at a given index.
MultiDimFunctionGraph< Size > * counter__

◆ nodeVar()

const DiscreteVariable* gum::StatesCounter::nodeVar ( NodeId  ni) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 102 of file statesCounter.h.

102  {
103  return counter__->node(ni)->nodeVar();
104  }
const InternalNode * node(NodeId n) const
Returns internalNode structure associated to that nodeId.
const DiscreteVariable * nodeVar() const
Returns the node variable.
MultiDimFunctionGraph< Size > * counter__

◆ reset()

void gum::StatesCounter::reset ( const Instantiation initialState)

Definition at line 49 of file statesCounter.cpp.

References gum::Set< Key, Alloc >::emplace().

49  {
50  counter__->clear();
51  for (SequenceIteratorSafe< const DiscreteVariable* > varIter
52  = initialState.variablesSequence().beginSafe();
53  varIter != initialState.variablesSequence().endSafe();
54  ++varIter)
55  counter__->add(**varIter);
56 
58 
59  incState__(initialState, 0, 0, 0);
60  }
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
MultiDimFunctionGraph< Size > * counter__
void incState__(const Instantiation &, NodeId, Idx, Size)
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
void clear()
Clears the function graph.
+ Here is the call graph for this function:

◆ root()

NodeId gum::StatesCounter::root ( ) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 92 of file statesCounter.h.

92 { return counter__->root(); }
MultiDimFunctionGraph< Size > * counter__
const NodeId & root() const
Returns the id of the root node from the diagram.

Member Data Documentation

◆ counter__

MultiDimFunctionGraph< Size >* gum::StatesCounter::counter__
private

Definition at line 132 of file statesCounter.h.

◆ visitedStates__

Set< Instantiation* > gum::StatesCounter::visitedStates__
private

Definition at line 134 of file statesCounter.h.


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