aGrUM  0.13.2
gum::prm::ClusteredLayerGenerator< GUM_SCALAR > Class Template Reference

<agrum/PRM/generator/clusteredLayerGenerator.h> More...

#include <clusteredLayerGenerator.h>

+ Inheritance diagram for gum::prm::ClusteredLayerGenerator< GUM_SCALAR >:
+ Collaboration diagram for gum::prm::ClusteredLayerGenerator< GUM_SCALAR >:

Public Member Functions

Constructors and destructor.
 ClusteredLayerGenerator ()
 Default constructor. More...
 
 ClusteredLayerGenerator (const ClusteredLayerGenerator &source)
 Copy constructor. More...
 
ClusteredLayerGeneratoroperator= (const ClusteredLayerGenerator &source)
 Copy operator. More...
 
virtual ~ClusteredLayerGenerator ()
 Destructor. More...
 
Size getDomainSize () const
 Getters and setters. More...
 
void setDomainSize (Size s)
 Set the domain size of generated types. More...
 
Size getMaxParents () const
 Returns the max number of parents allowed for any attribute or aggregator. More...
 
void setMaxParents (Size s)
 Returns the max number of parents allowed for any attribute or aggregator. More...
 
double getClusterRatio () const
 Returns the odds of a given class to be replaced by a cluster. More...
 
void setClusterRatio (double ratio)
 Define the odds of a given class to be replaced by a cluster. More...
 
void setLayers (const std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > &v)
 Defines the structure of each layers. More...
 
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > & getLayer ()
 Getters and setters. More...
 
const std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > & getLayer () const
 Getters and setters. More...
 
virtual PRM< GUM_SCALAR > * generate ()
 Proceeds with the generation of the PRM<GUM_SCALAR>. More...
 
void setNameGenerator (const NameGenerator &name_gen)
 Getters and setters. More...
 
const NameGeneratorgetNameGenerator () const
 Returns the NameGenerator used by this generator. More...
 

Protected Attributes

NameGenerator _name_gen
 The name generator used by this class. More...
 

Classes

struct  MyData
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::ClusteredLayerGenerator< GUM_SCALAR >

<agrum/PRM/generator/clusteredLayerGenerator.h>

This class generates PRMs with a clustered layer structure.

Definition at line 54 of file clusteredLayerGenerator.h.

Constructor & Destructor Documentation

template<typename GUM_SCALAR >
INLINE gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::ClusteredLayerGenerator ( )

Default constructor.

Definition at line 527 of file clusteredLayerGenerator_tpl.h.

527  :
528  __layers(), __domain_size(2), __max_parents(INT_MAX),
529  __cluster_ratio(0.0) {
530  GUM_CONSTRUCTOR(ClusteredLayerGenerator);
531  }
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers
template<typename GUM_SCALAR >
INLINE gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::ClusteredLayerGenerator ( const ClusteredLayerGenerator< GUM_SCALAR > &  source)

Copy constructor.

Definition at line 534 of file clusteredLayerGenerator_tpl.h.

535  :
536  __layers(source.__layers),
537  __domain_size(source.__domain_size), __max_parents(source.__max_parents) {
538  GUM_CONS_CPY(ClusteredLayerGenerator);
539  }
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers
template<typename GUM_SCALAR >
INLINE gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::~ClusteredLayerGenerator ( )
virtual

Destructor.

Definition at line 542 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::operator=().

542  {
543  GUM_DESTRUCTOR(ClusteredLayerGenerator);
544  // typedef HashTable<std::string, std::vector<std::string>*>::iterator
545  // Iter;
546  // for (Iter iter = __cluster_map.begin(); iter != __cluster_map.end();
547  // ++iter)
548  // {
549  // delete *iter;
550  // }
551  }

+ Here is the call graph for this function:

Member Function Documentation

template<typename GUM_SCALAR>
void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass ( PRMFactory< GUM_SCALAR > &  f,
const std::string &  type,
std::vector< typename ClusteredLayerGenerator< GUM_SCALAR >::MyData > &  l,
Size  lvl,
Set< std::string > &  i 
)
private

