55 template < GUM_Numeric GUM_SCALAR >
61 std::vector< MyData > l;
70 template < GUM_Numeric GUM_SCALAR >
84 template < GUM_Numeric GUM_SCALAR >
87 std::string_view type,
113 template < GUM_Numeric GUM_SCALAR >
116 std::string_view type,
135 template < GUM_Numeric GUM_SCALAR >
138 std::string_view type,
143 GUM_SCALAR sum = 0.0;
144 std::string first, second, third;
145 std::vector< std::string >* v = 0;
151 v =
new std::vector< std::string >();
153 first = l[lvl].c.back();
164 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end();
166 std::vector< std::string > chain(
168 std::format(
"{}.{}", v->back(), l[lvl].a[
randomValue(l[lvl].a.size())])),
174 for (std::vector< std::string >::iterator a = l[lvl].a.begin(); a != l[lvl].a.end();
186 for (
size_t norms = 0; norms < size; norms +=
getDomainSize()) {
190 val[idx] = 1 + std::rand();
195 cpf[norms + idx] = val[idx] / sum;
209 v =
new std::vector< std::string >();
212 first = l[lvl].c.back();
224 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end();
226 std::vector< std::string > chain(
228 std::format(
"{}.{}", v->back(), l[lvl].a[
randomValue(l[lvl].a.size())])),
234 for (std::vector< std::string >::iterator a = l[lvl].a.begin(); a != l[lvl].a.end();
246 for (
size_t norms = 0; norms < size; norms +=
getDomainSize()) {
250 val[idx] = 1 + std::rand();
255 cpf[norms + idx] = val[idx] / sum;
275 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end();
277 std::vector< std::string > chain(
279 std::format(
"{}.{}", v->back(), l[lvl].a[
randomValue(l[lvl].a.size())])),
285 for (std::vector< std::string >::iterator a = l[lvl].a.begin(); a != l[lvl].a.end();
297 for (
size_t norms = 0; norms < size; norms +=
getDomainSize()) {
301 val[idx] = 1 + std::rand();
306 cpf[norms + idx] = val[idx] / sum;
326 template < GUM_Numeric GUM_SCALAR >
329 std::string_view type,
334 GUM_SCALAR sum = 0.0;
346 for (
const auto& agg: l[lvl].g) {
347 std::vector< std::string > chain(
349 std::format(
"{}.{}", l[lvl].r, l[lvl - 1].a[
randomValue(l[lvl - 1].a.size())])),
356 for (
const auto& attr: l[lvl].a) {
367 for (
size_t norms = 0; norms < size; norms +=
getDomainSize()) {
371 val[idx] = 1 + std::rand();
376 cpf[norms + idx] = val[idx] / sum;
386 template < GUM_Numeric GUM_SCALAR >
392 float density =
_layers_[lvl].inner_density;
393 std::vector< NodeId > nodes;
397 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end(); ++g) {
404 for (std::vector< std::string >::iterator a = l[lvl].a.begin(); a != l[lvl].a.end(); ++a) {
408 for (std::vector< NodeId >::iterator prnt = nodes.begin(); prnt != nodes.end(); ++prnt)
417 for (
const auto node: dag.
nodes()) {
419 std::vector< NodeId > v;
421 for (
const auto par: dag.
parents(node))
426 Arc arc(v[idx], node);
436 template < GUM_Numeric GUM_SCALAR >
441 std::vector< std::vector< std::string > > o(
_layers_.size());
442 std::string name, c, first, second, third;
443 std::vector< std::string >* v = 0;
446 for (
size_t lvl = 0; lvl <
_layers_.size(); ++lvl) {
447 float density =
_layers_[lvl].outter_density;
449 for (
size_t count = 0; count <
_layers_[lvl].o; ++count) {
490 o[lvl].push_back(name);
493 std::string chain = std::format(
"{}.{}", name, l[lvl].r);
494 std::vector< std::string > ref2add;
496 for (std::vector< std::string >::iterator iter = o[lvl - 1].begin();
497 iter != o[lvl - 1].end();
499 if (
randomProba() <= density) ref2add.push_back(*iter);
506 ref2add[idx] = ref2add.back();
510 for (std::vector< std::string >::iterator iter = ref2add.begin(); iter != ref2add.end();
520 template < GUM_Numeric GUM_SCALAR >
526 template < GUM_Numeric GUM_SCALAR >
534 template < GUM_Numeric GUM_SCALAR >
539 template < GUM_Numeric GUM_SCALAR >
548 template < GUM_Numeric GUM_SCALAR >
553 template < GUM_Numeric GUM_SCALAR >
558 template < GUM_Numeric GUM_SCALAR >
563 template < GUM_Numeric GUM_SCALAR >
568 template < GUM_Numeric GUM_SCALAR >
574 template < GUM_Numeric GUM_SCALAR >
575 std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData >&
580 template < GUM_Numeric GUM_SCALAR >
581 const std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData >&
586 template < GUM_Numeric GUM_SCALAR >
591 template < GUM_Numeric 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.
const T2 & second(const T1 &first) const
void insert(const T1 &first, const T2 &second)
const T1 & first(const T2 &second) 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.
void insert(const Key &k)
Inserts a new element into the set.
Size size() const noexcept
Returns the number of elements in the set.
void _generateSystem_(PRMFactory< GUM_SCALAR > &factory, std::vector< typename ClusteredLayerGenerator::MyData > &l)
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 PRM< GUM_SCALAR > * generate()
Proceeds with the generation of the PRM<GUM_SCALAR>.
Size getDomainSize() const
Getters and setters.
void _generateClasses_(PRMFactory< GUM_SCALAR > &f, std::string_view type, std::vector< typename ClusteredLayerGenerator::MyData > &l)
void _generateClass_(PRMFactory< GUM_SCALAR > &f, std::string_view type, std::vector< typename ClusteredLayerGenerator::MyData > &l, Size lvl, Set< std::string > &i)
ClusteredLayerGenerator()
Default constructor.
void _generateCluster_(PRMFactory< GUM_SCALAR > &f, std::string_view type, std::vector< typename ClusteredLayerGenerator::MyData > &l, Size lvl, Set< std::string > &i)
void setLayers(const std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > &v)
Defines the structure of each layers.
std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData > _layers_
void setClusterRatio(double ratio)
Define the odds of a given class to be replaced by a cluster.
HashTable< std::string, std::vector< std::string > * > _cluster_map_
void _generateInterfaces_(PRMFactory< GUM_SCALAR > &f, std::string_view type, std::vector< MyData > &l)
virtual ~ClusteredLayerGenerator()
Destructor.
double getClusterRatio() const
Returns the odds of a given class to be replaced by a cluster.
Size getMaxParents() const
Returns the max number of parents allowed for any attribute or aggregator.
void setMaxParents(Size s)
Returns the max number of parents allowed for any attribute or aggregator.
ClusteredLayerGenerator & operator=(const ClusteredLayerGenerator &source)
Copy operator.
void setDomainSize(Size s)
Set the domain size of generated types.
Factory which builds a PRM<GUM_SCALAR>.
void addLabel(std::string_view l, std::string_view ext="") override
Add a label to the current discrete type.
void startDiscreteType(std::string_view name, std::string_view super="") override
Start a discrete subtype declaration.
void addReferenceSlot(std::string_view type, std::string_view name, bool isArray) override
Tells the factory that we started declaring a slot.
void endInterface() override
Tells the factory that we finished an interface declaration.
void setReferenceSlot(std::string_view left_instance, std::string_view left_reference, std::string_view right_instance) override
Instantiate a reference in the current model.
void startInterface(std::string_view i, std::string_view ext="", bool delayInheritance=false) override
Tells the factory that we start an interface declaration.
PRM< GUM_SCALAR > * prm() const
Returns a pointer on the PRM<GUM_SCALAR> created by this factory.
void addAttribute(std::string_view type, std::string_view name) override
Add an attribute to an interface.
void setRawCPFByLines(const std::vector< GUM_SCALAR > &array)
Gives the factory the CPF in its raw form.
PRMClass< GUM_SCALAR > & retrieveClass(std::string_view name)
Returns a reference over a Class<GUM_SCALAR> given its name.
void startSystem(std::string_view name) override
Tells the factory that we started declaring a model.
void addInstance(std::string_view type, std::string_view name) override
Add an instance to the model.
void addAggregator(std::string_view name, std::string_view agg_type, const std::vector< std::string > &chains, const std::vector< std::string > ¶ms, std::string_view type="") override
Add an aggregator in the current declared class.
void startAttribute(std::string_view type, std::string_view name, bool scalar_atttr=false) override
Tells the factory that we start an attribute declaration.
void endClass(bool checkImplementations=true) override
Tells the factory that we finished a class declaration.
void startClass(std::string_view c, std::string_view ext="", const Set< std::string > *implements=nullptr, bool delayInheritance=false) override
Tells the factory that we start a class declaration.
void endAttribute() override
Tells the factory that we finished declaring an attribute.
void endSystem() override
Tells the factory that we finished declaring a model.
void addParent(std::string_view name) override
Tells the factory that we add a parent to the current declared attribute.
void endDiscreteType() override
End the current discrete type declaration.
NameGenerator name_gen_
The name generator used by this class.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
Headers of ClusteredLayerGenerator.
#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