30 #ifndef GUM_LEARNING_RECORD_COUNTER_H 31 #define GUM_LEARNING_RECORD_COUNTER_H 38 #include <agrum/agrum.h> 39 #include <agrum/tools/core/bijection.h> 40 #include <agrum/tools/core/sequence.h> 41 #include <agrum/tools/core/OMPThreads.h> 42 #include <agrum/tools/core/threadData.h> 43 #include <agrum/tools/graphs/DAG.h> 44 #include <agrum/tools/database/DBRowGeneratorParser.h> 45 #include <agrum/tools/stattests/idCondSet.h> 111 template <
template <
typename >
class ALLOC = std::allocator >
112 class RecordCounter {
115 using allocator_type = ALLOC< NodeId >;
142 RecordCounter(
const DBRowGeneratorParser< ALLOC >& parser,
143 const std::vector< std::pair< std::size_t, std::size_t >,
144 ALLOC< std::pair< std::size_t, std::size_t > > >& ranges,
145 const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >& nodeId2columns
146 = Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
147 const allocator_type& alloc = allocator_type());
163 RecordCounter(
const DBRowGeneratorParser< ALLOC >& parser,
164 const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >& nodeId2columns
165 = Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
166 const allocator_type& alloc = allocator_type());
169 RecordCounter(
const RecordCounter< ALLOC >& from);
172 RecordCounter(
const RecordCounter< ALLOC >& from,
const allocator_type& alloc);
175 RecordCounter(RecordCounter< ALLOC >&& from);
178 RecordCounter(RecordCounter< ALLOC >&& from,
const allocator_type& alloc);
181 virtual RecordCounter< ALLOC >* clone()
const;
184 virtual RecordCounter< ALLOC >* clone(
const allocator_type& alloc)
const;
187 virtual ~RecordCounter();
199 RecordCounter< ALLOC >& operator=(
const RecordCounter< ALLOC >& from);
202 RecordCounter< ALLOC >& operator=(RecordCounter< ALLOC >&& from);
217 void setMaxNbThreads(
const std::size_t nb)
const;
220 std::size_t nbThreads()
const;
231 void setMinNbRowsPerThread(
const std::size_t nb)
const;
234 std::size_t minNbRowsPerThread()
const;
274 const std::vector<
double, ALLOC<
double > >& counts(
const IdCondSet< ALLOC >& ids,
275 const bool check_discrete_vars =
false);
284 template <
template <
typename >
class XALLOC >
286 const std::vector< std::pair< std::size_t, std::size_t >,
287 XALLOC< std::pair< std::size_t, std::size_t > > >& new_ranges);
293 const std::vector< std::pair< std::size_t, std::size_t >,
294 ALLOC< std::pair< std::size_t, std::size_t > > >&
301 template <
typename GUM_SCALAR >
302 void setBayesNet(
const BayesNet< GUM_SCALAR >& new_bn);
305 allocator_type getAllocator()
const;
311 const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >& nodeId2Columns()
const;
314 const DatabaseTable< ALLOC >& database()
const;
319 #ifndef DOXYGEN_SHOULD_SKIP_THIS 323 std::vector< ThreadData< DBRowGeneratorParser< ALLOC > >,
324 ALLOC< ThreadData< DBRowGeneratorParser< ALLOC > > > >
329 std::vector< std::pair< std::size_t, std::size_t >,
330 ALLOC< std::pair< std::size_t, std::size_t > > >
338 mutable std::vector< std::pair< std::size_t, std::size_t >,
339 ALLOC< std::pair< std::size_t, std::size_t > > >
344 Bijection< NodeId, std::size_t, ALLOC< std::size_t > > _nodeId2columns_;
347 std::vector<
double, ALLOC<
double > > _last_DB_countings_;
350 IdCondSet< ALLOC > _last_DB_ids_;
353 std::vector<
double, ALLOC<
double > > _last_nonDB_countings_;
356 IdCondSet< ALLOC > _last_nonDB_ids_;
359 mutable std::size_t _max_nb_threads_{std::size_t(gum::getMaxNumberOfThreads())};
363 mutable std::size_t _min_nb_rows_per_thread_{100};
368 HashTable< NodeId, std::size_t > _getNodeIds2Columns_(
const IdCondSet< ALLOC >& ids)
const;
371 std::vector<
double, ALLOC<
double > >&
372 _extractFromCountings_(
const IdCondSet< ALLOC >& subset_ids,
373 const IdCondSet< ALLOC >& superset_ids,
374 const std::vector<
double, ALLOC<
double > >& superset_vect);
377 std::vector<
double, ALLOC<
double > >& _countFromDatabase_(
const IdCondSet< ALLOC >& ids);
380 void _threadedCount_(
381 const std::size_t range_begin,
382 const std::size_t range_end,
383 DBRowGeneratorParser< ALLOC >& parser,
384 const std::vector< std::pair< std::size_t, std::size_t >,
385 ALLOC< std::pair< std::size_t, std::size_t > > >& cols_and_offsets,
386 std::vector<
double, ALLOC<
double > >& countings);
392 template <
template <
typename >
class XALLOC >
394 const std::vector< std::pair< std::size_t, std::size_t >,
395 XALLOC< std::pair< std::size_t, std::size_t > > >& new_ranges)
const;
400 void _checkDiscreteVariables_(
const IdCondSet< ALLOC >& ids)
const;
406 void _raiseCheckException_(
407 const std::vector< std::string, ALLOC< std::string > >& bad_vars)
const;
410 void _dispatchRangesToThreads_();
420 #include <agrum/tools/stattests/recordCounter_tpl.h>