pub struct CounterfactualQuery {
pub scm: StructuralCausalModel,
}Expand description
Compute counterfactual queries of the form E[Y | do(X=x), Z=z].
Uses the abduction-action-prediction three-step procedure on a linear SCM.
Fields§
§scm: StructuralCausalModelThe structural causal model for the query.
Implementations§
Source§impl CounterfactualQuery
impl CounterfactualQuery
Sourcepub fn new(scm: StructuralCausalModel) -> Self
pub fn new(scm: StructuralCausalModel) -> Self
Create a new counterfactual query engine.
Sourcepub fn query_do(
&self,
target: usize,
x_val: f64,
outcome: usize,
noise_samples: &[Vec<f64>],
) -> f64
pub fn query_do( &self, target: usize, x_val: f64, outcome: usize, noise_samples: &[Vec<f64>], ) -> f64
Compute E[Y | do(X_target=x_val)] using the interventional distribution.
§Arguments
target— the variable to intervene onx_val— the intervention valueoutcome— the outcome variablenoise_samples— noise samples for Monte Carlo evaluation
Sourcepub fn counterfactual(
&self,
obs: &[Option<f64>],
target: usize,
x_val: f64,
outcome: usize,
) -> f64
pub fn counterfactual( &self, obs: &[Option<f64>], target: usize, x_val: f64, outcome: usize, ) -> f64
Compute the counterfactual: given that we observed obs (variable→value pairs),
what would outcome have been if do(target=x_val)?
Three steps:
- Abduction: infer noise
Ufrom observations - Action: intervene on
target - Prediction: compute outcome under intervention
§Arguments
obs— observed values,obs[v]= Some(value) if observedtarget— intervention variablex_val— intervention valueoutcome— outcome variable index
Trait Implementations§
Source§impl Clone for CounterfactualQuery
impl Clone for CounterfactualQuery
Source§fn clone(&self) -> CounterfactualQuery
fn clone(&self) -> CounterfactualQuery
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CounterfactualQuery
impl RefUnwindSafe for CounterfactualQuery
impl Send for CounterfactualQuery
impl Sync for CounterfactualQuery
impl Unpin for CounterfactualQuery
impl UnsafeUnpin for CounterfactualQuery
impl UnwindSafe for CounterfactualQuery
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
Mutably borrows from an owned value. Read more
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>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.