aGrUM  0.16.0
DBRowGeneratorSet.h
Go to the documentation of this file.
1 
28 #ifndef GUM_LEARNING_DBROW_GENERATOR_SET_H
29 #define GUM_LEARNING_DBROW_GENERATOR_SET_H
30 
31 #include <vector>
32 
33 #include <agrum/agrum.h>
38 
39 namespace gum {
40 
41  namespace learning {
42 
43 
112  template < template < typename > class ALLOC = std::allocator >
114  public:
116  using allocator_type = ALLOC< DBTranslatedValue >;
117 
118  // ##########################################################################
120  // ##########################################################################
121 
123 
126 
129 
132  const allocator_type& alloc);
133 
136 
139  const allocator_type& alloc);
140 
142  virtual DBRowGeneratorSet< ALLOC >* clone() const;
143 
145  virtual DBRowGeneratorSet< ALLOC >* clone(const allocator_type& alloc) const;
146 
148  virtual ~DBRowGeneratorSet();
149 
151 
152 
153  // ##########################################################################
155  // ##########################################################################
156 
158 
162 
165 
167 
170  DBRowGenerator< ALLOC >& operator[](const std::size_t i);
171 
173 
176  const DBRowGenerator< ALLOC >& operator[](const std::size_t i) const;
177 
179 
180 
181  // ##########################################################################
183  // ##########################################################################
184 
186 
188 
192  template < template < template < typename > class > class Generator >
193  void insertGenerator(const Generator< ALLOC >& generator);
194 
196 
200  template < template < template < typename > class > class Generator >
201  void insertGenerator(const Generator< ALLOC >& generator,
202  const std::size_t i);
203 
205  std::size_t nbGenerators() const noexcept;
206 
208  std::size_t size() const noexcept;
209 
212  bool hasRows();
213 
215 
217  bool setInputRow(const DBRow< DBTranslatedValue, ALLOC >& input_row);
218 
220  const DBRow< DBTranslatedValue, ALLOC >& generate();
221 
223 
226  template < typename GUM_SCALAR >
227  void setBayesNet(const BayesNet< GUM_SCALAR >& new_bn);
228 
230  void reset();
231 
233  void clear();
234 
255  const std::vector< std::size_t, ALLOC< std::size_t > >& cols_of_interest);
256 
277  std::vector< std::size_t, ALLOC< std::size_t > >&& cols_of_interest);
278 
280  const std::vector< std::size_t, ALLOC< std::size_t > >&
281  columnsOfInterest() const;
282 
285 
287 
288 
289 #ifndef DOXYGEN_SHOULD_SKIP_THIS
290 
291  private:
292  // the vector of all the generators
293  std::vector< DBRowGenerator< ALLOC >*, ALLOC< DBRowGenerator< ALLOC >* > >
294  __generators;
295 
296  // the number of generators
297  std::size_t __nb_generators{std::size_t(0)};
298 
299  // the next output row to return when method generate is called
300  const DBRow< DBTranslatedValue, ALLOC >* __output_row{nullptr};
301 
302  // the generation of output rows can be viewed as the traversal of a
303  // tree: each node of the tree correspond to the input row received by
304  // a generator. So the root node is the row passed in argument to
305  // the setInputDBrow() Method. From these input rows, generators produce
306  // through their generate() method new output rows, which correspond to
307  // the input rows of the next level of the tree. If we traverse this tree
308  // in terms of generators rather than in terms of input rows, which makes
309  // sense knowing our data structures, we need to know whether we should
310  // call only Method generate() to move down the tree or whether we should
311  // call first Method setInputDBrow() and then generate(). Actually, when
312  // a generator receives a new input row, it should call Method
313  // setInputDBrow(), which updates its data structure in order to be able
314  // to subsequently produce new output rows using Method generate().
315  // So, we need to discriminate between the situation in which Method
316  // setInputDBrow() has already been called from the situation in which
317  // we first need to call setInputDBrow(). The following vector allows this
318  // discrimination: when its cells equal 0, we need to call setInputDBrow()
319  // first, else when they equal 1, we just need to call the generate()
320  // method.
321  std::vector< int, ALLOC< int > > __setInputRow_performed;
322 
323 
325 
330  bool __produceNextRow(const DBRow< DBTranslatedValue, ALLOC >* input_row,
331  std::size_t i);
332 
333 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
334  };
335 
336  } /* namespace learning */
337 
338 } /* namespace gum */
339 
340 // always include the template implementation
342 
343 
344 #endif /* GUM_LEARNING_DBROW_GENERATOR_SET_H */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
allocator_type getAllocator() const
returns the allocator used
Class representing a Bayesian Network.
Definition: BayesNet.h:78
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::size_t size() const noexcept
returns the number of generators (alias for nbGenerators)
The class used to pack sets of generators.
DBRowGeneratorSet(const allocator_type &alloc=allocator_type())
default constructor
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
STL namespace.
void clear()
removes all the generators
ALLOC< DBTranslatedValue > allocator_type
type for the allocators passed in arguments of methods
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The union class for storing the translated values in learning databases.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void setBayesNet(const BayesNet< GUM_SCALAR > &new_bn)
assign a new Bayes net to all the generators that depend on a BN
void setColumnsOfInterest(const std::vector< std::size_t, ALLOC< std::size_t > > &cols_of_interest)
sets the columns of interest: the output DBRow needs only contain correct values fot these columns ...
DBRowGeneratorSet< ALLOC > & operator=(const DBRowGeneratorSet< ALLOC > &from)
copy operator
const std::vector< std::size_t, ALLOC< std::size_t > > & columnsOfInterest() const
returns the current set of columns of interest
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual DBRowGeneratorSet< ALLOC > * clone() const
virtual copy constructor
void reset()
resets all the generators
The class for storing a record in a database.
Definition: DBRow.h:56
void insertGenerator(const Generator< ALLOC > &generator)
inserts a new generator at the end of the set
virtual ~DBRowGeneratorSet()
destructor
std::size_t nbGenerators() const noexcept
returns the number of generators
DBRowGenerator< ALLOC > & operator[](const std::size_t i)
returns the ith generator
const DBRow< DBTranslatedValue, ALLOC > & generate()
generates a new output row from the input row
bool setInputRow(const DBRow< DBTranslatedValue, ALLOC > &input_row)
sets the input row from which the generators will create new rows
The base class for all DBRow generators.
bool hasRows()
returns true if there are still rows that can be output by the set of generators