Skip to main content

StructuralCausalModel

Struct StructuralCausalModel 

Source
pub struct StructuralCausalModel {
    pub graph: CausalGraph,
    pub coefficients: Vec<Vec<f64>>,
    pub noise_std: Vec<f64>,
    pub intercepts: Vec<f64>,
}
Expand description

A linear structural causal model (SCM).

Each variable X_i is defined as: X_i = Σ_j (coeff[i][j] * X_j) + noise_std[i] * ε_i

where ε_i ~ N(0,1) and j ranges over parents of i.

Fields§

§graph: CausalGraph

The underlying causal graph.

§coefficients: Vec<Vec<f64>>

Structural coefficients: coefficients[i][k] is the coefficient for the k-th parent of node i.

§noise_std: Vec<f64>

Standard deviation of the exogenous noise for each variable.

§intercepts: Vec<f64>

Intercept terms for each variable.

Implementations§

Source§

impl StructuralCausalModel

Source

pub fn new(n: usize) -> Self

Create a new linear SCM on n variables.

All coefficients are zero, noise std = 1.0, intercepts = 0.0 by default.

Source

pub fn add_edge(&mut self, from: usize, to: usize, coeff: f64)

Add a causal edge with a specified structural coefficient.

§Arguments
  • from — parent (cause) node index
  • to — child (effect) node index
  • coeff — linear coefficient
Source

pub fn set_noise(&mut self, v: usize, std: f64)

Set the noise standard deviation for variable v.

Source

pub fn set_intercept(&mut self, v: usize, intercept: f64)

Set the intercept for variable v.

Source

pub fn sample_with_noise(&self, noise: &[f64]) -> Vec<f64>

Sample one observation from the SCM using provided noise values.

§Arguments
  • noise — exogenous noise values ε_i for each variable (length = n_nodes)

Returns x[i] values in topological order.

Source

pub fn intervene(&self, target: usize, val: f64) -> Self

Perform a do-calculus intervention: set variable target to value val.

Returns the modified SCM where all incoming edges to target are removed and its value is fixed at val (zero noise, intercept = val).

Source

pub fn average_causal_effect( &self, cause: usize, val: f64, effect: usize, noise_samples: &[Vec<f64>], ) -> f64

Compute the average causal effect (ACE) of intervention do(X_cause = val) on variable effect, using the provided noise samples.

§Arguments
  • cause — the variable to intervene on
  • val — the intervention value
  • effect — the outcome variable
  • noise_samples — matrix of noise samples, shape [n_samples][n_nodes]
Source

pub fn total_effect_linear(&self, cause: usize, effect: usize) -> f64

Compute the total causal effect of cause on effect analytically (only valid for linear SCMs).

Sums all directed path contributions.

Trait Implementations§

Source§

impl Clone for StructuralCausalModel

Source§

fn clone(&self) -> StructuralCausalModel

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 StructuralCausalModel

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.