aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
pseudoCount.cpp
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
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
64 if (this != &from) {
65 Prior* new_prior = from.prior_->clone();
66 RecordCounter new_counter = from.counter_;
67
68 if (prior_ != nullptr) delete prior_;
69
70 prior_ = new_prior;
71 counter_ = std::move(new_counter);
72 }
73 return *this;
74 }
75
78 if (this != &from) {
79 std::swap(prior_, from.prior_);
80
81 counter_ = std::move(from.counter_);
82 }
83 return *this;
84 }
85
87
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 }
105
107
112 std::vector< double > PseudoCount::get(const std::vector< NodeId >& ids) {
113 IdCondSet idset(ids, false, true);
114 std::vector< double > N_xyz(this->counter_.counts(idset, true));
115 const bool informative_external_prior = this->prior_->isInformative();
116 if (informative_external_prior) this->prior_->addJointPseudoCount(idset, N_xyz);
117 return N_xyz;
118 }
119
120 } /* namespace learning */
121
122} /* namespace gum */
123
124#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The class for giving access to pseudo count : count in the database + prior.
Definition pseudoCount.h:67
virtual void clear()
clears all the data structures from memory, including the cache
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
const std::vector< std::pair< std::size_t, std::size_t > > & ranges() const
returns the current ranges
PseudoCount & operator=(const PseudoCount &from)
copy operator
Prior * prior_
the expert knowledge a priorwe add to the contingency tables
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
RecordCounter counter_
the record counter used for the counts over discrete variables
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
the base class for all the independence tests used for learning
the base class for all the independence tests used for learning