aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
DBRowGenerator4CompleteRows_tpl.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 #include <agrum/tools/database/DBRowGenerator4CompleteRows.h>
29 
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 
32 namespace gum {
33 
34  namespace learning {
35 
36  /// returns the allocator used
37  template < template < typename > class ALLOC >
40  return DBRowGenerator< ALLOC >::getAllocator();
41  }
42 
43 
44  /// default constructor
45  template < template < typename > class ALLOC >
51  alloc) {
53  }
54 
55 
56  /// copy constructor with a given allocator
57  template < template < typename > class ALLOC >
64  }
65 
66 
67  /// copy constructor
68  template < template < typename > class ALLOC >
72 
73 
74  /// move constructor with a given allocator
75  template < template < typename > class ALLOC >
82  }
83 
84 
85  /// move constructor
86  template < template < typename > class ALLOC >
90 
91 
92  /// virtual copy constructor with a given allocator
93  template < template < typename > class ALLOC >
95  const typename DBRowGenerator4CompleteRows< ALLOC >::allocator_type& alloc) const {
98  try {
100  } catch (...) {
102  throw;
103  }
104  return generator;
105  }
106 
107 
108  /// virtual copy constructor
109  template < template < typename > class ALLOC >
111  return clone(this->getAllocator());
112  }
113 
114 
115  /// destructor
116  template < template < typename > class ALLOC >
119  }
120 
121 
122  /// copy operator
123  template < template < typename > class ALLOC >
128  return *this;
129  }
130 
131 
132  /// move operator
133  template < template < typename > class ALLOC >
138  return *this;
139  }
140 
141 
142  /// generates new lines from those the generator gets in input
143  template < template < typename > class ALLOC >
146  this->decreaseRemainingRows();
147  return *_input_row_;
148  }
149 
150 
151  /// computes the rows it will provide in output
152  template < template < typename > class ALLOC >
154  const DBRow< DBTranslatedValue, ALLOC >& row) {
155  // check that all the values are observed
156  const auto& xrow = row.row();
157  for (const auto col: this->columns_of_interest_) {
158  switch (this->column_types_[col]) {
160  if (xrow[col].discr_val == std::numeric_limits< std::size_t >::max()) {
161  _input_row_ = nullptr;
162  return std::size_t(0);
163  }
164  break;
165 
167  if (xrow[col].cont_val == std::numeric_limits< float >::max()) {
168  _input_row_ = nullptr;
169  return std::size_t(0);
170  }
171  break;
172 
173  default:
175  "DBTranslatedValueType " << int(this->column_types_[col])
176  << " is not supported yet");
177  break;
178  }
179  }
180  _input_row_ = &row;
181  return std::size_t(1);
182  }
183 
184 
185  } /* namespace learning */
186 
187 } /* namespace gum */
188 
189 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)