Causal Graphical Models

Encoding causality into the CF explanation generation.

Distributions

https://github.com/amirhk/recourse/blob/master/distributions.py


source

BASEDISTRIBUTION

CLASS relax.data.scm.BaseDistribution (name)

Base class for all distributions.


source

MIXTUREOFGAUSSIANS

CLASS relax.data.scm.MixtureOfGaussians (probs, means, vars)

Mixture of Gaussians distribution.


source

NORMAL

CLASS relax.data.scm.Normal (mean, var)

Normal distribution.

Load SCM

Load scm structural equations.


source

SANITY_3_LIN

relax.data.scm.sanity_3_lin ()

Causal Model


source

CAUSALMODEL

CLASS relax.data.scm.CausalModel (scm_class)

Class with topological methods given a structural causal model.

Parameters:
  • scm_class (str) – Name of the structural causal model.

Credit goes to the CARLA implementation.

scm = CausalModel('sanity_3_lin')
assert scm.get_children('x1') == {'x2', 'x3'}
assert scm.get_parents('x3') == ['x1', 'x2']
assert scm.get_ancestors('x3') == ['x1', 'x2']
assert scm.get_descendants('x1') == ['x2', 'x3']
assert scm.get_non_descendants('x1') == set()

Generate synthethic Data

Adapted from Carla.

(Experimental) Data Module

scm = CausalModel('sanity_3_lin')
df_endogenous, df_exogenous = _create_synthetic_data(scm, 1000)
d_config = TabularDataModuleConfigs(
    data_dir=".",
    data_name='sanity_3_lin',
    continous_cols=scm._continuous,
    discret_cols=scm._categorical,
)
dm = TabularDataModule(d_config, data=df_endogenous)
setattr(dm, 'scm', scm)
setattr(dm, 'exogenous', df_exogenous)
assert isinstance(dm.scm, CausalModel)
assert isinstance(dm.exogenous, pd.DataFrame)