From e48fd7bb5b6957f444a54b23ad3817da3ee80010 Mon Sep 17 00:00:00 2001 From: Drew Herren Date: Thu, 20 Nov 2025 14:12:09 -0600 Subject: [PATCH 1/2] Update Python BCF to work without propensities --- stochtree/bcf.py | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/stochtree/bcf.py b/stochtree/bcf.py index 10bf3f3c..2e1b2ad2 100644 --- a/stochtree/bcf.py +++ b/stochtree/bcf.py @@ -932,16 +932,15 @@ def sample( if sample_sigma2_leaf_tau is not None: if not isinstance(sample_sigma2_leaf_tau, bool): raise ValueError("sample_sigma2_leaf_tau must be a bool") - if propensity_covariate is not None: - if propensity_covariate not in [ - "prognostic", - "treatment_effect", - "both", - "none", - ]: - raise ValueError( - "propensity_covariate must be one of 'prognostic', 'treatment_effect', 'both', or 'none'" - ) + if propensity_covariate not in [ + "prognostic", + "treatment_effect", + "both", + "none", + ]: + raise ValueError( + "propensity_covariate must be one of 'prognostic', 'treatment_effect', 'both', or 'none'" + ) if b_0 is not None: b_0 = check_scalar( x=b_0, @@ -1663,15 +1662,6 @@ def sample( ] = 0 # Update covariates to include propensities if requested - if propensity_covariate not in [ - "none", - "prognostic", - "treatment_effect", - "both", - ]: - raise ValueError( - "propensity_covariate must equal one of 'none', 'prognostic', 'treatment_effect', or 'both'" - ) if propensity_covariate != "none": feature_types = np.append( feature_types, np.repeat(0, propensity_train.shape[1]) @@ -1700,9 +1690,10 @@ def sample( variable_weights_tau = np.append( variable_weights_tau, np.repeat(1 / num_cov_orig, propensity_train.shape[1]) ) - variable_weights_variance = np.append( - variable_weights_variance, np.repeat(0.0, propensity_train.shape[1]) - ) + # For now, propensities are not included in the variance forest + variable_weights_variance = np.append( + variable_weights_variance, np.repeat(0.0, propensity_train.shape[1]) + ) # Renormalize variable weights variable_weights_mu = variable_weights_mu / np.sum(variable_weights_mu) From 0a4d8c868ffe34a40e391ce0062cb5477cc597d2 Mon Sep 17 00:00:00 2001 From: Drew Herren Date: Thu, 20 Nov 2025 15:08:41 -0600 Subject: [PATCH 2/2] Added unit test to make sure BCF runs without propensity scores --- test/python/test_bcf.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/python/test_bcf.py b/test/python/test_bcf.py index eca2a5ff..c5a1446f 100644 --- a/test/python/test_bcf.py +++ b/test/python/test_bcf.py @@ -194,6 +194,19 @@ def test_binary_bcf(self): # Check treatment effect prediction method tau_hat = bcf_model.predict(X=X_test, Z=Z_test, terms="cate") + # Check that we can run BCF without propensities + bcf_model = BCFModel() + general_params = {"propensity_covariate": "none"} + bcf_model.sample( + X_train=X_train, + Z_train=Z_train, + y_train=y_train, + num_gfr=num_gfr, + num_burnin=num_burnin, + num_mcmc=num_mcmc, + general_params=general_params, + ) + def test_continuous_univariate_bcf(self): # RNG random_seed = 101