Module Index : Topics : Keywords
 
 
structure_learning.inference.causal_effects
index
/Users/165421/Documents/code/structure_learning/src/structure_learning/inference/causal_effects.py

This module provides methods for causal inference and effect estimation using Bayesian approaches.
 
Classes:
    CausalEffects:
        A class for performing causal inference and estimating effects using directed acyclic graphs (DAGs) and observational data.
 
Functions:
    gibbs_linear(X, y, n_iter=2000, burn_in=500):
        Performs Bayesian linear regression with unknown variance via Gibbs sampling.
 
    gibbs_probit(X, y, n_iter=2000, burn_in=500):
        Implements the Albert-Chib Gibbs sampler for probit regression.
 
    estimate_hybrid_dag(adj_matrix, data, domains, n_iter=2000, burn_in=500):
        Estimates posterior samples of parameters for each node in a DAG.
 
    normalise_data(data, domains):
        Standardises continuous columns to mean=0, sd=1 while leaving binary columns unchanged.
 
    denormalise_linear_sample(beta_norm, child_idx, parent_idxs, mus, sds):
        Converts normalised linear beta samples to their original scale.
 
    denormalise_probit_sample(beta_norm, child_idx, parent_idxs, mus, sds):
        Converts normalised probit beta samples to their original latent scale.
 
    simulate_do_effects(adj_matrix, intervention, est_params, domains, data, do_value=1.0, multiply=False):
        Simulates do-intervention effects on raw data, injecting noise at each step.

 
Modules
       
numpy
networkx
pandas
matplotlib.pyplot
seaborn
sumu

 
Classes
       
builtins.object
CausalEffects

 
class CausalEffects(builtins.object)
    CausalEffects(graphs: Union[structure_learning.data_structures.dag.DAG, List[structure_learning.data_structures.dag.DAG], structure_learning.distributions.distribution.MCMCDistribution], data: structure_learning.data.data.Data)
 

 
  Methods defined here:
__init__(self, graphs: Union[structure_learning.data_structures.dag.DAG, List[structure_learning.data_structures.dag.DAG], structure_learning.distributions.distribution.MCMCDistribution], data: structure_learning.data.data.Data)
Initialize the CausalEffects object with a graph and data.
 
Parameters:
    graph (DAG): The directed acyclic graph representing the causal structure.
    data (Data): The observational data.
beeps(self, edges: List[tuple] = None, plot: bool = False)
Compute pairwise causal effects using the BEEPS algorithm.
 
Returns:
    List[np.ndarray]: A list of pairwise causal effect matrices for each graph.
do(self, intervention: List[Union[int, str]], do_value: float = 1.0, multiply: bool = False) -> numpy.ndarray
Perform a do-intervention on the graph and data.
 
Parameters:
    intervention (List[Union[int, str]]): The node indices or labels to intervene on.
    do_value (float): The value to set for the intervention.
    multiply (bool): If True, applies the intervention as a multiplier; otherwise, adds it.
 
Returns:
    np.ndarray: The effect of the intervention on the data.
estimate_effects(self, n_iter=2000, burn_in=500)
Estimate the effects of interventions using Gibbs sampling.
Parameters:
    n_iter (int): Number of iterations for Gibbs sampling.
    burn_in (int): Number of burn-in iterations to discard.
Returns:
    dict: Estimated parameters for each node.
plot(self, effects, weights, edges)
simulate(self, intervention: List[Union[int, str]], do_value: float = 1.0, multiply: bool = False, plot=False, edges=None) -> numpy.ndarray
Perform do-intervention on the graph and data.
 
Parameters:
    intervention (Union[int, str]): The node index or label to intervene on.
    do_value (float): The value to set for the intervention.
    multiply (bool): If True, applies the intervention as a multiplier; otherwise, adds it.
 
Returns:
    np.ndarray: The effect of the intervention on the data.

Data descriptors defined here:
__dict__
dictionary for instance variables
__weakref__
list of weak references to the object

 
Functions
       
denormalise_linear_sample(beta_norm, child_idx, parent_idxs, mus, sds)
Given one normalised linear beta sample [intercept, slopes...],
return (intercept_orig, slopes_orig_list).
denormalise_probit_sample(beta_norm, child_idx, parent_idxs, mus, sds)
Given one normalised probit beta sample [intercept, slopes...],
return (intercept_orig, slopes_orig_list) on latent scale.
estimate_hybrid_dag(adj_matrix, data, domains, n_iter=2000, burn_in=500)
Given:
  - adj_matrix: (n x n) adjacency (0/1) of a DAG,
  - data:      (N x n) observations,
  - domains:   length-n list, 'continuous' or 'binary'
Returns posterior samples of parameters for each node.
gibbs_linear(X, y, n_iter=2000, burn_in=500)
Bayesian linear regression with unknown variance via Gibbs.
gibbs_probit(X, y, n_iter=2000, burn_in=500)
Albert-Chib Gibbs sampler for probit regression.
normalise_data(data, domains)
Standardise continuous columns to mean=0, sd=1; leave binaries unchanged.
Returns:
  data_norm : np.ndarray
  mus       : dict (column means)
  sds       : dict (column s.d.)
simulate_do_effects(adj_matrix, intervention, est_params, domains, data, do_value=1.0, multiply=False)
Perform do-intervention simulations on raw data, injecting noise at each step.
est_params[j] should contain:
  - 'beta_mean': array [intercept, slopes...]
  - optional 'sigma2_mean' for continuous nodes
do_value: if multiply=False, adds do_value to Xi; if multiply=True, multiplies Xi by do_value
multiply: boolean flag to apply do_value as multiplier instead of additive shift

 
Data
        List = typing.List
Union = typing.Union
norm = <scipy.stats._continuous_distns.norm_gen object>
truncnorm = <scipy.stats._continuous_distns.truncnorm_gen object>