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: CausalGraphThe 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
impl StructuralCausalModel
Sourcepub fn new(n: usize) -> Self
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.
Sourcepub fn add_edge(&mut self, from: usize, to: usize, coeff: f64)
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 indexto— child (effect) node indexcoeff— linear coefficient
Sourcepub fn set_noise(&mut self, v: usize, std: f64)
pub fn set_noise(&mut self, v: usize, std: f64)
Set the noise standard deviation for variable v.
Sourcepub fn set_intercept(&mut self, v: usize, intercept: f64)
pub fn set_intercept(&mut self, v: usize, intercept: f64)
Set the intercept for variable v.
Sourcepub fn sample_with_noise(&self, noise: &[f64]) -> Vec<f64>
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ε_ifor each variable (length = n_nodes)
Returns x[i] values in topological order.
Sourcepub fn intervene(&self, target: usize, val: f64) -> Self
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).
Sourcepub fn average_causal_effect(
&self,
cause: usize,
val: f64,
effect: usize,
noise_samples: &[Vec<f64>],
) -> f64
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 onval— the intervention valueeffect— the outcome variablenoise_samples— matrix of noise samples, shape[n_samples][n_nodes]
Sourcepub fn total_effect_linear(&self, cause: usize, effect: usize) -> f64
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
impl Clone for StructuralCausalModel
Source§fn clone(&self) -> StructuralCausalModel
fn clone(&self) -> StructuralCausalModel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for StructuralCausalModel
impl RefUnwindSafe for StructuralCausalModel
impl Send for StructuralCausalModel
impl Sync for StructuralCausalModel
impl Unpin for StructuralCausalModel
impl UnsafeUnpin for StructuralCausalModel
impl UnwindSafe for StructuralCausalModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.