pub struct CausalGraph { /* private fields */ }Expand description
v0.44: a directed acyclic graph over findings, derived from the link graph. Edges point from a finding to its declared parent (the finding it depends on / supports / cites as evidence).
We materialize parents and children both for fast lookup. The graph is built lazily from a Project; updates require rebuilding.
Implementations§
Source§impl CausalGraph
impl CausalGraph
Sourcepub fn from_project(project: &Project) -> Self
pub fn from_project(project: &Project) -> Self
Build the causal graph from a project’s link graph. Walks
every finding’s links array; depends and supports link
types contribute directed edges from source to target.
contradicts, extends, and other link types are excluded —
they don’t encode causal dependency.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the graph.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of directed edges in the graph.
Sourcepub fn parents_of(&self, node: &str) -> impl Iterator<Item = &str>
pub fn parents_of(&self, node: &str) -> impl Iterator<Item = &str>
Direct parents of node (findings that node depends on).
Sourcepub fn children_of(&self, node: &str) -> impl Iterator<Item = &str>
pub fn children_of(&self, node: &str) -> impl Iterator<Item = &str>
Direct children of node (findings that depend on node).
Sourcepub fn ancestors(&self, node: &str) -> HashSet<String>
pub fn ancestors(&self, node: &str) -> HashSet<String>
All ancestors of node (transitive closure of parents).
Sourcepub fn descendants(&self, node: &str) -> HashSet<String>
pub fn descendants(&self, node: &str) -> HashSet<String>
All descendants of node (transitive closure of children).
Includes node itself only if requested.
Sourcepub fn is_descendant_of(&self, candidate: &str, source: &str) -> bool
pub fn is_descendant_of(&self, candidate: &str, source: &str) -> bool
True iff candidate is a descendant of source (transitive).
Sourcepub fn paths_between(
&self,
start: &str,
end: &str,
max_paths: usize,
max_len: usize,
) -> Vec<Vec<String>>
pub fn paths_between( &self, start: &str, end: &str, max_paths: usize, max_len: usize, ) -> Vec<Vec<String>>
All undirected paths between start and end, capped at
max_paths and max_len. A path is a sequence of distinct
nodes; each consecutive pair is connected by either a parent
or child edge (we walk the graph as undirected for path
enumeration; direction matters for the d-separation check).
Returns paths as Vec<Vec<String>>, where each inner Vec is
the node sequence from start to end.
Sourcepub fn is_path_blocked(&self, path: &[String], z: &HashSet<String>) -> bool
pub fn is_path_blocked(&self, path: &[String], z: &HashSet<String>) -> bool
True iff path is d-separated by Z. A path is blocked by Z if any non-endpoint node on the path satisfies one of:
- chain or fork: node is in Z
- collider: neither node nor any descendant of node is in Z
Equivalently, path is open under Z iff every chain/fork node is not in Z, AND every collider node is in Z (or has a descendant in Z).
Sourcepub fn is_back_door_path(&self, path: &[String], x: &str) -> bool
pub fn is_back_door_path(&self, path: &[String], x: &str) -> bool
True iff the path is a “back-door path” from x to y: it begins at x with an incoming edge to x (i.e., the second node is a parent of x), not an outgoing edge.
Sourcepub fn is_directed_path(&self, path: &[String]) -> bool
pub fn is_directed_path(&self, path: &[String]) -> bool
v0.44.2: True iff every consecutive edge in path points
from the earlier node to the later node (i.e., the path is
a directed path in the DAG, not a mixed undirected walk).
Required for the front-door criterion’s “M intercepts every
directed path source → target” check.
Trait Implementations§
Source§impl Clone for CausalGraph
impl Clone for CausalGraph
Source§fn clone(&self) -> CausalGraph
fn clone(&self) -> CausalGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more