Skip to main content

Dag

Struct Dag 

Source
pub struct Dag { /* private fields */ }
Expand description

Static directed acyclic graph over variables.

Implementations§

Source§

impl Dag

Source

pub fn ancestors_of( &self, nodes: &[DenseNodeId], out: &mut BitSet, ws: &mut GraphWorkspace, )

Collect all ancestors of nodes (including nodes themselves) into out.

Source

pub fn descendants_of( &self, nodes: &[DenseNodeId], out: &mut BitSet, ws: &mut GraphWorkspace, )

Collect all descendants of nodes (including nodes) into out.

Source

pub fn is_ancestor(&self, anc: DenseNodeId, desc: DenseNodeId) -> bool

Whether anc is an ancestor of desc (or equal).

Source

pub fn markov_blanket( &self, node: DenseNodeId, out: &mut BitSet, ) -> Result<(), GraphError>

Markov blanket of node: parents ∪ children ∪ spouses (co-parents of children). Does not include node itself.

§Errors

Unknown node id.

Source

pub fn markov_blanket_nodes( &self, node: DenseNodeId, ) -> Result<Vec<DenseNodeId>, GraphError>

Sorted Markov blanket of node (excluding node).

§Errors

Unknown node id.

Source

pub fn mutilate(&self, intervened: &[DenseNodeId]) -> Result<Dag, GraphError>

Mutilate the graph under intervention: remove all edges into each intervened node. Returns a new DAG (nodes preserved).

Prefer Dag::view with GraphOverlay::do_intervention on hot paths to avoid cloning adjacency.

§Errors

Unknown node ids.

Source§

impl Dag

Source

pub fn empty() -> Self

Empty DAG.

Source

pub fn with_variables(n: u32) -> Self

Build a DAG with one static node per variable 0..n.

Source

pub fn from_named_edges( schema: &CausalSchema, edges: &[(&str, &str)], ) -> Result<Self, GraphError>

Build a DAG with one static node per schema variable (VariableId raw == dense id), then insert directed edges named by schema variable names.

§Errors

Unknown names, duplicate edges, or cycles.

Source

pub fn node_count(&self) -> usize

Number of nodes.

Source

pub fn is_empty(&self) -> bool

Whether empty.

Source

pub fn nodes(&self) -> &[NodeRef]

Node refs in dense order.

Source

pub fn add_node(&mut self, node: NodeRef) -> Result<DenseNodeId, GraphError>

Add a static node; returns its dense id.

§Errors

GraphError::TooManyNodes on overflow.

Source

pub fn insert_directed( &mut self, from: DenseNodeId, to: DenseNodeId, ) -> Result<(), GraphError>

Insert a directed edge from -> to if it preserves acyclicity.

§Errors

Unknown nodes, duplicates, or cycles.

Source

pub fn remove_directed(&mut self, from: DenseNodeId, to: DenseNodeId)

Remove a directed edge if present.

Source

pub fn children(&self, id: DenseNodeId) -> &[DenseNodeId]

Children of id.

Source

pub fn parents(&self, id: DenseNodeId) -> &[DenseNodeId]

Parents of id.

Source

pub fn reaches(&self, from: DenseNodeId, to: DenseNodeId) -> bool

Whether from can reach to via directed edges.

Source

pub fn reaches_with( &self, from: DenseNodeId, to: DenseNodeId, ws: &mut GraphWorkspace, ) -> bool

Reachability using a reusable workspace.

Source

pub fn topological_order(&self) -> Option<Vec<DenseNodeId>>

Topological order (Kahn). Returns None if a cycle slipped in.

Source

pub fn validate(&self) -> Result<(), GraphError>

Validate graph invariants.

§Errors

Cycle detected.

Source

pub fn edges(&self) -> impl Iterator<Item = MarkedEdge> + '_

Iterate directed edges as marked edges.

Source

pub fn directed_paths( &self, from: DenseNodeId, to: DenseNodeId, max_paths: usize, max_len: usize, ) -> Result<Vec<Vec<DenseNodeId>>, GraphError>

Enumerate simple directed paths from from to to (inclusive endpoints).

Bounded by max_paths and max_len (number of nodes on the path).

The returned set is silently truncated when either bound binds. Callers whose correctness depends on seeing every path — e.g. a recanting-witness test, which concludes “no witness exists” from the absence of one — must use Self::directed_paths_with_budget and fail closed on truncation instead.

§Errors

Unknown nodes.

Source

pub fn directed_paths_with_budget( &self, from: DenseNodeId, to: DenseNodeId, max_paths: usize, max_len: usize, ) -> Result<(Vec<Vec<DenseNodeId>>, bool), GraphError>

Self::directed_paths plus a flag reporting whether enumeration was cut short.

The flag is true when max_paths stopped the search with candidates still pending, or when max_len pruned a partial path that had not yet reached to. It is deliberately conservative: true means “the path set may be incomplete”, never “it is definitely incomplete”.

§Errors

Unknown nodes.

Source§

impl Dag

Source

pub fn is_d_separated( &self, x: DenseNodeId, y: DenseNodeId, z: &[DenseNodeId], ws: &mut DSeparationWorkspace, ) -> Result<bool, GraphError>

Whether x is d-separated from y given z (boolean; no path alloc).

If Z ∩ {x,y} ≠ ∅ the query is ill-posed and this returns false (not separated), matching PAG m-separation / definite-status activity.

§Errors

Unknown node ids.

Source

pub fn is_d_separated_batch( &self, queries: &[(DenseNodeId, DenseNodeId, &[DenseNodeId])], out: &mut [bool], ws: &mut DSeparationWorkspace, ) -> Result<(), GraphError>

Batch boolean d-separation. out[i] corresponds to queries[i] = (x,y,z).

§Errors

Unknown nodes; or out.len() != queries.len().

Source

pub fn d_separation( &self, x: DenseNodeId, y: DenseNodeId, z: &[DenseNodeId], ws: &mut DSeparationWorkspace, ) -> Result<SeparationResult, GraphError>

d-separation with witness (active path or separation certificate).

§Errors

Unknown nodes.

Source§

impl Dag

Source

pub fn view<'a>(&'a self, overlay: &'a GraphOverlay) -> DagView<'a>

Borrow self under an intervention / mutilation overlay.

Trait Implementations§

Source§

impl Clone for Dag

Source§

fn clone(&self) -> Dag

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dag

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Dag

§

impl RefUnwindSafe for Dag

§

impl Send for Dag

§

impl Sync for Dag

§

impl Unpin for Dag

§

impl UnsafeUnpin for Dag

§

impl UnwindSafe for Dag

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.