aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
doorCriteria.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
46#ifndef GUM_DOOR_CRITERIA_H
47#define GUM_DOOR_CRITERIA_H
48
49#include <optional>
50#include <vector>
51
53
54namespace gum {
55
80 public:
82 using NodeSetVec = std::vector< NodeSet >;
83
84 /* ------------------------- Backdoor --------------------------- */
85
95 static bool satisfiesBackdoorCriterion(const DAG& dag, NodeId X, NodeId Y, const NodeSet& Z);
96
109 static NodeSetVec enumerateBackdoorSets(const DAG& dag,
110 NodeId X,
111 NodeId Y,
112 const NodeSet& excluded_nodes = NodeSet(),
113 std::size_t max_cardinality = 0,
114 bool only_minimal = true,
115 bool stopAtFirst = false);
116
126 static NodeSetVec enumerateBackdoorSets(const DAG& dag, NodeId X, NodeId Y, bool stopAtFirst);
127
141 static std::optional< NodeSet > firstBackdoor(const DAG& dag,
142 NodeId X,
143 NodeId Y,
144 const NodeSet& excluded_nodes = NodeSet(),
145 std::size_t max_cardinality = 0,
146 bool only_minimal = true);
147
148 /* ------------------------- Frontdoor -------------------------- */
149
159 static bool satisfiesFrontdoorCriterion(const DAG& dag, NodeId X, NodeId Y, const NodeSet& Z);
160
173 static NodeSetVec enumerateFrontdoorSets(const DAG& dag,
174 NodeId X,
175 NodeId Y,
176 const NodeSet& excluded_nodes = NodeSet(),
177 std::size_t max_cardinality = 0,
178 bool only_minimal = true,
179 bool stopAtFirst = false);
180
190 static NodeSetVec enumerateFrontdoorSets(const DAG& dag, NodeId X, NodeId Y, bool stopAtFirst);
191
205 static std::optional< NodeSet > firstFrontdoor(const DAG& dag,
206 NodeId X,
207 NodeId Y,
208 const NodeSet& excluded_nodes = NodeSet(),
209 std::size_t max_cardinality = 0,
210 bool only_minimal = true);
211
212 /* -------------------------- Utilities ------------------------- */
213
223 static bool existsUnblockedDirectedPath(const DAG& dag, NodeId X, NodeId Y, const NodeSet& Z);
224
233 static std::optional< NodeSet > nodesOnDirectedPaths(const DAG& dag, NodeId X, NodeId Y);
234
245 static NodeSet backdoorReach(const DAG& dag, NodeId X);
246
256 static bool hasBackdoorPath(const DAG& dag, NodeId X, NodeId Y, const NodeSet& Z);
257
258 private:
268 static bool _isMinimalBackdoorAdjustment(const DAG& dag, NodeId X, NodeId Y, const NodeSet& Z);
269
279 static bool _isMinimalFrontdoorAdjustment(const DAG& dag, NodeId X, NodeId Y, const NodeSet& Z);
280
281 static bool _existsUnblockedDirectedPath_(const DAG& dag,
282 NodeId X,
283 NodeId Y,
284 const NodeSet& Z,
285 NodeSet& visited);
286 };
287
288} // namespace gum
289
290#ifndef GUM_NO_INLINE
292#endif // GUM_NO_INLINE
293
294#endif // GUM_DOOR_CRITERIA_H
Base classes for directed acyclic graphs.
Base class for dag.
Definition DAG.h:121
Implements Backdoor and Frontdoor criteria utilities for a DAG.
static bool _isMinimalBackdoorAdjustment(const DAG &dag, NodeId X, NodeId Y, const NodeSet &Z)
Check whether Z is a minimal backdoor adjustment set.
static std::optional< NodeSet > firstBackdoor(const DAG &dag, NodeId X, NodeId Y, const NodeSet &excluded_nodes=NodeSet(), std::size_t max_cardinality=0, bool only_minimal=true)
Directly return the first backdoor adjustment set if any.
static bool _existsUnblockedDirectedPath_(const DAG &dag, NodeId X, NodeId Y, const NodeSet &Z, NodeSet &visited)
static NodeSetVec enumerateBackdoorSets(const DAG &dag, NodeId X, NodeId Y, const NodeSet &excluded_nodes=NodeSet(), std::size_t max_cardinality=0, bool only_minimal=true, bool stopAtFirst=false)
Enumerate valid backdoor adjustment sets.
static bool hasBackdoorPath(const DAG &dag, NodeId X, NodeId Y, const NodeSet &Z)
Test whether there exists an open backdoor path from X to Y given Z.
static NodeSetVec enumerateFrontdoorSets(const DAG &dag, NodeId X, NodeId Y, const NodeSet &excluded_nodes=NodeSet(), std::size_t max_cardinality=0, bool only_minimal=true, bool stopAtFirst=false)
Enumerate valid frontdoor adjustment sets.
static bool existsUnblockedDirectedPath(const DAG &dag, NodeId X, NodeId Y, const NodeSet &Z)
Check whether there exists a directed path X->..->Y unblocked by Z.
static std::optional< NodeSet > nodesOnDirectedPaths(const DAG &dag, NodeId X, NodeId Y)
Compute nodes lying on some directed path from X to Y.
static bool satisfiesFrontdoorCriterion(const DAG &dag, NodeId X, NodeId Y, const NodeSet &Z)
Check if Z satisfies the frontdoor criterion relative to (X, Y).
static bool satisfiesBackdoorCriterion(const DAG &dag, NodeId X, NodeId Y, const NodeSet &Z)
Check if Z satisfies the backdoor criterion relative to (X, Y).
std::vector< NodeSet > NodeSetVec
Convenience type: list of candidate adjustment sets.
static NodeSet backdoorReach(const DAG &dag, NodeId X)
Compute the "backdoor reach" of a node.
static std::optional< NodeSet > firstFrontdoor(const DAG &dag, NodeId X, NodeId Y, const NodeSet &excluded_nodes=NodeSet(), std::size_t max_cardinality=0, bool only_minimal=true)
Directly return the first frontdoor adjustment set if any.
static bool _isMinimalFrontdoorAdjustment(const DAG &dag, NodeId X, NodeId Y, const NodeSet &Z)
Check whether Z is a minimal frontdoor adjustment set.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46