metacausal.adapters.StochtreeAdapter

class metacausal.adapters.StochtreeAdapter(name='BCF', *, propensity_model=None, num_gfr=5, num_burnin=200, num_mcmc=200, alpha=0.05, propensity_n_splits=5, propensity_clip_eps=0.01, general_params=None, prognostic_forest_params=None, treatment_effect_forest_params=None)[source]

Bases: object

Wrap stochtree’s BCFModel for use in CausalEnsemble.

BCF requires propensity scores as input. By default, this adapter computes cross-fitted propensity scores using the provided propensity_model. A pre-computed propensity array can be passed via fit(..., propensity=ps) to skip this step.

Parameters:
  • name (str) – Display name (default "BCF").

  • propensity_model (Any) – An sklearn-compatible classifier for propensity estimation. Must support fit(X, T) and predict_proba(X). If None, uses HistGradientBoostingClassifier with early stopping.

  • num_gfr (int) – Number of “grow-from-root” warm-start iterations (default 5). Set to 0 to disable.

  • num_burnin (int) – MCMC burn-in iterations (default 200).

  • num_mcmc (int) – Posterior samples after burn-in (default 200).

  • alpha (float) – Credible interval level (default 0.05 for 95% CI).

  • propensity_n_splits (int) – CV folds for propensity estimation (default 5).

  • propensity_clip_eps (float) – Clip propensities to [eps, 1 - eps] (default 0.01).

  • general_params (dict | None) – Optional dict passed to BCFModel.sample(general_params=...). See stochtree docs for keys such as "random_seed", "propensity_covariate", "adaptive_coding", "standardize", "num_chains", etc.

  • prognostic_forest_params (dict | None) – Optional dict passed to BCFModel.sample(prognostic_forest_params=...). Common keys: "num_trees" (default 250), "alpha", "beta", "min_samples_leaf", "max_depth".

  • treatment_effect_forest_params (dict | None) – Optional dict passed to BCFModel.sample(treatment_effect_forest_params=...). Common keys: "num_trees" (default 50), "alpha", "beta", "min_samples_leaf", "max_depth".

Examples

Small num_gfr/num_burnin/num_mcmc below keep this a fast example; use more posterior draws in practice.

>>> from metacausal.adapters.stochtree import StochtreeAdapter
>>> from metacausal.datasets import load_lalonde
>>> from sklearn.linear_model import LogisticRegression
>>> X, T, Y = load_lalonde()
>>> bcf = StochtreeAdapter(
...     propensity_model=LogisticRegression(max_iter=2000),
...     num_gfr=2,
...     num_burnin=20,
...     num_mcmc=20,
... )
>>> bcf.fit(X, T, Y, random_state=42)
>>> result = bcf.ate()
>>> result
ComponentAteEstimate(ate=..., ci=[..., ...])

Methods

__init__

ate

cate

fit

validate_outcome_type

No-op: BCF has no user-configurable outcome learner.

Attributes

Details

ate(X=None)[source]
Parameters:

X (ndarray | None)

Return type:

ComponentAteEstimate

cate(X)[source]
Parameters:

X (ndarray)

Return type:

ComponentCateEstimate

fit(X, T, Y, **kwargs)[source]
Parameters:
Return type:

None

validate_outcome_type(detected)[source]

No-op: BCF has no user-configurable outcome learner. Routing away from binary outcomes happens via supported_outcome_types.

Parameters:

detected (str)

Return type:

None

property name: str
supported_outcome_types: tuple[str, ...] = ('continuous',)
property supports_cate: bool