Definition at line 317 of file clusteredLayerGenerator_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addAggregator(), gum::prm::PRMFactory< GUM_SCALAR >::addParent(), gum::prm::PRMFactory< GUM_SCALAR >::addReferenceSlot(), gum::prm::PRMObject::CLASS, gum::prm::PRMFactory< GUM_SCALAR >::endAttribute(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::first(), gum::ArcGraphPart::parents(), gum::prm::PRMFactory< GUM_SCALAR >::retrieveClass(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::second(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByLines(), gum::prm::PRMFactory< GUM_SCALAR >::startAttribute(), and gum::prm::PRMFactory< GUM_SCALAR >::startClass().

322  {
323  Size size = 0;
324  GUM_SCALAR sum = 0.0;
325  l[lvl].c.push_back(this->_name_gen.nextName(PRMObject::prm_type::CLASS));
326  f.startClass(l[lvl].c.back(), "", &i);
327 
328  if (lvl) f.addReferenceSlot(l[lvl - 1].i, l[lvl].r, true);
329 
330  DAG dag;
332  __generateClassDag(lvl, dag, names, l);
333 
334  // Adding aggregates
335  if (lvl) {
336  for (const auto agg : l[lvl].g) {
337  std::stringstream s;
338  s << l[lvl].r << "." << l[lvl - 1].a[std::rand() % l[lvl - 1].a.size()];
339  std::vector< std::string > chain(1, s.str()), param(1, "1");
340  f.addAggregator(agg, "exists", chain, param);
341  }
342  }
343 
344  // Adding attributes
345  for (const auto attr : l[lvl].a) {
346  f.startAttribute(type, attr, true);
347  size = getDomainSize();
348 
349  for (const auto par : dag.parents(names.second(attr))) {
350  f.addParent(names.first(par));
351  size *= f.retrieveClass(l[lvl].c.back())
352  .get(names.first(par))
353  .type()
354  ->domainSize();
355  }
356 
357  std::vector< GUM_SCALAR > cpf(size), val(getDomainSize());
358 
359  for (size_t norms = 0; norms < size; norms += getDomainSize()) {
360  sum = 0.0;
361 
362  for (size_t idx = 0; idx < getDomainSize(); ++idx) {
363  val[idx] = 1 + std::rand();
364  sum += val[idx];
365  }
366 
367  for (size_t idx = 0; idx < getDomainSize(); ++idx)
368  cpf[norms + idx] = val[idx] / sum;
369  }
370 
371  f.setRawCPFByLines(cpf);
372  f.endAttribute();
373  }
374 
375  f.endClass();
376  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
Size getDomainSize() const
Getters and setters.
void __generateClassDag(Size lvl, DAG &dag, Bijection< std::string, NodeId > &names, std::vector< typename ClusteredLayerGenerator::MyData > &l)
NameGenerator _name_gen
The name generator used by this class.
Definition: PRMGenerator.h:78
std::string nextName(PRMObject::prm_type type)
Getters and setters.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag ( Size  lvl,
DAG dag,
Bijection< std::string, NodeId > &  names,
std::vector< typename ClusteredLayerGenerator< GUM_SCALAR >::MyData > &  l 
)
private

Definition at line 379 of file clusteredLayerGenerator_tpl.h.

References gum::DAG::addArc(), gum::NodeGraphPart::addNode(), gum::ArcGraphPart::eraseArc(), gum::ArcGraphPart::existsArc(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert(), gum::NodeGraphPart::nodes(), gum::ArcGraphPart::parents(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::second(), and gum::Set< Key, Alloc >::size().

383  {
384  float density = __layers[lvl].inner_density * RAND_MAX;
385  std::vector< NodeId > nodes;
386  NodeId id = 0;
387 
388  if (lvl) {
389  for (std::vector< std::string >::iterator g = l[lvl].g.begin();
390  g != l[lvl].g.end();
391  ++g) {
392  id = dag.addNode();
393  names.insert(*g, id);
394  nodes.push_back(id);
395  }
396  }
397 
398  for (std::vector< std::string >::iterator a = l[lvl].a.begin();
399  a != l[lvl].a.end();
400  ++a) {
401  id = dag.addNode();
402  names.insert(*a, id);
403 
404  for (std::vector< NodeId >::iterator prnt = nodes.begin();
405  prnt != nodes.end();
406  ++prnt)
407  if (std::rand() < density) dag.addArc(*prnt, names.second(*a));
408 
409  nodes.push_back(id);
410  }
411 
412  // For each nodes with #parents > __max_parents we randomly remove parents
413  // until
414  // #parents <= __max_parents
415  for (const auto node : dag.nodes()) {
416  if (dag.parents(node).size() > getMaxParents()) {
417  std::vector< NodeId > v;
418 
419  for (const auto par : dag.parents(node))
420  v.push_back(par);
421 
422  while (dag.parents(node).size() > getMaxParents()) {
423  size_t idx = std::rand() % v.size();
424  Arc arc(v[idx], node);
425  GUM_ASSERT(dag.existsArc(arc));
426  dag.eraseArc(arc);
427  v[idx] = v.back();
428  v.pop_back();
429  }
430  }
431  }
432  }
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Size getMaxParents() const
Returns the max number of parents allowed for any attribute or aggregator.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClasses ( PRMFactory< GUM_SCALAR > &  f,
const std::string &  type,
std::vector< typename ClusteredLayerGenerator< GUM_SCALAR >::MyData > &  l 
)
private

Definition at line 94 of file clusteredLayerGenerator_tpl.h.

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

97  {
98  // double ratio = getClusterRatio() + RAND_MAX;
100 
101  for (Size lvl = 0; lvl < __layers.size(); ++lvl) {
102  i.insert(l[lvl].i);
103 
104  for (Size c = 0; c < __layers[lvl].c; ++c) {
105  // if (std::rand() < ratio)
106  __generateCluster(f, type, l, lvl, i);
107  // else
108  // __generateClass(f, type, l, lvl, i);
109  }
110 
111  i.erase(l[lvl].i);
112  }
113  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers
void __generateCluster(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< typename ClusteredLayerGenerator::MyData > &l, Size lvl, Set< std::string > &i)
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster ( PRMFactory< GUM_SCALAR > &  f,
const std::string &  type,
std::vector< typename ClusteredLayerGenerator< GUM_SCALAR >::MyData > &  l,
Size  lvl,
Set< std::string > &  i 
)
private

Definition at line 116 of file clusteredLayerGenerator_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addAggregator(), gum::prm::PRMFactory< GUM_SCALAR >::addParent(), gum::prm::PRMFactory< GUM_SCALAR >::addReferenceSlot(), gum::prm::PRMObject::CLASS, gum::prm::PRMObject::CLASS_ELT, gum::prm::PRMFactory< GUM_SCALAR >::endAttribute(), gum::prm::PRMFactory< GUM_SCALAR >::endClass(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::first(), GUM_ERROR, gum::ArcGraphPart::parents(), gum::prm::PRMFactory< GUM_SCALAR >::retrieveClass(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::second(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByLines(), gum::prm::PRMFactory< GUM_SCALAR >::startAttribute(), and gum::prm::PRMFactory< GUM_SCALAR >::startClass().

121  {
122  Size size = 0;
123  GUM_SCALAR sum = 0.0;
124  std::string first, second, third;
125  std::vector< std::string >* v = 0;
126 
127  switch (std::rand() % 2) {
128  // Shape A->B
129  // v == [first, second, second.ref -> first]
130  case 0: {
131  v = new std::vector< std::string >();
132  __generateClass(f, type, l, lvl, i);
133  first = l[lvl].c.back();
134  v->push_back(first);
135  v->push_back(this->_name_gen.nextName(PRMObject::prm_type::CLASS));
136  f.startClass(v->back());
138  f.addReferenceSlot(first, v->back(), true);
139  DAG dag;
141  __generateClassDag(lvl, dag, names, l);
142 
143  // Adding aggregates
144  for (std::vector< std::string >::iterator g = l[lvl].g.begin();
145  g != l[lvl].g.end();
146  ++g) {
147  std::stringstream s;
148  s << v->back() << "." << l[lvl].a[std::rand() % l[lvl].a.size()];
149  std::vector< std::string > chain(1, s.str()), param(1, "1");
150  f.addAggregator(*g, "exists", chain, param);
151  }
152 
153  // Adding attributes
154  for (std::vector< std::string >::iterator a = l[lvl].a.begin();
155  a != l[lvl].a.end();
156  ++a) {
157  f.startAttribute(type, *a, true);
158  size = getDomainSize();
159 
160  for (const auto par : dag.parents(names.second(*a))) {
161  f.addParent(names.first(par));
162  size *= f.retrieveClass(l[lvl].c.back())
163  .get(names.first(par))
164  .type()
165  ->domainSize();
166  }
167 
168  std::vector< GUM_SCALAR > cpf(size), val(getDomainSize());
169 
170  for (size_t norms = 0; norms < size; norms += getDomainSize()) {
171  sum = 0.0;
172 
173  for (size_t idx = 0; idx < getDomainSize(); ++idx) {
174  val[idx] = 1 + std::rand();
175  sum += val[idx];
176  }
177 
178  for (size_t idx = 0; idx < getDomainSize(); ++idx)
179  cpf[norms + idx] = val[idx] / sum;
180  }
181 
182  f.setRawCPFByLines(cpf);
183  f.endAttribute();
184  }
185 
186  f.endClass();
187  break;
188  }
189 
190  // Shape A -> B -> C
191  // v == [first, second, second.ref -> first, third, third.ref -> second]
192  case 1: {
193  v = new std::vector< std::string >();
194  __generateClass(f, type, l, lvl, i);
195  {
196  first = l[lvl].c.back();
197  v->push_back(first);
198  v->push_back(this->_name_gen.nextName(PRMObject::prm_type::CLASS));
199  second = v->back();
200  f.startClass(second);
202  f.addReferenceSlot(first, v->back(), true);
203  DAG dag;
205  __generateClassDag(lvl, dag, names, l);
206 
207  // Adding aggregates
208  for (std::vector< std::string >::iterator g = l[lvl].g.begin();
209  g != l[lvl].g.end();
210  ++g) {
211  std::stringstream s;
212  s << v->back() << "." << l[lvl].a[std::rand() % l[lvl].a.size()];
213  std::vector< std::string > chain(1, s.str()), param(1, "1");
214  f.addAggregator(*g, "exists", chain, param);
215  }
216 
217  // Adding attributes
218  for (std::vector< std::string >::iterator a = l[lvl].a.begin();
219  a != l[lvl].a.end();
220  ++a) {
221  f.startAttribute(type, *a, true);
222  size = getDomainSize();
223 
224  for (const auto par : dag.parents(names.second(*a))) {
225  f.addParent(names.first(par));
226  size *= f.retrieveClass(l[lvl].c.back())
227  .get(names.first(par))
228  .type()
229  ->domainSize();
230  }
231 
232  std::vector< GUM_SCALAR > cpf(size), val(getDomainSize());
233 
234  for (size_t norms = 0; norms < size; norms += getDomainSize()) {
235  sum = 0.0;
236 
237  for (size_t idx = 0; idx < getDomainSize(); ++idx) {
238  val[idx] = 1 + std::rand();
239  sum += val[idx];
240  }
241 
242  for (size_t idx = 0; idx < getDomainSize(); ++idx)
243  cpf[norms + idx] = val[idx] / sum;
244  }
245 
246  f.setRawCPFByLines(cpf);
247  f.endAttribute();
248  }
249 
250  f.endClass();
251  }
252  {
253  v->push_back(this->_name_gen.nextName(PRMObject::prm_type::CLASS));
254  third = v->back();
255  f.startClass(third);
257  f.addReferenceSlot(second, v->back(), true);
258  DAG dag;
260  __generateClassDag(lvl, dag, names, l);
261 
262  // Adding aggregates
263  for (std::vector< std::string >::iterator g = l[lvl].g.begin();
264  g != l[lvl].g.end();
265  ++g) {
266  std::stringstream s;
267  s << v->back() << "." << l[lvl].a[std::rand() % l[lvl].a.size()];
268  std::vector< std::string > chain(1, s.str()), param(1, "1");
269  f.addAggregator(*g, "exists", chain, param);
270  }
271 
272  // Adding attributes
273  for (std::vector< std::string >::iterator a = l[lvl].a.begin();
274  a != l[lvl].a.end();
275  ++a) {
276  f.startAttribute(type, *a, true);
277  size = getDomainSize();
278 
279  for (const auto par : dag.parents(names.second(*a))) {
280  f.addParent(names.first(par));
281  size *= f.retrieveClass(l[lvl].c.back())
282  .get(names.first(par))
283  .type()
284  ->domainSize();
285  }
286 
287  std::vector< GUM_SCALAR > cpf(size), val(getDomainSize());
288 
289  for (size_t norms = 0; norms < size; norms += getDomainSize()) {
290  sum = 0.0;
291 
292  for (size_t idx = 0; idx < getDomainSize(); ++idx) {
293  val[idx] = 1 + std::rand();
294  sum += val[idx];
295  }
296 
297  for (size_t idx = 0; idx < getDomainSize(); ++idx)
298  cpf[norms + idx] = val[idx] / sum;
299  }
300 
301  f.setRawCPFByLines(cpf);
302  f.endAttribute();
303  }
304 
305  f.endClass();
306  }
307  break;
308  }
309 
310  default: { GUM_ERROR(OperationNotAllowed, "unexpected value"); }
311  }
312 
313  __cluster_map.insert(first, v);
314  }
HashTable< std::string, std::vector< std::string > * > __cluster_map
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
Size getDomainSize() const
Getters and setters.
void __generateClassDag(Size lvl, DAG &dag, Bijection< std::string, NodeId > &names, std::vector< typename ClusteredLayerGenerator::MyData > &l)
NameGenerator _name_gen
The name generator used by this class.
Definition: PRMGenerator.h:78
void __generateClass(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< typename ClusteredLayerGenerator::MyData > &l, Size lvl, Set< std::string > &i)
std::string nextName(PRMObject::prm_type type)
Getters and setters.
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateInterfaces ( PRMFactory< GUM_SCALAR > &  f,
const std::string &  type,
std::vector< MyData > &  l 
)
private

Definition at line 63 of file clusteredLayerGenerator_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addAttribute(), gum::prm::PRMFactory< GUM_SCALAR >::addReferenceSlot(), gum::prm::PRMObject::CLASS_ELT, gum::prm::PRMFactory< GUM_SCALAR >::endInterface(), gum::prm::PRMObject::PRM_INTERFACE, and gum::prm::PRMFactory< GUM_SCALAR >::startInterface().

66  {
67  for (Size lvl = 0; lvl < __layers.size(); ++lvl) {
68  l.push_back(ClusteredLayerGenerator< GUM_SCALAR >::MyData());
70  f.startInterface(l[lvl].i);
71 
72  for (Size a = 0; a < __layers[lvl].a; ++a) {
73  l[lvl].a.push_back(
75  f.addAttribute(type, l[lvl].a.back());
76  }
77 
78  if (lvl) {
79  for (Size g = 0; g < __layers[lvl].g; ++g) {
80  l[lvl].g.push_back(
82  f.addAttribute("boolean", l[lvl].g.back());
83  }
84 
86  f.addReferenceSlot(l[lvl - 1].i, l[lvl].r, true);
87  }
88 
89  f.endInterface();
90  }
91  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers
NameGenerator _name_gen
The name generator used by this class.
Definition: PRMGenerator.h:78
std::string nextName(PRMObject::prm_type type)
Getters and setters.

+ Here is the call graph for this function:

template<typename GUM_SCALAR>
void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateSystem ( PRMFactory< GUM_SCALAR > &  factory,
std::vector< typename ClusteredLayerGenerator< GUM_SCALAR >::MyData > &  l 
)
private

Definition at line 435 of file clusteredLayerGenerator_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addInstance(), gum::prm::PRMFactory< GUM_SCALAR >::endSystem(), GUM_ERROR, gum::prm::PRMObject::INSTANCE, gum::prm::PRMFactory< GUM_SCALAR >::setReferenceSlot(), gum::prm::PRMFactory< GUM_SCALAR >::startSystem(), and gum::prm::PRMObject::SYSTEM.

437  {
438  factory.startSystem(this->_name_gen.nextName(PRMObject::prm_type::SYSTEM));
439  std::vector< std::vector< std::string > > o(__layers.size());
440  std::string name, c, first, second, third;
441  std::vector< std::string >* v = 0;
442  size_t idx = 0;
443 
444  for (size_t lvl = 0; lvl < __layers.size(); ++lvl) {
445  float density = __layers[lvl].outter_density * RAND_MAX;
446 
447  for (size_t count = 0; count < __layers[lvl].o; ++count) {
448  c = l[lvl].c[std::rand() % l[lvl].c.size()];
449 
450  if (__cluster_map.exists(c)) {
451  v = __cluster_map[c];
452 
453  switch (v->size()) {
454  case 3: {
456  factory.addInstance(c, first);
458  factory.addInstance(v->at(1), second);
459  std::stringstream chain;
460  chain << second << "." << v->at(2);
461  factory.setReferenceSlot(chain.str(), first);
462  break;
463  }
464 
465  case 5: {
467  factory.addInstance(c, first);
469  factory.addInstance(v->at(1), second);
470  std::stringstream chain_1, chain_2;
471  chain_1 << second << "." << v->at(2);
472  factory.setReferenceSlot(chain_1.str(), first);
474  factory.addInstance(v->at(3), third);
475  chain_2 << third << "." << v->at(4);
476  factory.setReferenceSlot(chain_2.str(), second);
477  break;
478  }
479 
480  default: {
481  GUM_ERROR(OperationNotAllowed, "unexpected vector size");
482  }
483  }
484 
485  // __cluster_map.erase(c);
486  // delete v;
487  name = first;
488  } else {
490  factory.addInstance(c, name);
491  }
492 
493  o[lvl].push_back(name);
494 
495  if (lvl) {
496  std::stringstream chain;
497  chain << name << "." << l[lvl].r;
498  std::vector< std::string > ref2add;
499 
500  for (std::vector< std::string >::iterator iter = o[lvl - 1].begin();
501  iter != o[lvl - 1].end();
502  ++iter)
503  if (std::rand() <= density) ref2add.push_back(*iter);
504 
505  if (ref2add.empty())
506  factory.setReferenceSlot(
507  chain.str(), o[lvl - 1][std::rand() % o[lvl - 1].size()]);
508 
509  while (ref2add.size() > getMaxParents()) {
510  idx = std::rand() % ref2add.size();
511  ref2add[idx] = ref2add.back();
512  ref2add.pop_back();
513  }
514 
515  for (std::vector< std::string >::iterator iter = ref2add.begin();
516  iter != ref2add.end();
517  ++iter)
518  factory.setReferenceSlot(chain.str(), *iter);
519  }
520  }
521  }
522 
523  factory.endSystem();
524  }
HashTable< std::string, std::vector< std::string > * > __cluster_map
Size getMaxParents() const
Returns the max number of parents allowed for any attribute or aggregator.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers
NameGenerator _name_gen
The name generator used by this class.
Definition: PRMGenerator.h:78
std::string nextName(PRMObject::prm_type type)
Getters and setters.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
std::string gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateType ( PRMFactory< GUM_SCALAR > &  f)
private

Definition at line 47 of file clusteredLayerGenerator_tpl.h.

References gum::prm::PRMFactory< GUM_SCALAR >::addLabel(), gum::prm::PRMFactory< GUM_SCALAR >::endDiscreteType(), gum::prm::PRMFactory< GUM_SCALAR >::startDiscreteType(), and gum::prm::PRMObject::TYPE.

48  {
49  std::string name = this->_name_gen.nextName(PRMObject::prm_type::TYPE);
50  factory.startDiscreteType(name);
51 
52  for (Size i = 0; i < __domain_size; ++i) {
53  std::stringstream sBuff;
54  sBuff << i;
55  factory.addLabel(sBuff.str());
56  }
57 
58  factory.endDiscreteType();
59  return name;
60  }
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
NameGenerator _name_gen
The name generator used by this class.
Definition: PRMGenerator.h:78
std::string nextName(PRMObject::prm_type type)
Getters and setters.

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
PRM< GUM_SCALAR > * gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::generate ( )
virtual

Proceeds with the generation of the PRM<GUM_SCALAR>.

Implements gum::prm::PRMGenerator< GUM_SCALAR >.

Definition at line 31 of file clusteredLayerGenerator_tpl.h.

References GUM_ERROR, and gum::prm::PRMFactory< GUM_SCALAR >::prm().

31  {
32  if (__layers.size() == 0) {
33  GUM_ERROR(OperationNotAllowed,
34  "cannot generate a layered PRM<GUM_SCALAR> without layers");
35  }
36 
37  std::vector< MyData > l;
38  PRMFactory< GUM_SCALAR > factory;
39  std::string type = __generateType(factory);
40  __generateInterfaces(factory, type, l);
41  __generateClasses(factory, type, l);
42  __generateSystem(factory, l);
43  return factory.prm();
44  }
std::string __generateType(PRMFactory< GUM_SCALAR > &f)
void __generateSystem(PRMFactory< GUM_SCALAR > &factory, std::vector< typename ClusteredLayerGenerator::MyData > &l)
void __generateInterfaces(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< MyData > &l)
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers
void __generateClasses(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< typename ClusteredLayerGenerator::MyData > &l)
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66

+ Here is the call graph for this function:

template<typename GUM_SCALAR >
INLINE double gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::getClusterRatio ( ) const

Returns the odds of a given class to be replaced by a cluster.

Definition at line 602 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__cluster_ratio.

602  {
603  return __cluster_ratio;
604  }
template<typename GUM_SCALAR >
INLINE Size gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::getDomainSize ( ) const

Getters and setters.

Returns the domain size of generated types.

Definition at line 564 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__domain_size.

564  {
565  return __domain_size;
566  }
template<typename GUM_SCALAR >
INLINE std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > & gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::getLayer ( )

Getters and setters.

Returns the domain size of generated types.

Definition at line 591 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__layers.

591  {
592  return __layers;
593  }
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers
template<typename GUM_SCALAR >
INLINE const std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > & gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::getLayer ( ) const

Getters and setters.

Returns the domain size of generated types.

Definition at line 597 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__layers.

597  {
598  return __layers;
599  }
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers
template<typename GUM_SCALAR >
INLINE Size gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::getMaxParents ( ) const

Returns the max number of parents allowed for any attribute or aggregator.

Definition at line 574 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__max_parents.

574  {
575  return __max_parents;
576  }
template<typename GUM_SCALAR >
INLINE const NameGenerator & gum::prm::PRMGenerator< GUM_SCALAR >::getNameGenerator ( ) const
inherited

Returns the NameGenerator used by this generator.

Definition at line 55 of file PRMGenerator_tpl.h.

References gum::prm::PRMGenerator< GUM_SCALAR >::_name_gen.

55  {
56  return _name_gen;
57  }
NameGenerator _name_gen
The name generator used by this class.
Definition: PRMGenerator.h:78
template<typename GUM_SCALAR >
INLINE ClusteredLayerGenerator< GUM_SCALAR > & gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::operator= ( const ClusteredLayerGenerator< GUM_SCALAR > &  source)

Copy operator.

Definition at line 556 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__domain_size, gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__layers, and gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__max_parents.

Referenced by gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::~ClusteredLayerGenerator().

556  {
557  __layers = source.__layers;
558  __domain_size = source.__domain_size;
559  __max_parents = source.__max_parents;
560  return *this;
561  }
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers

+ Here is the caller graph for this function:

template<typename GUM_SCALAR >
INLINE void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::setClusterRatio ( double  ratio)

Define the odds of a given class to be replaced by a cluster.

Definition at line 608 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__cluster_ratio.

608  {
609  __cluster_ratio = ratio;
610  }
template<typename GUM_SCALAR >
INLINE void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::setDomainSize ( Size  s)

Set the domain size of generated types.

Definition at line 569 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__domain_size.

template<typename GUM_SCALAR >
INLINE void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::setLayers ( const std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > &  v)

Defines the structure of each layers.

Each value in v defines a layer, were v[i].first is the number of different classes in the i-th layer and v[i].second is the number of instances in the i-th layer.

Parameters
vA vector describing each layer.

Definition at line 584 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__layers.

585  {
586  __layers = v;
587  }
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > __layers
template<typename GUM_SCALAR >
INLINE void gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::setMaxParents ( Size  s)

Returns the max number of parents allowed for any attribute or aggregator.

Definition at line 579 of file clusteredLayerGenerator_tpl.h.

References gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__max_parents.

template<typename GUM_SCALAR >
INLINE void gum::prm::PRMGenerator< GUM_SCALAR >::setNameGenerator ( const NameGenerator name_gen)
inherited

Getters and setters.

Defines the NameGenerator used by this generator.

Definition at line 49 of file PRMGenerator_tpl.h.

References gum::prm::PRMGenerator< GUM_SCALAR >::_name_gen.

49  {
50  _name_gen = name_gen;
51  }
NameGenerator _name_gen
The name generator used by this class.
Definition: PRMGenerator.h:78

Member Data Documentation

template<typename GUM_SCALAR>
HashTable< std::string, std::vector< std::string >* > gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__cluster_map
private

Definition at line 119 of file clusteredLayerGenerator.h.

template<typename GUM_SCALAR >
NameGenerator gum::prm::PRMGenerator< GUM_SCALAR >::_name_gen
protectedinherited

The name generator used by this class.

Definition at line 78 of file PRMGenerator.h.

Referenced by gum::prm::PRMGenerator< GUM_SCALAR >::getNameGenerator(), and gum::prm::PRMGenerator< GUM_SCALAR >::setNameGenerator().


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