aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::InfluenceDiagramGenerator< GUM_SCALAR > Class Template Reference

<agrum/ID/generator/influenceDiagramGenerator.h> More...

#include <influenceDiagramGenerator.h>

+ Collaboration diagram for gum::InfluenceDiagramGenerator< GUM_SCALAR >:

Public Member Functions

Constructors / Destructor
 InfluenceDiagramGenerator ()
 Default constructor. More...
 
 InfluenceDiagramGenerator (ICPTGenerator< GUM_SCALAR > *cptGenerator)
 Use this constructor if you want to use a different policy for generating CPT than the default one. More...
 
 InfluenceDiagramGenerator (UTGenerator *utGenerator)
 Use this constructor if you want to use a different policy for generating UT than the default one. More...
 
 InfluenceDiagramGenerator (ICPTGenerator< GUM_SCALAR > *cptGenerator, UTGenerator *utGenerator)
 Use this constructor if you want to use a different policy for generating both CPT & UT than the defaults ones. More...
 
 ~InfluenceDiagramGenerator ()
 Destructor. More...
 
ID generation methods
InfluenceDiagram< GUM_SCALAR > * generateID (Size nbrNodes, GUM_SCALAR arcDensity, GUM_SCALAR chanceNodeDensity, GUM_SCALAR utilityNodeDensity, Size max_modality=2)
 Generates an influence diagram using floats. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::InfluenceDiagramGenerator< GUM_SCALAR >

<agrum/ID/generator/influenceDiagramGenerator.h>

Class for generating influence diagram.

This class randomly generates an influence diagram given four parameters: the number of nodes,the probability of adding an arc between two nodes, the proportion of chance node and the proportion of utility node (the proportion of decision node is deduce from thos two)

Definition at line 56 of file influenceDiagramGenerator.h.

Constructor & Destructor Documentation

◆ InfluenceDiagramGenerator() [1/4]

template<typename GUM_SCALAR >
gum::InfluenceDiagramGenerator< GUM_SCALAR >::InfluenceDiagramGenerator ( )

Default constructor.

Use the SimpleCPTGenerator for generating the IDs CPT. Use the SimpleUTGenerator for generating the IDs UT.

Definition at line 36 of file influenceDiagramGenerator_tpl.h.

36  {
37  GUM_CONSTRUCTOR(InfluenceDiagramGenerator);
38  cptGenerator__ = new SimpleCPTGenerator< GUM_SCALAR >();
39  utGenerator__ = new SimpleUTGenerator();
40  }
ICPTGenerator< GUM_SCALAR > * cptGenerator__

◆ InfluenceDiagramGenerator() [2/4]

template<typename GUM_SCALAR >
gum::InfluenceDiagramGenerator< GUM_SCALAR >::InfluenceDiagramGenerator ( ICPTGenerator< GUM_SCALAR > *  cptGenerator)
explicit

Use this constructor if you want to use a different policy for generating CPT than the default one.

The cptGenerator will be erased when the destructor is called.

Parameters
cptGeneratorThe policy used to generate CPT.

Definition at line 47 of file influenceDiagramGenerator_tpl.h.

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

48  {
49  GUM_CONSTRUCTOR(InfluenceDiagramGenerator);
50  cptGenerator__ = cptGenerator;
51  utGenerator__ = new SimpleUTGenerator();
52  }
ICPTGenerator< GUM_SCALAR > * cptGenerator__
+ Here is the call graph for this function:

◆ InfluenceDiagramGenerator() [3/4]

template<typename GUM_SCALAR >
gum::InfluenceDiagramGenerator< GUM_SCALAR >::InfluenceDiagramGenerator ( UTGenerator utGenerator)
explicit

Use this constructor if you want to use a different policy for generating UT than the default one.

The utGenerator will be erased when the destructor is called.

Parameters
utGeneratorThe policy used to generate UT.

Definition at line 59 of file influenceDiagramGenerator_tpl.h.

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

60  {
61  GUM_CONSTRUCTOR(InfluenceDiagramGenerator);
62  cptGenerator__ = new SimpleCPTGenerator< GUM_SCALAR >();
63  utGenerator__ = utGenerator;
64  }
ICPTGenerator< GUM_SCALAR > * cptGenerator__
+ Here is the call graph for this function:

◆ InfluenceDiagramGenerator() [4/4]

template<typename GUM_SCALAR >
gum::InfluenceDiagramGenerator< GUM_SCALAR >::InfluenceDiagramGenerator ( ICPTGenerator< GUM_SCALAR > *  cptGenerator,
UTGenerator utGenerator 
)

Use this constructor if you want to use a different policy for generating both CPT & UT than the defaults ones.

The cptGenerator and utGenerator will be erased when the destructor is called.

Parameters
cptGeneratorThe policy used to generate CPT.
utGeneratorThe policy used to generate UT.

Definition at line 73 of file influenceDiagramGenerator_tpl.h.

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

75  {
76  GUM_CONSTRUCTOR(InfluenceDiagramGenerator);
77  cptGenerator__ = cptGenerator;
78  utGenerator__ = utGenerator;
79  }
ICPTGenerator< GUM_SCALAR > * cptGenerator__
+ Here is the call graph for this function:

◆ ~InfluenceDiagramGenerator()

template<typename GUM_SCALAR >
gum::InfluenceDiagramGenerator< GUM_SCALAR >::~InfluenceDiagramGenerator ( )

Destructor.

Definition at line 83 of file influenceDiagramGenerator_tpl.h.

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

