aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
independenceTest.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_INDEPENDENCE_TEST_H
48#define GUM_LEARNING_INDEPENDENCE_TEST_H
49
51
52namespace gum {
53
54 namespace learning {
55
62 public:
63 // ##########################################################################
65 // ##########################################################################
67
69
90 const Prior& external_prior,
91 const std::vector< std::pair< std::size_t, std::size_t > >& ranges,
92 const Bijection< NodeId, std::size_t >& nodeId2columns
94
95
97
112 const Prior& external_prior,
113 const Bijection< NodeId, std::size_t >& nodeId2columns
115
117 [[nodiscard]] virtual IndependenceTest* clone() const = 0;
118
121
124
126 virtual std::pair< double, double >
127 statistics(NodeId var1, NodeId var2, const std::vector< NodeId >& rhs_ids = {}) = 0;
128
130
132
133
134 protected:
137
140
143
146
148 std::vector< std::size_t > _domain_sizes_;
149
151
159 static Size degreesOfFreedom_(std::size_t X_size,
160 std::size_t Y_size,
161 std::size_t Z_size = 1,
162 std::size_t n_skipped = 0);
163
165
174 std::vector< double > marginalize_(const std::size_t node_2_marginalize,
175 const std::size_t X_size,
176 const std::size_t Y_size,
177 const std::size_t Z_size,
178 const std::vector< double >& N_xyz) const;
179
181
185 template < typename CellContribFn >
186 std::pair< double, double > computeStatistics_(const IdCondSet& idset,
187 CellContribFn cellContrib);
188 };
189
190 } /* namespace learning */
191
192} /* namespace gum */
193
196
197// include the inlined functions if necessary
198#ifndef GUM_NO_INLINE
200#endif /* GUM_NO_INLINE */
201
202#endif /* GUM_LEARNING_INDEPENDENCE_TEST_H */
Common counting infrastructure for independence tests and KNML scoring.
const std::vector< std::pair< std::size_t, std::size_t > > & ranges() const
returns the current ranges
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
the class used to read a row in the database and to transform it into a set of DBRow instances that c...
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
Definition idCondSet.h:214
virtual std::pair< double, double > statistics(NodeId var1, NodeId var2, const std::vector< NodeId > &rhs_ids={})=0
returns the pair (test statistic, p-value) for the independence test X _|_ Y | Z
IndependenceTest(IndependenceTest &&from)
move constructor
IndependenceTest(const IndependenceTest &from)
copy constructor
IndependenceTest(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
std::vector< std::size_t > _domain_sizes_
the domain sizes of the variables (indexed by column id in the database)
std::vector< double > marginalize_(const std::size_t node_2_marginalize, const std::size_t X_size, const std::size_t Y_size, const std::size_t Z_size, const std::vector< double > &N_xyz) const
returns a counting vector where variables are marginalized from N_xyz
IndependenceTest & operator=(IndependenceTest &&from)
move operator
IndependenceTest & operator=(const IndependenceTest &from)
copy operator
std::pair< double, double > computeStatistics_(const IdCondSet &idset, CellContribFn cellContrib)
shared loop for chi-squared-family statistics
static Size degreesOfFreedom_(std::size_t X_size, std::size_t Y_size, std::size_t Z_size=1, std::size_t n_skipped=0)
returns the degrees of freedom for a chi2/G2 test X _|_ Y | Z
~IndependenceTest() override
destructor
virtual IndependenceTest * clone() const =0
virtual copy constructor
IndependenceTest(const DBRowGeneratorParser &parser, const Prior &external_prior, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
the base class for all a priori
Definition prior.h:81
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
the base class for all the independence tests used for learning
template implementation of computeStatistics_(), shared by all chi-squared-family independence tests ...
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46