aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DBRowGeneratorSet.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
47#ifndef GUM_LEARNING_DBROW_GENERATOR_SET_H
48#define GUM_LEARNING_DBROW_GENERATOR_SET_H
49
50#include <vector>
51
52#include <agrum/agrum.h>
53
55
56namespace gum {
57
58 namespace learning {
59
60
129 class DBRowGeneratorSet final {
130 public:
131 // ##########################################################################
133 // ##########################################################################
134
136
139
142
145
147 virtual DBRowGeneratorSet* clone() const;
148
151
153
154
155 // ##########################################################################
157 // ##########################################################################
158
160
163
166
168
171 DBRowGenerator& operator[](const std::size_t i);
172
174
177 const DBRowGenerator& operator[](const std::size_t i) const;
178
180
181
182 // ##########################################################################
184 // ##########################################################################
185
187
189
193 template < class Generator >
194 void insertGenerator(const Generator& generator);
195
197
201 template < class Generator >
202 void insertGenerator(const Generator& generator, 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 >& input_row);
218
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
254 void setColumnsOfInterest(const std::vector< std::size_t >& cols_of_interest);
255
275 void setColumnsOfInterest(std::vector< std::size_t >&& cols_of_interest);
276
278 const std::vector< std::size_t >& columnsOfInterest() const;
279
281
282
283#ifndef DOXYGEN_SHOULD_SKIP_THIS
284
285 private:
286 // the vector of all the generators
287 std::vector< DBRowGenerator* > _generators_;
288
289 // the number of generators
290 std::size_t _nb_generators_{std::size_t(0)};
291
292 // the next output row to return when method generate is called
293 const DBRow< DBTranslatedValue >* _output_row_{nullptr};
294
295 // the generation of output rows can be viewed as the traversal of a
296 // tree: each node of the tree correspond to the input row received by
297 // a generator. So the root node is the row passed in argument to
298 // the setInputDBrow() Method. From these input rows, generators produce
299 // through their generate() method new output rows, which correspond to
300 // the input rows of the next level of the tree. If we traverse this tree
301 // in terms of generators rather than in terms of input rows, which makes
302 // sense knowing our data structures, we need to know whether we should
303 // call only Method generate() to move down the tree or whether we should
304 // call first Method setInputDBrow() and then generate(). Actually, when
305 // a generator receives a new input row, it should call Method
306 // setInputDBrow(), which updates its data structure in order to be able
307 // to subsequently produce new output rows using Method generate().
308 // So, we need to discriminate between the situation in which Method
309 // setInputDBrow() has already been called from the situation in which
310 // we first need to call setInputDBrow(). The following vector allows this
311 // discrimination: when its cells equal 0, we need to call setInputDBrow()
312 // first, else when they equal 1, we just need to call the generate()
313 // method.
314 std::vector< int > _setInputRow_performed_;
315
316
318
323 bool _produceNextRow_(const DBRow< DBTranslatedValue >* input_row, std::size_t i);
324
325#endif /* DOXYGEN_SHOULD_SKIP_THIS */
326 };
327
328 } /* namespace learning */
329
330} /* namespace gum */
331
332// always include the template implementation
334
336#ifndef GUM_NO_INLINE
338#endif /* GUM_NO_INLINE */
339
340
341#endif /* GUM_LEARNING_DBROW_GENERATOR_SET_H */
Template implementation of DBRowGeneratorSet.
Base class for DBRowGenerator classes that use a BN for computing their outputs.
Class representing a Bayesian network.
Definition BayesNet.h:93
void insertGenerator(const Generator &generator)
inserts a new generator at the end of the set
DBRowGeneratorSet & operator=(DBRowGeneratorSet &&from)
move operator
bool hasRows()
returns true if there are still rows that can be output by the set of generators
void setBayesNet(const BayesNet< GUM_SCALAR > &new_bn)
assign a new Bayes net to all the generators that depend on a BN
DBRowGeneratorSet(const DBRowGeneratorSet &from)
copy constructor
const DBRowGenerator & operator[](const std::size_t i) const
returns the ith generator
void reset()
resets all the generators
const std::vector< std::size_t > & columnsOfInterest() const
returns the current set of columns of interest
void setColumnsOfInterest(const std::vector< std::size_t > &cols_of_interest)
sets the columns of interest: the output DBRow needs only contain correct values fot these columns
std::size_t nbGenerators() const noexcept
returns the number of generators
DBRowGeneratorSet & operator=(const DBRowGeneratorSet &from)
copy operator
virtual ~DBRowGeneratorSet()
destructor
bool setInputRow(const DBRow< DBTranslatedValue > &input_row)
sets the input row from which the generators will create new rows
virtual DBRowGeneratorSet * clone() const
virtual copy constructor
DBRowGenerator & operator[](const std::size_t i)
returns the ith generator
void clear()
removes all the generators
const DBRow< DBTranslatedValue > & generate()
generates a new output row from the input row
void insertGenerator(const Generator &generator, const std::size_t i)
inserts a new generator at the ith position of the set
std::size_t size() const noexcept
returns the number of generators (alias for nbGenerators)
DBRowGeneratorSet(DBRowGeneratorSet &&from)
move constructor
DBRowGeneratorSet()
default constructor
The base class for all DBRow generators.
The class for storing a record in a database.
Definition DBRow.h:75
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.
The union class for storing the translated values in learning databases.