55 template < GUM_Numeric GUM_SCALAR >
61 std::vector< MyData > l;
70 template < GUM_Numeric GUM_SCALAR >
76 factory.
addLabel(std::format(
"{}", i));
83 template < GUM_Numeric GUM_SCALAR >
86 std::string_view type,
112 template < GUM_Numeric GUM_SCALAR >
115 std::string_view type,
118 GUM_SCALAR sum = 0.0;
136 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end();
138 std::vector< std::string > chain(
140 std::format(
"{}.{}", l[lvl].r, l[lvl - 1].a[
randomValue(l[lvl - 1].a.size())])),
147 for (std::vector< std::string >::iterator a = l[lvl].a.begin(); a != l[lvl].a.end();
159 for (
size_t norms = 0; norms < size; norms +=
getDomainSize()) {
163 val[idx] = 1 + std::rand();
168 cpf[norms + idx] = val[idx] / sum;
182 template < GUM_Numeric GUM_SCALAR >
188 float density =
_layers_[lvl].inner_density;
189 std::vector< NodeId > nodes;
193 for (
const auto& agg: l[lvl].g) {
200 for (
const auto& attr: l[lvl].a) {
204 for (
const auto node: nodes)
213 for (
const auto node: dag.
nodes()) {
215 std::vector< NodeId > v;
217 for (
const auto par: dag.
parents(node))
222 Arc arc(v[idx], node);
232 template < GUM_Numeric GUM_SCALAR >
237 std::vector< std::vector< std::string > > o(
_layers_.size());
241 for (
size_t lvl = 0; lvl <
_layers_.size(); ++lvl) {
242 float density =
_layers_[lvl].outter_density;
244 for (
size_t count = 0; count <
_layers_[lvl].o; ++count) {
247 o[lvl].push_back(name);
250 std::string chain = std::format(
"{}.{}", name, l[lvl].r);
251 std::vector< std::string > ref2add;
253 for (std::vector< std::string >::iterator iter = o[lvl - 1].begin();
254 iter != o[lvl - 1].end();
256 if (
randomProba() <= density) ref2add.push_back(*iter);
263 ref2add[idx] = ref2add.back();
267 for (std::vector< std::string >::iterator iter = ref2add.begin(); iter != ref2add.end();
277 template < GUM_Numeric GUM_SCALAR >
283 template < GUM_Numeric GUM_SCALAR >
290 template < GUM_Numeric GUM_SCALAR >
295 template < GUM_Numeric GUM_SCALAR >
304 template < GUM_Numeric GUM_SCALAR >
309 template < GUM_Numeric GUM_SCALAR >
314 template < GUM_Numeric GUM_SCALAR >
319 template < GUM_Numeric GUM_SCALAR >
324 template < GUM_Numeric GUM_SCALAR >
330 template < GUM_Numeric GUM_SCALAR >
331 std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData >&
336 template < GUM_Numeric GUM_SCALAR >
337 const std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData >&
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.
<agrum/PRM/generator/layerGenerator.h>
Size getDomainSize() const
Returns the domain size of generated types.
Size getMaxParents() const
Returns the max number of parents allowed for any attribute or aggregator.
void _generateClassDag_(Size lvl, DAG &dag, Bijection< std::string, NodeId > &names, std::vector< typename LayerGenerator::MyData > &l)
std::string _generateType_(PRMFactory< GUM_SCALAR > &f)
void setLayers(const std::vector< LayerData > &v)
Defines the structure of each layers.
virtual PRM< GUM_SCALAR > * generate()
Proceeds with the generation of the PRM<GUM_SCALAR>.
void setDomainSize(Size s)
Set the domain size of generated types.
LayerGenerator & operator=(const LayerGenerator &source)
Copy operator.
void _generateClasses_(PRMFactory< GUM_SCALAR > &f, std::string_view type, std::vector< typename LayerGenerator::MyData > &l)
std::vector< LayerData > _layers_
void _generateSystem_(PRMFactory< GUM_SCALAR > &factory, std::vector< typename LayerGenerator::MyData > &l)
void _generateInterfaces_(PRMFactory< GUM_SCALAR > &f, std::string_view type, std::vector< MyData > &l)
virtual ~LayerGenerator()
Destructor.
std::vector< LayerData > & getLayer()
Returns the domain size of generated types.
void setMaxParents(Size s)
Returns the max number of parents allowed for any attribute or aggregator.
LayerGenerator()
Default constructor.
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>.
#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.
Headers of LayerGenerator.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities