Skip to main content

Crate causasv

Crate causasv 

Source
Expand description

Causal feature attribution via Asymmetric Shapley Values (ASV) over DAGs, for explainable AI (XAI) / SHAP-style feature importance with Rust + Python bindings.

§Quick Start

use causasv::{AsvExplainer, CausasvError, Dag};

fn main() -> Result<(), CausasvError> {
    let mut dag = Dag::new();
    let x = dag.add_node("X");
    let y = dag.add_node("Y");
    dag.add_edge(x, y)?;

    let explainer = AsvExplainer::new(dag);
    let result = explainer.exact(|coalition| Ok(coalition.len() as f64))?;

    for (id, val) in &result.values {
        println!("{id:?} = {val:.4}");
    }
    Ok(())
}

For large graphs use AsvExplainer::approximate or AsvExplainer::auto. See the README for Python usage and benchmarks.

Re-exports§

pub use asv::AsvExplainer;
pub use asv::AsvResult;
pub use asv::ExactTreeConfig;

Modules§

asv

Structs§

AdaptiveSamplingConfig
Configuration for adaptive approximate ASV sampling.
Cpdag
Partially directed graph: some edges are compelled (directed), others are unresolved (undirected). Node indexing mirrors Dag: stable NodeIds assigned in insertion order.
Dag
Directed acyclic graph with stable node indexing.
ExactDagConfig
Configuration for sparse order-ideal exact DAG DP.
NodeId
Stable handle to a node in a Dag, assigned in insertion order starting at 0. Valid only for the Dag that created it — passing a NodeId from a different (or stale) Dag returns CausasvError::InvalidNodeId.
SamplingConfig
Configuration for approximate ASV sampling.

Enums§

CausasvError
All ways a causasv operation can fail.

Functions§

enumerate_topos
Enumerates ALL valid topological orderings. Output is deterministic (frontier sorted by NodeId at each step). Only practical for small graphs (n ≤ ~8).
topo_sort
Returns a valid topological ordering (smallest NodeId first among ties).

Type Aliases§

ValueFn
Type alias for a value function over node coalitions. The library guarantees the coalition slice is sorted in ascending NodeId order before calling, so callers may use it as a stable cache key.