54 template <
typename GUM_SCALAR >
60 std::vector< MyData > l;
69 template <
typename GUM_SCALAR >
75 std::stringstream sBuff;
84 template <
typename GUM_SCALAR >
87 const std::string& type,
113 template <
typename GUM_SCALAR >
116 const std::string& type,
119 GUM_SCALAR sum = 0.0;
137 for (std::vector< std::string >::iterator g = l[lvl].g.begin(); g != l[lvl].g.end();
140 s << l[lvl].r <<
"." << l[lvl - 1].a[
randomValue(l[lvl - 1].a.size())];
141 std::vector< std::string > chain(1, s.str()), param(1,
"1");
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 <
typename 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 <
typename 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::stringstream chain;
251 chain << name <<
"." << l[lvl].r;
252 std::vector< std::string > ref2add;
254 for (std::vector< std::string >::iterator iter = o[lvl - 1].begin();
255 iter != o[lvl - 1].end();
257 if (
randomProba() <= density) ref2add.push_back(*iter);
264 ref2add[idx] = ref2add.back();
268 for (std::vector< std::string >::iterator iter = ref2add.begin(); iter != ref2add.end();
278 template <
typename GUM_SCALAR >
284 template <
typename GUM_SCALAR >
292 template <
typename GUM_SCALAR >
297 template <
typename GUM_SCALAR >
306 template <
typename GUM_SCALAR >
311 template <
typename GUM_SCALAR >
316 template <
typename GUM_SCALAR >
321 template <
typename GUM_SCALAR >
326 template <
typename GUM_SCALAR >
332 template <
typename GUM_SCALAR >
333 INLINE std::vector< typename LayerGenerator< GUM_SCALAR >::LayerData >&
338 template <
typename GUM_SCALAR >
339 INLINE
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.
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.
<agrum/PRM/generator/layerGenerator.h>
void _generateInterfaces_(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< MyData > &l)
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 _generateClasses_(PRMFactory< GUM_SCALAR > &f, const std::string &type, std::vector< typename LayerGenerator::MyData > &l)
Size getDomainSize() const
Returns the domain size of generated types.
virtual PRM< GUM_SCALAR > * generate()
Proceeds with the generation of the PRM<GUM_SCALAR>.
std::vector< LayerData > _layers_
void _generateSystem_(PRMFactory< GUM_SCALAR > &factory, std::vector< typename LayerGenerator::MyData > &l)
LayerGenerator & operator=(const LayerGenerator &source)
Copy operator.
void setDomainSize(Size s)
Set the domain size of generated types.
virtual ~LayerGenerator()
Destructor.
void setMaxParents(Size s)
Returns the max number of parents allowed for any attribute or aggregator.
std::vector< LayerData > & getLayer()
Returns the domain size of generated types.
Size getMaxParents() const
Returns the max number of parents allowed for any attribute or aggregator.
LayerGenerator()
Default constructor.
void setLayers(const std::vector< LayerData > &v)
Defines the structure of each layers.
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.
Headers of LayerGenerator.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities