dowhy.do_samplers 包#

子模块#

dowhy.do_samplers.kernel_density_sampler 模块#

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

基类: DoSampler

使用数据和相关变量名初始化 do 采样器。

Do 采样实现了 Pearl (2000) 的 do() 操作。此操作定义在因果贝叶斯网络上,其显式实现是 MCMC 采样方法的基础。

我们将三步过程背后的思想抽象化,以允许其他方法。 disrupt_causes 方法是使处理分配可忽略的手段。在 Pearlian 框架中,这是我们切断指向因果状态的边的地方。对于其他方法,这通常是通过使用假设条件可忽略性的一些方法来实现的(例如,加权,或使用 Robins G-formula 进行显式条件化)。

接下来, make_treatment_effective 方法反映了我们施加的干预是“有效”的假设。最简单地说,我们将因果状态固定到某个特定值。如果未为因果状态指定值,则跳过此步骤,而是使用原始值。

最后,我们从结果分布中采样。这可以是来自 point_sample 方法(如果推理方法不支持批量采样),或者来自 sample 方法(如果支持批量采样)。为了方便起见, point_sample 方法使用 multiprocessing 进行并行化,并使用 num_cores kwargs 设置用于并行化的核心数量。

虽然不同的方法将有自己的类属性,但 _df 方法应该对所有方法都是通用的。这是临时数据集,它以原始数据的副本开始,并进行修改以反映 do 操作的步骤。阅读现有方法(加权可能是最简单的)以了解其工作原理,以便自己实现一个方法。

参数:
  • data – 包含数据的 pandas.DataFrame

  • identified_estimand – dowhy.causal_identifier.IdentifiedEstimand: 使用后门方法得到的估计量

用于效果识别。 :param treatments: list 或 str: 处理变量的名称 :param outcomes: list 或 str: 结果变量的名称 :param variable_types: dict: 包含变量名称和类型的字典。‘c’ 表示连续型,‘o’ 表示有序型,‘d’ 表示离散型,‘u’ 表示无序离散型。 :param keep_original_treatment: bool: 是否使用 make_treatment_effective,或保留原始处理分配。 :param params: (可选) 附加方法参数

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]#

基类: object

sample_point(x_z)[source]#

dowhy.do_samplers.mcmc_sampler 模块#

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]#

基类: 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 模块#

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]#

基类: DoSampler

g, df, data_types

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

覆盖此方法以使处理分配条件可忽略 :return

make_treatment_effective(x)[source]#

这更有可能是您想使用的实现,但某些方法可能需要覆盖此方法以使处理有效。 :param x: :return

sample()[source]#

默认情况下,这期望在类初始化时构建一个包含 sample 方法的采样器。如果您想使用不同的采样方法,请覆盖此方法。 :return

dowhy.do_samplers.weighting_sampler 模块#

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]#

基类: DoSampler

g, df, data_types

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

覆盖此方法以使处理分配条件可忽略 :return

make_treatment_effective(x)[source]#

这更有可能是您想使用的实现,但某些方法可能需要覆盖此方法以使处理有效。 :param x: :return

sample()[source]#

默认情况下,这期望在类初始化时构建一个包含 sample 方法的采样器。如果您想使用不同的采样方法,请覆盖此方法。 :return

模块内容#

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