DAG#

class sdm.prior.DAG(parent_ptr: Tensor, parent_idx: Tensor, input_nodes: Tensor | None = None, target_node: int | None = None)#

Bases: object

Directed acyclic graph in CSR layout.

Parameters:
  • parent_ptr (Tensor) – Parent offsets with shape [N + 1] for N nodes.

  • parent_idx (Tensor) – Parent indices with shape [E] for E edges. Each parent precedes its child.

  • input_nodes (Tensor | None) – Optional feature node indices with shape [F] for F features.

  • target_node (int | None) – Optional target node index.

property num_nodes: int#

Return the node count.

property num_edges: int#

Return the edge count.

parents(i: int) → Tensor#

Return a node’s parent indices.

Parameters:

i (int) – Node index.

Return type:

Tensor

property topological_order: Tensor#

Return all nodes in topological order.

property pruned_topological_order: Tensor#

Return assigned nodes and their ancestors in topological order.

Return all nodes if either assignment is missing.

with_columns(num_columns: int, generator: Generator | None = None) → DAG#

Return a graph with sampled feature and target assignments.

Parameters:
  • num_columns (int) – Feature count.

  • generator (Generator | None) – Pseudorandom generator.

Return type:

DAG

is_valid() → bool#

Check for an undirected path between target and feature nodes.

Unassigned graphs are accepted.

Return type:

bool