aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
DBRowGenerator4CompleteRows.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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
95 
96  /// copy constructor
98  const DBRowGenerator4CompleteRows< ALLOC >& from);
99 
100  /// copy constructor with a given allocator
101  DBRowGenerator4CompleteRows(const DBRowGenerator4CompleteRows< ALLOC >& from,
102  const allocator_type& alloc);
103 
104  /// move constructor
105  DBRowGenerator4CompleteRows(DBRowGenerator4CompleteRows< ALLOC >&& from);
106 
107  /// move constructor with a given allocator
108  DBRowGenerator4CompleteRows(DBRowGenerator4CompleteRows< ALLOC >&& from,
109  const allocator_type& alloc);
110 
111  /// virtual copy constructor
112  virtual DBRowGenerator4CompleteRows< ALLOC >* clone() const override final;
113 
114  /// virtual copy constructor with a given allocator
116  clone(const allocator_type& alloc) const override final;
117 
118  /// destructor
120 
121  /// @}
122 
123 
124  // ##########################################################################
125  /// @name Operators
126  // ##########################################################################
127 
128  /// @{
129 
130  /// copy operator
133 
134  /// move operator
137 
138  /// @}
139 
140 
141  // ##########################################################################
142  /// @name Accessors / Modifiers
143  // ##########################################################################
144 
145  /// @{
146 
147  /// generates one ouput DBRow for each DBRow passed to method setInputRow
148  /** @warning if this method is applied while the row it should return is
149  * incomplete w.r.t. the nodes of interest, its behavior is uncertain
150  * and will certainly result in a segmentation fault */
151  virtual const DBRow< DBTranslatedValue, ALLOC >& generate() final;
152 
153  /// returns the allocator used
155 
156  /// @}
157 
158 
159  protected:
160  /// computes the rows it will provide as output
161  virtual std::size_t
162  computeRows_(const DBRow< DBTranslatedValue, ALLOC >& row) final;
163 
164 
165 #ifndef DOXYGEN_SHOULD_SKIP_THIS
166 
167  private:
168  /// the row used as input to generate the output DBRows
169  const DBRow< DBTranslatedValue, ALLOC >* input_row__{nullptr};
170 
171 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
172  };
173 
174  } /* namespace learning */
175 
176 } /* namespace gum */
177 
178 
179 // always include the template implementation
180 #include <agrum/tools/database/DBRowGenerator4CompleteRows_tpl.h>
181 
182 #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:669
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