83  {
84  GUM_DESTRUCTOR(InfluenceDiagramGenerator);
85  delete cptGenerator__;
86  delete utGenerator__;
87  }
ICPTGenerator< GUM_SCALAR > * cptGenerator__
+ Here is the call graph for this function:

Member Function Documentation

◆ checkTemporalOrder__()

template<typename GUM_SCALAR >
void gum::InfluenceDiagramGenerator< GUM_SCALAR >::checkTemporalOrder__ ( InfluenceDiagram< GUM_SCALAR > *  infdiag)
private

Definition at line 163 of file influenceDiagramGenerator_tpl.h.

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

164  {
165  if (!infdiag->decisionOrderExists()) {
166  Sequence< NodeId > order = infdiag->topologicalOrder(true);
167 
168  auto orderIter = order.begin();
169 
170  while ((orderIter != order.end()) && (!infdiag->isDecisionNode(*orderIter)))
171  ++orderIter;
172 
173  if (orderIter == order.end()) return;
174 
175  NodeId parentDecision = (*orderIter);
176 
177  ++orderIter;
178 
179  for (; orderIter != order.end(); ++orderIter)
180  if (infdiag->isDecisionNode(*orderIter)) {
181  infdiag->addArc(parentDecision, (*orderIter));
182  parentDecision = (*orderIter);
183  }
184  }
185  }
iterator begin() const
Returns an unsafe begin iterator.
Definition: sequence_tpl.h:658
const iterator & end() const noexcept
Returns the unsafe end iterator.
Definition: sequence_tpl.h:665
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ generateID()

template<typename GUM_SCALAR >
InfluenceDiagram< GUM_SCALAR > * gum::InfluenceDiagramGenerator< GUM_SCALAR >::generateID ( Size  nbrNodes,
GUM_SCALAR  arcDensity,
GUM_SCALAR  chanceNodeDensity,
GUM_SCALAR  utilityNodeDensity,
Size  max_modality = 2 
)

Generates an influence diagram using floats.

Parameters
nbrNodesThe number of nodes in the generated ID.
arcDensityThe probability of adding an arc between two nodes.
chanceNodeDensityThe proportion of chance node
utilityNodeDensityThe proportion of utility node
max_modalityEach DRV has from 2 to max_modality modalities
Returns
A IDs randomly generated.

Definition at line 98 of file influenceDiagramGenerator_tpl.h.

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

103  {
104  InfluenceDiagram< GUM_SCALAR >* influenceDiagram
105  = new InfluenceDiagram< GUM_SCALAR >();
106  // First we add nodes
107  HashTable< Size, NodeId > map;
108  std::stringstream strBuff;
109  Size nb_mod;
110 
111  for (Idx i = 0; i < nbrNodes; ++i) {
112  strBuff << i;
113  nb_mod = (max_modality == 2) ? 2 : 2 + rand() % (max_modality - 1);
114 
115  GUM_SCALAR cnd = chanceNodeDensity * (GUM_SCALAR)RAND_MAX;
116  GUM_SCALAR und = utilityNodeDensity * (GUM_SCALAR)RAND_MAX;
117 
118  GUM_SCALAR d = (GUM_SCALAR)rand();
119 
120  if (d < cnd)
121  map.insert(i,
122  influenceDiagram->addChanceNode(
123  LabelizedVariable(strBuff.str(), "", nb_mod)));
124  else if (d < (cnd + und))
125  map.insert(i,
126  influenceDiagram->addUtilityNode(
127  LabelizedVariable(strBuff.str(), "", 1)));
128  else
129  map.insert(i,
130  influenceDiagram->addDecisionNode(
131  LabelizedVariable(strBuff.str(), "", nb_mod)));
132 
133  strBuff.str("");
134  }
135 
136  // We add arcs
137  GUM_SCALAR p = arcDensity * (GUM_SCALAR)RAND_MAX;
138 
139  for (Size i = 0; i < nbrNodes; ++i)
140  if (!influenceDiagram->isUtilityNode(map[i]))
141  for (Size j = i + 1; j < nbrNodes; ++j)
142  if (((GUM_SCALAR)rand()) < p) {
143  influenceDiagram->addArc(map[i], map[j]);
144  }
145 
146  // And fill the CPTs and UTs
147  for (Size i = 0; i < nbrNodes; ++i)
148  if (influenceDiagram->isChanceNode(map[i]))
149  cptGenerator__->generateCPT(
150  influenceDiagram->cpt(map[i]).pos(influenceDiagram->variable(map[i])),
151  influenceDiagram->cpt(map[i]));
152  else if (influenceDiagram->isUtilityNode(map[i]))
153  utGenerator__->generateUT(influenceDiagram->utility(map[i]).pos(
154  influenceDiagram->variable(map[i])),
155  influenceDiagram->utility(map[i]));
156 
157  checkTemporalOrder__(influenceDiagram);
158 
159  return influenceDiagram;
160  }
ICPTGenerator< GUM_SCALAR > * cptGenerator__
virtual void generateUT(const Idx &varId, const Potential< float > &ut)=0
Generates a UT using floats.
void checkTemporalOrder__(InfluenceDiagram< GUM_SCALAR > *infdiag)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

Member Data Documentation

◆ cptGenerator__

template<typename GUM_SCALAR >
ICPTGenerator< GUM_SCALAR >* gum::InfluenceDiagramGenerator< GUM_SCALAR >::cptGenerator__
private

Definition at line 126 of file influenceDiagramGenerator.h.

◆ utGenerator__

template<typename GUM_SCALAR >
UTGenerator* gum::InfluenceDiagramGenerator< GUM_SCALAR >::utGenerator__
private

Definition at line 128 of file influenceDiagramGenerator.h.


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