aGrUM 2.3.2
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-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
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
131 MixedGraph graph);
132
135
140
142
152 template < typename 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,
185 MixedGraph& graph,
186 HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sepSet,
188
190
201 void iteration_(CorrectedMutualInformation& mutualInformation,
202 MixedGraph& graph,
203 HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sepSet,
205
208
214 void orientationMiic_(
215 CorrectedMutualInformation& mutualInformation,
216 MixedGraph& graph,
217 const HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > >& sepSet);
219
221 CorrectedMutualInformation& mutualInformation,
222 MixedGraph& graph,
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 /*@param graph graph in which to find the triples
244 *@param I mutual information object to compute the scores
245 *@param sep_set hashtable storing the separation sets for pairs of variables
246 */
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 /*@param graph graph in which to find the triples
255 *@param I mutual information object to compute the scores
256 *@param sep_set hashtable storing the separation sets for pairs of variables
257 * @param marks hashtable containing the orientation marks for edges
258 */
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 /*@param graph graph in which to find the triples
267 *@param proba_triples probabilities for the different triples to update
268 */
269 std::vector< ProbabilisticRanking >
270 updateProbaTriples_(const MixedGraph& graph,
271 std::vector< ProbabilisticRanking > probaTriples);
272
274 /*@param dag graph in which to which to propagate arcs
275 *@param node node on which neighbours to propagate th orientation
276 *@param force : true if an orientation has always to be found.
277 */
279
282
283 protected:
284 bool isForbidenArc_(NodeId x, NodeId y) const;
285 bool isOrientable_(const MixedGraph& graph, NodeId xi, NodeId xj) const;
286
287 private:
289 int _maxLog_ = 100;
291 const std::vector< NodeId > _emptySet_;
293 std::vector< Arc > _latentCouples_;
294
297
300
303
311 static bool _existsNonTrivialDirectedPath_(const MixedGraph& graph, NodeId n1, NodeId n2);
312
318 static bool _existsDirectedPath_(const MixedGraph& graph, NodeId n1, NodeId n2);
319
321 HashTable< std::pair< NodeId, NodeId >, char >& marks,
322 NodeId x,
323 NodeId y,
324 NodeId z,
325 double p1,
326 double p2);
327
329 HashTable< std::pair< NodeId, NodeId >, char >& marks,
330 NodeId x,
331 NodeId y,
332 NodeId z,
333 double p1,
334 double p2);
335
337 };
338
339 } /* namespace learning */
340
341} /* namespace gum */
342
343#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:637
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:291
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:289
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 propabilities for each arc set in the graph.
Definition SimpleMiic.h:299
std::vector< Arc > _latentCouples_
an empty vector of arcs
Definition SimpleMiic.h:293
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:302
SimpleMiic()
default constructor
Size _size_
size of the database
Definition SimpleMiic.h:296
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)
Propagates the orientation from a node to its neighbours.
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)
Gets the orientation probabilities like MIIC for the orientation phase.
void initiation_(CorrectedMutualInformation &mutualInformation, MixedGraph &graph, HashTable< std::pair< NodeId, NodeId >, std::vector< NodeId > > &sepSet, Heap< CondRanking, GreaterPairOn2nd > &rank)
Initiation phase.
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:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46