aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
DBRowGenerator4CompleteRows.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief A DBRowGenerator class that returns the rows that are complete
24  * (fully observed) w.r.t. the nodes of interest
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 #ifndef GUM_LEARNING_DBROW_GENERATOR_4_COMPLETE_ROWS_H
29 #define GUM_LEARNING_DBROW_GENERATOR_4_COMPLETE_ROWS_H
30 
31 #include <agrum/agrum.h>
32 #include <agrum/tools/database/DBRowGenerator.h>
33 
34 namespace gum {
35 
36  namespace learning {
37 
38  /** @class DBRowGenerator4CompleteRows
39  * @headerfile DBRowGenerator4CompleteRows.h <agrum/tools/database/DBRowGenerator4CompleteRows.h>
40  * @brief A DBRowGenerator class that returns the rows that are complete
41  * (fully observed) w.r.t. the nodes of interest
42  *
43  * @ingroup learning_database
44  *
45  * This class is a DBRowGenerator that returns all the rows that are
46  * complete (i.e., fully observed) w.r.t. the nodes of interest. In other
47  * words, whenever the values of the nodes of interest are observed in a
48  * row, this one is returned, but if at least one node is unobserved, the
49  * generator does not return anything. This class is useful for bootstraping
50  * EM algorithms.
51  *
52  * The standard usage of a DBRowGenerator is the following:
53  * @code
54  * // create a DatabaseTable and fill it
55  * gum::learning::DBTranslatorSet<> set;
56  * for ( int i = 0; i < 10; ++i )
57  * set.insertTranslator(gum::learning::DBTranslator4LabelizedVariable<>(),i);
58  * gum::learning::DatabaseTable<> database ( set );
59  * // fill the database
60  *
61  * // keep in a vector the types of the columns in the database
62  * const std::vector<gum::learning::DBTranslatedValueType>
63  * column_types ( 10, gum::learning::DBTranslatedValueType::DISCRETE );
64  *
65  * // create the generator
66  * gum::learning::DBRowGenerator4CompleteRows<> generator ( col_types );
67  *
68  * // parse the database and produce output rows
69  * for ( auto dbrow : database ) {
70  * generator.setInputRow ( dbrow );
71  * if ( generator.hasRows() ) {
72  * const auto& output_dbrow = generator.generate ();
73  * // do something with the output dbrow
74  * }
75  * }
76  * @endcode
77  */
78  template < template < typename > class ALLOC = std::allocator >
80  public:
81  /// type for the allocators passed in arguments of methods
83 
84  // ##########################################################################
85  /// @name Constructors / Destructors
86  // ##########################################################################
87 
88  /// @{
89 
90  /// default constructor
94 
95  /// copy constructor
96  DBRowGenerator4CompleteRows(const DBRowGenerator4CompleteRows< ALLOC >& from);
97 
98  /// copy constructor with a given allocator
99  DBRowGenerator4CompleteRows(const DBRowGenerator4CompleteRows< ALLOC >& from,
100  const allocator_type& alloc);
101 
102  /// move constructor
103  DBRowGenerator4CompleteRows(DBRowGenerator4CompleteRows< ALLOC >&& from);
104 
105  /// move constructor with a given allocator
106  DBRowGenerator4CompleteRows(DBRowGenerator4CompleteRows< ALLOC >&& from,
107  const allocator_type& alloc);
108 
109  /// virtual copy constructor
110  virtual DBRowGenerator4CompleteRows< ALLOC >* clone() const override final;
111 
112  /// virtual copy constructor with a given allocator
114  clone(const allocator_type& alloc) const override final;
115 
116  /// destructor
118 
119  /// @}
120 
121 
122  // ##########################################################################
123  /// @name Operators
124  // ##########################################################################
125 
126  /// @{
127 
128  /// copy operator
131 
132  /// move operator
134 
135  /// @}
136 
137 
138  // ##########################################################################
139  /// @name Accessors / Modifiers
140  // ##########################################################################
141 
142  /// @{
143 
144  /// generates one ouput DBRow for each DBRow passed to method setInputRow
145  /** @warning if this method is applied while the row it should return is
146  * incomplete w.r.t. the nodes of interest, its behavior is uncertain
147  * and will certainly result in a segmentation fault */
148  virtual const DBRow< DBTranslatedValue, ALLOC >& generate() final;
149 
150  /// returns the allocator used
152 
153  /// @}
154 
155 
156  protected:
157  /// computes the rows it will provide as output
158  virtual std::size_t computeRows_(const DBRow< DBTranslatedValue, ALLOC >& row) final;
159 
160 
161 #ifndef DOXYGEN_SHOULD_SKIP_THIS
162 
163  private:
164  /// the row used as input to generate the output DBRows
165  const DBRow< DBTranslatedValue, ALLOC >* _input_row_{nullptr};
166 
167 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
168  };
169 
170  } /* namespace learning */
171 
172 } /* namespace gum */
173 
174 
175 // always include the template implementation
176 #include <agrum/tools/database/DBRowGenerator4CompleteRows_tpl.h>
177 
178 #endif /* GUM_LEARNING_DBROW_GENERATOR_4_COMPLETE_ROWS_H */
DBRowGenerator4CompleteRows< ALLOC > & operator=(DBRowGenerator4CompleteRows< ALLOC > &&from)
move operator
virtual std::size_t computeRows_(const DBRow< DBTranslatedValue, ALLOC > &row) final
computes the rows it will provide as output
DBRowGenerator4CompleteRows(DBRowGenerator4CompleteRows< ALLOC > &&from)
move constructor
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
DBRowGenerator4CompleteRows(const DBRowGenerator4CompleteRows< ALLOC > &from, const allocator_type &alloc)
copy constructor with a given allocator
DBRowGenerator4CompleteRows(const DBRowGenerator4CompleteRows< ALLOC > &from)
copy constructor
virtual DBRowGenerator4CompleteRows< ALLOC > * clone(const allocator_type &alloc) const override final
virtual copy constructor with a given allocator
DBRowGenerator4CompleteRows< ALLOC > & operator=(const DBRowGenerator4CompleteRows< ALLOC > &from)
copy operator
allocator_type getAllocator() const
returns the allocator used
DBRowGenerator4CompleteRows(const std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > > column_types, const allocator_type &alloc=allocator_type())
default constructor
A DBRowGenerator class that returns the rows that are complete (fully observed) w.r.t.
DBRowGenerator4CompleteRows(DBRowGenerator4CompleteRows< ALLOC > &&from, const allocator_type &alloc)
move constructor with a given allocator
virtual const DBRow< DBTranslatedValue, ALLOC > & generate() final
generates one ouput DBRow for each DBRow passed to method setInputRow
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
virtual DBRowGenerator4CompleteRows< ALLOC > * clone() const override final
virtual copy constructor