aGrUM  0.14.2
DBRowGeneratorSet.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
25 #ifndef GUM_LEARNING_DBROW_GENERATOR_SET_H
26 #define GUM_LEARNING_DBROW_GENERATOR_SET_H
27 
28 #include <vector>
29 
30 #include <agrum/agrum.h>
35 
36 namespace gum {
37 
38  namespace learning {
39 
40 
109  template < template < typename > class ALLOC = std::allocator >
111  public:
113  using allocator_type = ALLOC< DBTranslatedValue >;
114 
115  // ##########################################################################
117  // ##########################################################################
118 
120 
123 
126 
129  const allocator_type& alloc);
130 
133 
136  const allocator_type& alloc);
137 
139  virtual DBRowGeneratorSet< ALLOC >* clone() const;
140 
142  virtual DBRowGeneratorSet< ALLOC >* clone(const allocator_type& alloc) const;
143 
145  virtual ~DBRowGeneratorSet();
146 
148 
149 
150  // ##########################################################################
152  // ##########################################################################
153 
155 
159 
162 
164 
167  DBRowGenerator< ALLOC >& operator[](const std::size_t i);
168 
170 
173  const DBRowGenerator< ALLOC >& operator[](const std::size_t i) const;
174 
176 
177 
178  // ##########################################################################
180  // ##########################################################################
181 
183 
185 
189  template < template < template < typename > class > class Generator >
190  void insertGenerator(const Generator< ALLOC >& generator);
191 
193 
197  template < template < template < typename > class > class Generator >
198  void insertGenerator(const Generator< ALLOC >& generator,
199  const std::size_t i);
200 
202  std::size_t nbGenerators() const noexcept;
203 
205  std::size_t size() const noexcept;
206 
209  bool hasRows();
210 
212 
214  bool setInputRow(const DBRow< DBTranslatedValue, ALLOC >& input_row);
215 
217  const DBRow< DBTranslatedValue, ALLOC >& generate();
218 
220 
223  template < typename GUM_SCALAR >
224  void setBayesNet(const BayesNet< GUM_SCALAR >& new_bn);
225 
227  void reset();
228 
230  void clear();
231 
252  const std::vector< std::size_t, ALLOC< std::size_t > >& cols_of_interest);
253 
274  std::vector< std::size_t, ALLOC< std::size_t > >&& cols_of_interest);
275 
277  const std::vector< std::size_t, ALLOC< std::size_t > >&
278  columnsOfInterest() const;
279 
282 
284 
285 
286 #ifndef DOXYGEN_SHOULD_SKIP_THIS
287 
288  private:
289  // the vector of all the generators
290  std::vector< DBRowGenerator< ALLOC >*, ALLOC< DBRowGenerator< ALLOC >* > >
291  __generators;
292 
293  // the number of generators
294  std::size_t __nb_generators{std::size_t(0)};
295 
296  // the next output row to return when method generate is called
297  const DBRow< DBTranslatedValue, ALLOC >* __output_row{nullptr};
298 
299  // the generation of output rows can be viewed as the traversal of a
300  // tree: each node of the tree correspond to the input row received by
301  // a generator. So the root node is the row passed in argument to
302  // the setInputDBrow() Method. From these input rows, generators produce
303  // through their generate() method new output rows, which correspond to
304  // the input rows of the next level of the tree. If we traverse this tree
305  // in terms of generators rather than in terms of input rows, which makes
306  // sense knowing our data structures, we need to know whether we should
307  // call only Method generate() to move down the tree or whether we should
308  // call first Method setInputDBrow() and then generate(). Actually, when
309  // a generator receives a new input row, it should call Method
310  // setInputDBrow(), which updates its data structure in order to be able
311  // to subsequently produce new output rows using Method generate().
312  // So, we need to discriminate between the situation in which Method
313  // setInputDBrow() has already been called from the situation in which
314  // we first need to call setInputDBrow(). The following vector allows this
315  // discrimination: when its cells equal 0, we need to call setInputDBrow()
316  // first, else when they equal 1, we just need to call the generate()
317  // method.
318  std::vector< int, ALLOC< int > > __setInputRow_performed;
319 
320 
322 
327  bool __produceNextRow(const DBRow< DBTranslatedValue, ALLOC >* input_row,
328  std::size_t i);
329 
330 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
331  };
332 
333  } /* namespace learning */
334 
335 } /* namespace gum */
336 
337 // always include the template implementation
339 
340 
341 #endif /* GUM_LEARNING_DBROW_GENERATOR_SET_H */
The union class for storing the translated values in learning databases.
allocator_type getAllocator() const
returns the allocator used
Class representing a Bayesian Network.
Definition: BayesNet.h:76
The base class for all DBRow generators.
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
Base class for DBRowGenerator classes that use a BN for computing their outputs.
STL namespace.
void clear()
removes all the generators
ALLOC< DBTranslatedValue > allocator_type
type for the allocators passed in arguments of methods
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The union class for storing the translated values in learning databases.
The class representing a record stored in a tabular database.
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
Template implementation of DBRowGeneratorSet.
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:53
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