aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
pseudoCount.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_PSEUDO_COUNT_H
48#define GUM_LEARNING_PSEUDO_COUNT_H
49
50#include <utility>
51
52#include <agrum/agrum.h>
53
56
57namespace gum {
58
59 namespace learning {
60
68 public:
69 // ##########################################################################
71 // ##########################################################################
73
75
96 const Prior& external_prior,
97 const std::vector< std::pair< std::size_t, std::size_t > >& ranges,
98 const Bijection< NodeId, std::size_t >& nodeId2columns
100
101
103
118 const Prior& external_prior,
119 const Bijection< NodeId, std::size_t >& nodeId2columns
121
123 virtual ~PseudoCount();
124
125
128
131
134
138
139
140 // ##########################################################################
142 // ##########################################################################
144
146
150 void setNumberOfThreads(Size nb) override;
151
153 Size getNumberOfThreads() const override;
154
156 bool isGumNumberOfThreadsOverriden() const override;
157
167 virtual void setMinNbRowsPerThread(const std::size_t nb) const;
168
170 virtual std::size_t minNbRowsPerThread() const;
171
173
179 void setRanges(const std::vector< std::pair< std::size_t, std::size_t > >& new_ranges);
180
183
185 const std::vector< std::pair< std::size_t, std::size_t > >& ranges() const;
186
188
192 std::vector< double > get(const std::vector< NodeId >& ids);
193
195 virtual void clear();
196
198
202
204 const DatabaseTable& database() const;
205
207
208
209 protected:
211 Prior* prior_{nullptr};
212
215
217 const std::vector< NodeId > empty_ids_;
218 }; /* namespace learning */
219 } // namespace learning
220} /* namespace gum */
221
222// include the inlined functions if necessary
223#ifndef GUM_NO_INLINE
225#endif /* GUM_NO_INLINE */
226
227#endif /* GUM_LEARNING_PSEUDO_COUNT_H */
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:81
const DatabaseTable & database() const
return the database used by the pseudo-count
virtual void clear()
clears all the data structures from memory, including the cache
PseudoCount & operator=(PseudoCount &&from)
move operator
PseudoCount(const PseudoCount &from)
copy constructor
void clearRanges()
reset the ranges to the one range corresponding to the whole database
std::vector< double > get(const std::vector< NodeId > &ids)
returns the pseudo-count of a pair of nodes given some other nodes
void setNumberOfThreads(Size nb) override
sets the number max of threads that can be used
const std::vector< std::pair< std::size_t, std::size_t > > & ranges() const
returns the current ranges
Size getNumberOfThreads() const override
returns the current max number of threads of the scheduler
const Bijection< NodeId, std::size_t > & nodeId2Columns() const
return the mapping between the columns of the database and the node ids
virtual ~PseudoCount()
destructor
PseudoCount & operator=(const PseudoCount &from)
copy operator
bool isGumNumberOfThreadsOverriden() const override
indicates whether the user set herself the number of threads
const std::vector< NodeId > empty_ids_
an empty vector
Prior * prior_
the expert knowledge a priorwe add to the contingency tables
PseudoCount(const DBRowGeneratorParser &parser, const Prior &external_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
PseudoCount(PseudoCount &&from)
move constructor
virtual void setMinNbRowsPerThread(const std::size_t nb) const
changes the number min of rows a thread should process in a multithreading context
void setRanges(const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges)
sets new ranges to perform the counts used by the independence test
virtual std::size_t minNbRowsPerThread() const
returns the minimum of rows that each thread should process
PseudoCount(const DBRowGeneratorParser &parser, const Prior &external_prior, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
RecordCounter counter_
the record counter used for the counts over discrete variables
The class that computes counting of observations from the database.
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:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
the base class for all a priori
the base class for all the independence tests used for learning
The class that computes counting of observations from the database.