dowhy.do_samplers package

Submodules

dowhy.do_samplers.kernel_density_sampler module

class dowhy.do_samplers.kernel_density_sampler.KernelDensitySampler(*args, **kwargs)[source]

Bases: DoSampler

Initializes a do sampler with data and names of relevant variables.

Do sampling implements the do() operation from Pearl (2000). This is an operation is defined on a causal bayesian network, an explicit implementation of which is the basis for the MCMC sampling method.

We abstract the idea behind the three-step process to allow other methods, as well. The disrupt_causes method is the means to make treatment assignment ignorable. In the Pearlian framework, this is where we cut the edges pointing into the causal state. With other methods, this will typically be by using some approach which assumes conditional ignorability (e.g. weighting, or explicit conditioning with Robins G-formula.)

Next, the make_treatment_effective method reflects the assumption that the intervention we impose is “effective”. Most simply, we fix the causal state to some specific value. We skip this step there is no value specified for the causal state, and the original values are used instead.

Finally, we sample from the resulting distribution. This can be either from a point_sample method, in the case that the inference method doesn’t support batch sampling, or the sample method in the case that it does. For convenience, the point_sample method parallelizes with multiprocessing using the num_cores kwargs to set the number of cores to use for parallelization.

While different methods will have their own class attributes, the _df method should be common to all methods. This is them temporary dataset which starts as a copy of the original data, and is modified to reflect the steps of the do operation. Read through the existing methods (weighting is likely the most minimal) to get an idea of how this works to implement one yourself.

Parameters
  • data – pandas.DataFrame containing the data

  • identified_estimand – dowhy.causal_identifier.IdentifiedEstimand: and estimand using a backdoor method

for effect identification. :param treatments: list or str: names of the treatment variables :param outcomes: list or str: names of the outcome variables :param variable_types: dict: A dictionary containing the variable’s names and types. ‘c’ for continuous, ‘o’ for ordered, ‘d’ for discrete, and ‘u’ for unordered discrete. :param keep_original_treatment: bool: Whether to use make_treatment_effective, or to keep the original treatment assignments. :param params: (optional) additional method parameters

class dowhy.do_samplers.kernel_density_sampler.KernelSampler(outcome_upper_support, outcome_lower_support, outcome_names, treatment_names, backdoor_variables, data, dep_type, indep_type, bw, defaults)[source]

Bases: object

sample_point(x_z)[source]

dowhy.do_samplers.mcmc_sampler module

class dowhy.do_samplers.mcmc_sampler.McmcSampler(data, *args, params=None, variable_types=None, num_cores=1, keep_original_treatment=False, causal_model=None, **kwargs)[source]

Bases: DoSampler

g, df, data_types

apply_data_types(g, data_types)[source]
apply_parameters(g, df, initialization_trace=None)[source]
apply_parents(g)[source]
build_bayesian_network(g, df)[source]
do_sample(x)[source]
do_x_surgery(g, x)[source]
fit_causal_model(g, df, data_types, initialization_trace=None)[source]
make_intervention_effective(x)[source]
sample_prior_causal_model(g, df, data_types, initialization_trace)[source]

dowhy.do_samplers.multivariate_weighting_sampler module

class dowhy.do_samplers.multivariate_weighting_sampler.MultivariateWeightingSampler(data, *args, params=None, variable_types=None, num_cores=1, keep_original_treatment=False, causal_model=None, **kwargs)[source]

Bases: DoSampler

g, df, data_types

compute_weights()[source]
disrupt_causes()[source]

Override this method to render treatment assignment conditionally ignorable :return:

make_treatment_effective(x)[source]

This is more likely the implementation you’d like to use, but some methods may require overriding this method to make the treatment effective. :param x: :return:

sample()[source]

By default, this expects a sampler to be built on class initialization which contains a sample method. Override this method if you want to use a different approach to sampling. :return:

dowhy.do_samplers.weighting_sampler module

class dowhy.do_samplers.weighting_sampler.WeightingSampler(data, *args, params=None, variable_types=None, num_cores=1, keep_original_treatment=False, causal_model=None, **kwargs)[source]

Bases: DoSampler

g, df, data_types

compute_weights()[source]
disrupt_causes()[source]

Override this method to render treatment assignment conditionally ignorable :return:

make_treatment_effective(x)[source]

This is more likely the implementation you’d like to use, but some methods may require overriding this method to make the treatment effective. :param x: :return:

sample()[source]

By default, this expects a sampler to be built on class initialization which contains a sample method. Override this method if you want to use a different approach to sampling. :return:

Module contents

dowhy.do_samplers.get_class_object(method_name, *args, **kwargs)[source]