aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
recordCounter_inl.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#pragma once
41
42
43#ifndef DOXYGEN_SHOULD_SKIP_THIS
44
46
47namespace gum {
48
49 namespace learning {
50
52 INLINE std::size_t RecordCounter::minNbRowsPerThread() const {
53 return _min_nb_rows_per_thread_;
54 }
55
57 INLINE const Bijection< NodeId, std::size_t >& RecordCounter::nodeId2Columns() const {
58 return _nodeId2columns_;
59 }
60
62 INLINE const DatabaseTable& RecordCounter::database() const {
63 return _parsers_[0].data.database();
64 }
65
67 INLINE const std::vector< double >& RecordCounter::counts(const IdCondSet& ids,
68 const bool check_discrete_vars) {
69 // if the idset is empty, return an empty vector
70 if (ids.empty()) {
71 _last_nonDB_ids_.clear();
72 _last_nonDB_counting_.clear();
73 return _last_nonDB_counting_;
74 }
75
76 // check whether we can extract the vector we wish to return from
77 // some already computed counting vector
78 if (_last_nonDB_ids_.contains(ids))
79 return _extractFromCountings_(ids, _last_nonDB_ids_, _last_nonDB_counting_);
80 else if (_last_DB_ids_.contains(ids))
81 return _extractFromCountings_(ids, _last_DB_ids_, _last_DB_counting_);
82 else {
83 if (check_discrete_vars) _checkDiscreteVariables_(ids);
84 return _countFromDatabase_(ids);
85 }
86 }
87
89 INLINE const std::vector< std::pair< std::size_t, std::size_t > >&
90 RecordCounter::ranges() const {
91 return _ranges_;
92 }
93
97
98 // redispatch the ranges to the threads
99 _dispatchRangesToThreads_();
100 }
101
102 } /* namespace learning */
103
104} /* namespace gum */
105
106#endif /* DOXYGEN_SHOULD_SKIP_THIS */
virtual void setNumberOfThreads(Size nb)
sets the number max of threads to be used by the class containing this ThreadNumberManager
The class representing a tabular database as used by learning tasks.
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
Definition idCondSet.h:214
std::size_t minNbRowsPerThread() const
returns the minimum of rows that each thread should process
const std::vector< std::pair< std::size_t, std::size_t > > & ranges() const
returns the current ranges
virtual void setNumberOfThreads(Size nb)
sets the number max of threads that can be used
const DatabaseTable & database() const
returns the database on which we perform the counts
const Bijection< NodeId, std::size_t > & nodeId2Columns() const
returns the mapping from ids to column positions in the database
const std::vector< double > & counts(const IdCondSet &ids, const bool check_discrete_vars=false)
returns the counts over all the variables in an IdCondSet
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
The class that computes counting of observations from the database.