aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
cachedContingencyCounter.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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
41
47#ifndef GUM_LEARNING_CACHED_CONTINGENCY_COUNTER_H
48#define GUM_LEARNING_CACHED_CONTINGENCY_COUNTER_H
49
50#include <utility>
51
52#include <agrum/agrum.h>
53
58
59namespace gum {
60
61 namespace learning {
62
73 public:
74 // ##########################################################################
76 // ##########################################################################
78
80
92 const Prior& prior,
93 const std::vector< std::pair< std::size_t, std::size_t > >& ranges,
94 const Bijection< NodeId, std::size_t >& nodeId2columns
96
99 const Prior& prior,
100 const Bijection< NodeId, std::size_t >& nodeId2columns
102
105
107
108
109 // ##########################################################################
111 // ##########################################################################
113
115 void setNumberOfThreads(Size nb) override;
116
118 Size getNumberOfThreads() const override;
119
121 bool isGumNumberOfThreadsOverriden() const override;
122
125 virtual void setMinNbRowsPerThread(const std::size_t nb) const;
126
128 virtual std::size_t minNbRowsPerThread() const;
129
131 void setRanges(const std::vector< std::pair< std::size_t, std::size_t > >& new_ranges);
132
135
137 const std::vector< std::pair< std::size_t, std::size_t > >& ranges() const;
138
140 virtual void clear();
141
143 virtual void clearCache();
144
146 virtual void useCache(const bool on_off);
147
149
153
155 const DatabaseTable& database() const;
156
158
159
160 protected:
162 const double one_log2_{M_LOG2E};
163
165 Prior* prior_{nullptr};
166
169
172
174 bool use_cache_{true};
175
177 const std::vector< NodeId > empty_ids_;
178
179
182
185
188
191 };
192
193 } /* namespace learning */
194
195} /* namespace gum */
196
197// include the inlined functions if necessary
198#ifndef GUM_NO_INLINE
200#endif /* GUM_NO_INLINE */
201
202#endif /* GUM_LEARNING_CACHED_CONTINGENCY_COUNTER_H */
implementation of gum::learning::CachedContingencyCounter
bool isGumNumberOfThreadsOverriden() const override
indicates whether the user set herself the number of threads
RecordCounter counter_
the record counter used for the counts over discrete variables
Prior * prior_
the expert knowledge prior added to the contingency tables
CachedContingencyCounter(const CachedContingencyCounter &from)
copy constructor
CachedContingencyCounter & operator=(CachedContingencyCounter &&from)
move operator
void clearRanges()
reset the ranges to the one range corresponding to the whole database
const std::vector< std::pair< std::size_t, std::size_t > > & ranges() const
returns the current ranges
const Bijection< NodeId, std::size_t > & nodeId2Columns() const
return the mapping between the columns of the database and the node ids
const DatabaseTable & database() const
return the database used by the score
virtual ~CachedContingencyCounter()
destructor
virtual void clear()
clears all the data structures from memory, including the cache
virtual std::size_t minNbRowsPerThread() const
returns the minimum of rows that each thread should process
CachedContingencyCounter & operator=(const CachedContingencyCounter &from)
copy operator
const std::vector< NodeId > empty_ids_
an empty vector
void setRanges(const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges)
sets new ranges to perform the counts
CachedContingencyCounter(CachedContingencyCounter &&from)
move constructor
void setNumberOfThreads(Size nb) override
sets the number max of threads that can be used
CachedContingencyCounter(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
virtual void clearCache()
clears the current cache
virtual void useCache(const bool on_off)
turn on/off the use of a cache of the previously computed score
virtual void setMinNbRowsPerThread(const std::size_t nb) const
changes the number min of rows a thread should process in a multithreading context
Size getNumberOfThreads() const override
returns the current max number of threads of the scheduler
bool use_cache_
a Boolean indicating whether we wish to use the cache
CachedContingencyCounter(const DBRowGeneratorParser &parser, const Prior &prior, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor (no ranges)
the class used to read a row in the database and to transform it into a set of DBRow instances that c...
The class representing a tabular database as used by learning tasks.
the base class for all a priori
Definition prior.h:83
The class that computes counting of observations from the database.
a cache for caching scores and independence tests results
the classes to account for structure changes in a graph
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
#define M_LOG2E
Definition math_utils.h:55
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
the base class for all a priori
The class that computes counting of observations from the database.
a cache for caching scores and independence tests results