aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
SimpleMiic.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
56#ifndef GUM_LEARNING_SIMPLE_MIIC_H
57#define GUM_LEARNING_SIMPLE_MIIC_H
58
59#include <string>
60#include <vector>
61
62#include <agrum/config.h>
63
65
66namespace gum {
67
68 namespace learning {
69
84 public:
85 // ##########################################################################
87 // ##########################################################################
89
91 SimpleMiic();
92
94 explicit SimpleMiic(int maxLog);
95
97 SimpleMiic(const SimpleMiic& from);
98
100 SimpleMiic(SimpleMiic&& from);
101
103 ~SimpleMiic() override;
104
106
108 SimpleMiic& operator=(const SimpleMiic& from);
109
112
113 // ##########################################################################
115 // ##########################################################################
117
119
124
126
132
135
140
142
152 template < GUM_Numeric GUM_SCALAR = double,
153 typename GRAPH_CHANGES_SELECTOR,
154 typename PARAM_ESTIMATOR >
155 BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR& selector,
156 PARAM_ESTIMATOR& estimator,
157 DAG initial_dag = DAG());
158
160 const std::vector< Arc > latentVariables() const;
161
163 void addConstraints(HashTable< std::pair< NodeId, NodeId >, char > constraints);
164
166
167 protected:
168 // ##########################################################################
170 // ##########################################################################
172
174
184 void initiation_(CorrectedMutualInformation& mutualInformation,
186 HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sepSet,
188
190
201 void iteration_(CorrectedMutualInformation& mutualInformation,
203 HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sepSet,
205
208
214 void orientationMiic_(
215 CorrectedMutualInformation& mutualInformation,
217 const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sepSet);
219
221 CorrectedMutualInformation& mutualInformation,
223 const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sepSet);
224
226
235 NodeId y,
236 const std::vector< NodeId >& ui,
237 const MixedGraph& graph,
238 CorrectedMutualInformation& mutualInformation,
240
243
247 std::vector< Ranking > unshieldedTriples_(
248 const MixedGraph& graph,
249 CorrectedMutualInformation& mutualInformation,
250 const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sepSet);
251
254
259 std::vector< ProbabilisticRanking > unshieldedTriplesMiic_(
260 const MixedGraph& graph,
261 CorrectedMutualInformation& mutualInformation,
262 const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sepSet,
263 HashTable< std::pair< NodeId, NodeId >, char >& marks);
264
266
269 std::vector< ProbabilisticRanking >
271 std::vector< ProbabilisticRanking > probaTriples);
272
274
278
281
282 protected:
283 bool isForbidenArc_(NodeId x, NodeId y) const;
284 bool isOrientable_(const MixedGraph& graph, NodeId xi, NodeId xj) const;
285
286 private:
288 int _maxLog_ = 100;
290 const std::vector< NodeId > _emptySet_;
292 std::vector< Arc > _latentCouples_;
293
296
299
302
310 static bool _existsNonTrivialDirectedPath_(const MixedGraph& graph, NodeId n1, NodeId n2);
311
317 static bool _existsDirectedPath_(const MixedGraph& graph, NodeId n1, NodeId n2);
318
320 HashTable< std::pair< NodeId, NodeId >, char >& marks,
321 NodeId x,
322 NodeId y,
323 NodeId z,
324 double p1,
325 double p2);
326
328 HashTable< std::pair< NodeId, NodeId >, char >& marks,
329 NodeId x,
330 NodeId y,
331 NodeId z,
332 double p1,
333 double p2);
334
336 };
337
338 } /* namespace learning */
339
340} /* namespace gum */
341
342#endif /* GUM_LEARNING_MIIC_H */
The Miic algorithm.
ApproximationScheme(bool verbosity=false)
Base class for dag.
Definition DAG.h:121
The class for generic Hash Tables.
Definition hashTable.h:640
Heap data structure.
Definition heap.h:141
Base class for mixed graphs.
Definition mixedGraph.h:146
The class computing n times the corrected mutual information, as used in the MIIC algorithm.
DAG learnStructure(CorrectedMutualInformation &I, MixedGraph graph)
learns the structure of a Bayesian network, i.e. a DAG, by first learning an Essential graph and then...
bool isOrientable_(const MixedGraph &graph, NodeId xi, NodeId xj) const
const std::vector< Arc > latentVariables() const
get the list of arcs hiding latent variables
const std::vector< NodeId > _emptySet_
an empty conditioning set
Definition SimpleMiic.h:290
MixedGraph learnMixedStructure(CorrectedMutualInformation &mutualInformation, MixedGraph graph)
learns the structure of an Essential Graph
SimpleMiic & operator=(const SimpleMiic &from)
copy operator
void orientationMiic_(CorrectedMutualInformation &mutualInformation, MixedGraph &graph, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sepSet)
Orientation phase from the MIIC algorithm, returns a mixed graph that may contain circles.
void _propagatingOrientationMiic_(MixedGraph &graph, HashTable< std::pair< NodeId, NodeId >, char > &marks, NodeId x, NodeId y, NodeId z, double p1, double p2)
void iteration_(CorrectedMutualInformation &mutualInformation, MixedGraph &graph, HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sepSet, Heap< CondRanking, GreaterPairOn2nd > &rank)
Iteration phase.
bool _isNotLatentCouple_(NodeId x, NodeId y)
int _maxLog_
Fixes the maximum log that we accept in exponential computations.
Definition SimpleMiic.h:288
void _orientingVstructureMiic_(MixedGraph &graph, HashTable< std::pair< NodeId, NodeId >, char > &marks, NodeId x, NodeId y, NodeId z, double p1, double p2)
~SimpleMiic() override
destructor
std::vector< ProbabilisticRanking > unshieldedTriplesMiic_(const MixedGraph &graph, CorrectedMutualInformation &mutualInformation, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sepSet, HashTable< std::pair< NodeId, NodeId >, char > &marks)
gets the list of unshielded triples in the graph in decreasing value of |I'(x, y, z|{ui}...
ArcProperty< double > _arcProbas_
Storing the probabilities for each arc set in the graph.
Definition SimpleMiic.h:298
std::vector< Arc > _latentCouples_
an empty vector of arcs
Definition SimpleMiic.h:292
static bool _existsDirectedPath_(const MixedGraph &graph, NodeId n1, NodeId n2)
checks for directed paths in a graph, consider double arcs like edges
HashTable< std::pair< NodeId, NodeId >, char > _initialMarks_
Initial marks for the orientation phase, used to convey constraints.
Definition SimpleMiic.h:301
SimpleMiic()
default constructor
Size _size_
size of the database
Definition SimpleMiic.h:295
void propagatesOrientationInChainOfRemainingEdges_(MixedGraph &graph)
heuristic for remaining edges when everything else has been tried
void orientationLatents_(CorrectedMutualInformation &mutualInformation, MixedGraph &graph, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sepSet)
variant trying to propagate both orientations in a bidirected arc
MixedGraph learnPDAG(CorrectedMutualInformation &mutualInformation, MixedGraph graph)
learns the structure of an Essential Graph
bool propagatesRemainingOrientableEdges_(MixedGraph &graph, NodeId xj)
Tries to orient edges incident to xj using Meek rules.
void findBestContributor_(NodeId x, NodeId y, const std::vector< NodeId > &ui, const MixedGraph &graph, CorrectedMutualInformation &mutualInformation, Heap< CondRanking, GreaterPairOn2nd > &rank)
finds the best contributor node for a pair given a conditioning set
bool isForbidenArc_(NodeId x, NodeId y) const
void addConstraints(HashTable< std::pair< NodeId, NodeId >, char > constraints)
Set a ensemble of constraints for the orientation phase.
BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR &selector, PARAM_ESTIMATOR &estimator, DAG initial_dag=DAG())
learns the structure and the parameters of a BN
static bool _existsNonTrivialDirectedPath_(const MixedGraph &graph, NodeId n1, NodeId n2)
checks for directed paths in a graph, considering double arcs like edges, not considering arc as a di...
std::vector< Ranking > unshieldedTriples_(const MixedGraph &graph, CorrectedMutualInformation &mutualInformation, const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sepSet)
gets the list of unshielded triples in the graph in decreasing value of |I'(x, y, z|{ui}...
std::vector< ProbabilisticRanking > updateProbaTriples_(const MixedGraph &graph, std::vector< ProbabilisticRanking > probaTriples)
Updates orientation probabilities for the remaining unoriented triples.
void initiation_(CorrectedMutualInformation &mutualInformation, MixedGraph &graph, HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sepSet, Heap< CondRanking, GreaterPairOn2nd > &rank)
Initiation phase.
Complete concept for GUM_SCALAR template parameter.
Definition concepts.h:148
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
HashTable< Arc, VAL > ArcProperty
Property on graph elements.
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46