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
dowhy.do_samplers.mcmc_sampler module#
- class dowhy.do_samplers.mcmc_sampler.McmcSampler(graph: DiGraph, action_nodes: List[str], outcome_nodes: List[str], observed_nodes: List[str], data, params=None, variable_types=None, num_cores=1, keep_original_treatment=False, estimand_type=EstimandType.NONPARAMETRIC_ATE)[source]#
Bases:
DoSampler
g, df, data_types
dowhy.do_samplers.multivariate_weighting_sampler module#
- class dowhy.do_samplers.multivariate_weighting_sampler.MultivariateWeightingSampler(graph: DiGraph, action_nodes: List[str], outcome_nodes: List[str], observed_nodes: List[str], data, params=None, variable_types=None, num_cores=1, keep_original_treatment=False, estimand_type=EstimandType.NONPARAMETRIC_ATE)[source]#
Bases:
DoSampler
g, df, data_types
- disrupt_causes()[source]#
Override this method to render treatment assignment conditionally ignorable :return:
dowhy.do_samplers.weighting_sampler module#
- class dowhy.do_samplers.weighting_sampler.WeightingSampler(graph: DiGraph, action_nodes: List[str], outcome_nodes: List[str], observed_nodes: List[str], data, params=None, variable_types=None, num_cores=1, keep_original_treatment=False, estimand_type=EstimandType.NONPARAMETRIC_ATE)[source]#
Bases:
DoSampler
g, df, data_types
- disrupt_causes()[source]#
Override this method to render treatment assignment conditionally ignorable :return: