aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
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
49
#include <
agrum/base/stattests/cachedContingencyCounter.h
>
50
51
#ifndef DOXYGEN_SHOULD_SKIP_THIS
52
54
# ifdef GUM_NO_INLINE
55
# include <
agrum/base/stattests/cachedContingencyCounter_inl.h
>
56
# endif
/* GUM_NO_INLINE */
57
58
namespace
gum
{
59
60
namespace
learning
{
61
63
CachedContingencyCounter
&
64
CachedContingencyCounter::operator=
(
const
CachedContingencyCounter
& from) {
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
82
CachedContingencyCounter
&
CachedContingencyCounter::operator=
(
CachedContingencyCounter
&& from) {
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
93
void
CachedContingencyCounter::setRanges
(
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
101
void
CachedContingencyCounter::clearRanges
() {
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 */
cachedContingencyCounter.h
Common counting infrastructure for independence tests and KNML scoring.
cachedContingencyCounter_inl.h
implementation of gum::learning::CachedContingencyCounter
gum::learning::CachedContingencyCounter
Common counting infrastructure shared by IndependenceTest and KNML.
Definition
cachedContingencyCounter.h:71
gum::learning::CachedContingencyCounter::counter_
RecordCounter counter_
the record counter used for the counts over discrete variables
Definition
cachedContingencyCounter.h:167
gum::learning::CachedContingencyCounter::prior_
Prior * prior_
the expert knowledge prior added to the contingency tables
Definition
cachedContingencyCounter.h:164
gum::learning::CachedContingencyCounter::cache_
ScoringCache cache_
the scoring cache
Definition
cachedContingencyCounter.h:170
gum::learning::CachedContingencyCounter::clearRanges
void clearRanges()
reset the ranges to the one range corresponding to the whole database
gum::learning::CachedContingencyCounter::ranges
const std::vector< std::pair< std::size_t, std::size_t > > & ranges() const
returns the current ranges
gum::learning::CachedContingencyCounter::clear
virtual void clear()
clears all the data structures from memory, including the cache
gum::learning::CachedContingencyCounter::operator=
CachedContingencyCounter & operator=(const CachedContingencyCounter &from)
copy operator
gum::learning::CachedContingencyCounter::setRanges
void setRanges(const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges)
sets new ranges to perform the counts
gum::learning::CachedContingencyCounter::use_cache_
bool use_cache_
a Boolean indicating whether we wish to use the cache
Definition
cachedContingencyCounter.h:173
gum::learning::RecordCounter::setRanges
void setRanges(const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges)
sets new ranges to perform the counting
gum::learning::RecordCounter::clearRanges
void clearRanges()
reset the ranges to the one range corresponding to the whole database
gum::learning
include the inlined functions if necessary
Definition
CSVParser.h:55
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0