aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
cachedContingencyCounter.cpp
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
48
50
51#ifndef DOXYGEN_SHOULD_SKIP_THIS
52
54# ifdef GUM_NO_INLINE
56# endif /* GUM_NO_INLINE */
57
58namespace gum {
59
60 namespace learning {
61
65 if (this != &from) {
66 Prior* new_prior = from.prior_->clone();
67 RecordCounter new_counter = from.counter_;
68 ScoringCache new_cache = from.cache_;
69
70 if (prior_ != nullptr) delete prior_;
71
72 prior_ = new_prior;
73 counter_ = std::move(new_counter);
74 cache_ = std::move(new_cache);
75
76 use_cache_ = from.use_cache_;
77 }
78 return *this;
79 }
80
83 if (this != &from) {
84 std::swap(prior_, from.prior_);
85 counter_ = std::move(from.counter_);
86 cache_ = std::move(from.cache_);
87 use_cache_ = from.use_cache_;
88 }
89 return *this;
90 }
91
94 const std::vector< std::pair< std::size_t, std::size_t > >& new_ranges) {
95 std::vector< std::pair< std::size_t, std::size_t > > old_ranges = ranges();
96 counter_.setRanges(new_ranges);
97 if (old_ranges != ranges()) clear();
98 }
99
102 std::vector< std::pair< std::size_t, std::size_t > > old_ranges = ranges();
103 counter_.clearRanges();
104 if (old_ranges != ranges()) clear();
105 }
106
107 } /* namespace learning */
108
109} /* namespace gum */
110
111#endif /* DOXYGEN_SHOULD_SKIP_THIS */
Common counting infrastructure for independence tests and KNML scoring.
implementation of gum::learning::CachedContingencyCounter
Common counting infrastructure shared by IndependenceTest and KNML.
RecordCounter counter_
the record counter used for the counts over discrete variables
Prior * prior_
the expert knowledge prior added to the contingency tables
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
virtual void clear()
clears all the data structures from memory, including the cache
CachedContingencyCounter & operator=(const CachedContingencyCounter &from)
copy operator
void setRanges(const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges)
sets new ranges to perform the counts
bool use_cache_
a Boolean indicating whether we wish to use the cache
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46