52 template <
typename GUM_SCALAR >
58 std::vector< MyData > l;
67 template <
typename GUM_SCALAR >
74 std::stringstream sBuff;
83 template <
typename GUM_SCALAR >
86 const std::string& type,
112 template <
typename GUM_SCALAR >
115 const std::string& type,
134 template <
typename GUM_SCALAR >
137 const std::string& type,
142 GUM_SCALAR sum = 0.0;
143 std::string first, second, third;
144 std::vector< std::string >* v = 0;
150 v =
new std::vector< std::string >();
152 first = l[lvl].c.back();
163 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end();
166 s << v->back() <<
"." << l[lvl].a[
randomValue(l[lvl].a.size())];
167 std::vector< std::string > chain(1, s.str()), param(1,
"1");
172 for (std::vector< std::string >::iterator a = l[lvl].a.begin(); a != l[lvl].a.end();
184 for (
size_t norms = 0; norms < size; norms +=
getDomainSize()) {
188 val[idx] = 1 + std::rand();
193 cpf[norms + idx] = val[idx] / sum;
207 v =
new std::vector< std::string >();
210 first = l[lvl].c.back();
222 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end();
225 s << v->back() <<
"." << l[lvl].a[
randomValue(l[lvl].a.size())];
226 std::vector< std::string > chain(1, s.str()), param(1,
"1");
231 for (std::vector< std::string >::iterator a = l[lvl].a.begin(); a != l[lvl].a.end();
243 for (
size_t norms = 0; norms < size; norms +=
getDomainSize()) {
247 val[idx] = 1 + std::rand();
252 cpf[norms + idx] = val[idx] / sum;
272 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end();
275 s << v->back() <<
"." << l[lvl].a[
randomValue(l[lvl].a.size())];
276 std::vector< std::string > chain(1, s.str()), param(1,
"1");
281 for (std::vector< std::string >::iterator a = l[lvl].a.begin(); a != l[lvl].a.end();
293 for (
size_t norms = 0; norms < size; norms +=
getDomainSize()) {
297 val[idx] = 1 + std::rand();
302 cpf[norms + idx] = val[idx] / sum;
322 template <
typename GUM_SCALAR >
325 const std::string& type,
330 GUM_SCALAR sum = 0.0;
342 for (
const auto& agg: l[lvl].g) {
344 s << l[lvl].r <<
"." << l[lvl - 1].a[
randomValue(l[lvl - 1].a.size())];
345 std::vector< std::string > chain(1, s.str()), param(1,
"1");
351 for (
const auto& attr: l[lvl].a) {
362 for (
size_t norms = 0; norms < size; norms +=
getDomainSize()) {
366 val[idx] = 1 + std::rand();
371 cpf[norms + idx] = val[idx] / sum;
381 template <
typename GUM_SCALAR >
387 float density =
_layers_[lvl].inner_density;
388 std::vector< NodeId > nodes;
392 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end(); ++g) {
399 for (std::vector< std::string >::iterator a = l[lvl].a.begin(); a != l[lvl].a.end(); ++a) {
403 for (std::vector< NodeId >::iterator prnt = nodes.begin(); prnt != nodes.end(); ++prnt)
412 for (
const auto node: dag.
nodes()) {
414 std::vector< NodeId > v;
416 for (
const auto par: dag.
parents(node))
421 Arc arc(v[idx], node);
431 template <
typename GUM_SCALAR >
436 std::vector< std::vector< std::string > > o(
_layers_.size());
437 std::string name, c, first, second, third;
438 std::vector< std::string >* v = 0;
441 for (
size_t lvl = 0; lvl <
_layers_.size(); ++lvl) {
442 float density =
_layers_[lvl].outter_density;
444 for (
size_t count = 0; count <
_layers_[lvl].o; ++count) {
456 std::stringstream chain;
457 chain << second <<
"." << v->at(2);
467 std::stringstream chain_1, chain_2;
468 chain_1 << second <<
"." << v->at(2);
472 chain_2 << third <<
"." << v->at(4);
490 o[lvl].push_back(name);
493 std::stringstream chain;
494 chain << name <<
"." << l[lvl].r;
495 std::vector< std::string > ref2add;
497 for (std::vector< std::string >::iterator iter = o[lvl - 1].begin();
498 iter != o[lvl - 1].end();
500 if (
randomProba() <= density) ref2add.push_back(*iter);
507 ref2add[idx] = ref2add.back();
511 for (std::vector< std::string >::iterator iter = ref2add.begin(); iter != ref2add.end();
521 template <
typename GUM_SCALAR >
527 template <
typename GUM_SCALAR >
535 template <
typename GUM_SCALAR >
540 template <
typename GUM_SCALAR >
549 template <
typename GUM_SCALAR >
554 template <
typename GUM_SCALAR >
559 template <
typename GUM_SCALAR >
564 template <
typename GUM_SCALAR >
569 template <
typename GUM_SCALAR >
575 template <
typename GUM_SCALAR >
576 INLINE std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData >&
581 template <
typename GUM_SCALAR >
582 INLINE
const std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData >&
587 template <
typename GUM_SCALAR >
592 template <
typename GUM_SCALAR >
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
The base class for all directed edges.
void insert(const T1 &first, const T2 &second)
const T1 & first(const T2 &second) const
const T2 & second(const T1 &first) const
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
virtual NodeId addNode()
insert a new node and return its id
Exception : operation not allowed.
Size size() const noexcept
Returns the number of elements in the set.
void insert(const Key &k)
Inserts a new element into the set.
Size getDomainSize() const
Getters and setters.
void _generateClasses_(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< typename ClusteredLayerGenerator::MyData > &l)
void _generateSystem_(PRMFactory< GUM_SCALAR > &factory, std::vector< typename ClusteredLayerGenerator::MyData > &l)
ClusteredLayerGenerator & operator=(const ClusteredLayerGenerator &source)
Copy operator.
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > & getLayer()
Getters and setters.
void _generateClassDag_(Size lvl, DAG &dag, Bijection< std::string, NodeId > &names, std::vector< typename ClusteredLayerGenerator::MyData > &l)
std::string _generateType_(PRMFactory< GUM_SCALAR > &f)
virtual ~ClusteredLayerGenerator()
Destructor.
virtual PRM< GUM_SCALAR > * generate()
Proceeds with the generation of the PRM<GUM_SCALAR>.
void _generateInterfaces_(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< MyData > &l)
double getClusterRatio() const
Returns the odds of a given class to be replaced by a cluster.
void setLayers(const std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > &v)
Defines the structure of each layers.
void setClusterRatio(double ratio)
Define the odds of a given class to be replaced by a cluster.
void _generateClass_(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< typename ClusteredLayerGenerator::MyData > &l, Size lvl, Set< std::string > &i)
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > _layers_
HashTable< std::string, std::vector< std::string > * > _cluster_map_
Size getMaxParents() const
Returns the max number of parents allowed for any attribute or aggregator.
ClusteredLayerGenerator()
Default constructor.
void _generateCluster_(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< typename ClusteredLayerGenerator::MyData > &l, Size lvl, Set< std::string > &i)
void setMaxParents(Size s)
Returns the max number of parents allowed for any attribute or aggregator.
void setDomainSize(Size s)
Set the domain size of generated types.
Factory which builds a PRM<GUM_SCALAR>.
virtual void startAttribute(const std::string &type, const std::string &name, bool scalar_atttr=false) override
Tells the factory that we start an attribute declaration.
virtual void addAggregator(const std::string &name, const std::string &agg_type, const std::vector< std::string > &chains, const std::vector< std::string > ¶ms, std::string type="") override
Add an aggregator in the current declared class.
virtual void addInstance(const std::string &type, const std::string &name) override
Add an instance to the model.
virtual void addParent(const std::string &name) override
Tells the factory that we add a parent to the current declared attribute.
void setRawCPFByLines(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
virtual void endSystem() override
Tells the factory that we finished declaring a model.
virtual void setReferenceSlot(const std::string &left_instance, const std::string &left_reference, const std::string &right_instance) override
Instantiate a reference in the current model.
PRMClass< GUM_SCALAR > & retrieveClass(const std::string &name)
Returns a reference over a Class<GUM_SCALAR> given its name.
virtual void addReferenceSlot(const std::string &type, const std::string &name, bool isArray) override
Tells the factory that we started declaring a slot.
virtual void endAttribute() override
Tells the factory that we finished declaring an attribute.
virtual void startClass(const std::string &c, const std::string &ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
Tells the factory that we start a class declaration.
virtual void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.
virtual void startSystem(const std::string &name) override
Tells the factory that we started declaring a model.
virtual void addAttribute(const std::string &type, const std::string &name) override
Add an attribute to an interface.
virtual void endInterface() override
Tells the factory that we finished an interface declaration.
virtual void startDiscreteType(const std::string &name, std::string super="") override
Start a discrete subtype declaration.
PRM< GUM_SCALAR > * prm() const
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
virtual void startInterface(const std::string &i, const std::string &ext="", bool delayInheritance=false) override
Tells the factory that we start an interface declaration.
virtual void endDiscreteType() override
End the current discrete type declaration.
virtual void addLabel(const std::string &l, std::string ext="") override
Add a label to the current discrete type.
NameGenerator name_gen_
The name generator used by this class.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
double randomProba()
Returns a random double between 0 and 1 included (i.e.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities